mirror of
https://github.com/owncloud/ocis.git
synced 2025-04-18 23:44:07 +03:00
Merge pull request #11166 from owncloud/use-auth-app-token
[tests-only][full-ci] adding test for using auth-app token
This commit is contained in:
commit
674291eb7c
@ -33,7 +33,8 @@ require_once 'bootstrap.php';
|
||||
*/
|
||||
class AuthAppContext implements Context {
|
||||
private FeatureContext $featureContext;
|
||||
private string $lastCreatedToken;
|
||||
private array $lastCreatedToken = [];
|
||||
private bool $usingAuthAppToken = false;
|
||||
|
||||
/**
|
||||
* @BeforeScenario
|
||||
@ -49,6 +50,20 @@ class AuthAppContext implements Context {
|
||||
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getLastCreatedToken(): array {
|
||||
return $this->lastCreatedToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isUsingAuthAppToken(): bool {
|
||||
return $this->usingAuthAppToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^user "([^"]*)" (?:creates|tries to create) auth-app token with expiration time "([^"]*)" using the auth-app API$/
|
||||
*
|
||||
@ -84,7 +99,10 @@ class AuthAppContext implements Context {
|
||||
["expiry" => $expiration]
|
||||
);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response);
|
||||
$this->lastCreatedToken = json_decode($response->getBody()->getContents())->token;
|
||||
$this->lastCreatedToken = [
|
||||
"user" => strtolower($user),
|
||||
"token" => json_decode($response->getBody()->getContents())->token
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,7 +151,10 @@ class AuthAppContext implements Context {
|
||||
. "HTTP status code 200 is not the expected value " . $response->getStatusCode(),
|
||||
$response
|
||||
);
|
||||
$this->lastCreatedToken = json_decode($response->getBody()->getContents())->token;
|
||||
$this->lastCreatedToken = [
|
||||
"user" => strtolower($impersonatedUser),
|
||||
"token" => json_decode($response->getBody()->getContents())->token
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -256,9 +277,18 @@ class AuthAppContext implements Context {
|
||||
$baseUrl,
|
||||
$user,
|
||||
$password,
|
||||
$this->lastCreatedToken,
|
||||
$this->getLastCreatedToken()['token'],
|
||||
);
|
||||
$this->featureContext->setResponse($deleteResponse);
|
||||
$this->featureContext->pushToLastHttpStatusCodesArray((string)$deleteResponse->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given using auth-app token
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function usingAuthAppToken(): void {
|
||||
$this->usingAuthAppToken = true;
|
||||
}
|
||||
}
|
||||
|
@ -164,6 +164,7 @@ class FeatureContext extends BehatVariablesContext {
|
||||
public TUSContext $tusContext;
|
||||
public GraphContext $graphContext;
|
||||
public SpacesContext $spacesContext;
|
||||
public AuthAppContext $authAppContext;
|
||||
public OcmContext $ocmContext;
|
||||
|
||||
/**
|
||||
@ -1784,7 +1785,12 @@ class FeatureContext extends BehatVariablesContext {
|
||||
public function getPasswordForUser(?string $userName): string {
|
||||
$userNameNormalized = $this->normalizeUsername($userName);
|
||||
$username = $this->getActualUsername($userNameNormalized);
|
||||
if ($username === $this->getAdminUsername()) {
|
||||
if ($this->authAppContext->isUsingAuthAppToken()
|
||||
&& $this->authAppContext->getLastCreatedToken() !== []
|
||||
&& strtolower($userName) === $this->authAppContext->getLastCreatedToken()["user"]
|
||||
) {
|
||||
return $this->authAppContext->getLastCreatedToken()["token"];
|
||||
} elseif ($username === $this->getAdminUsername()) {
|
||||
return $this->getAdminPassword();
|
||||
} elseif (\array_key_exists($username, $this->createdUsers)) {
|
||||
return (string)$this->createdUsers[$username]['password'];
|
||||
@ -2670,6 +2676,7 @@ class FeatureContext extends BehatVariablesContext {
|
||||
$this->ocmContext = BehatHelper::getContext($scope, $environment, 'OcmContext');
|
||||
$this->graphContext = BehatHelper::getContext($scope, $environment, 'GraphContext');
|
||||
$this->spacesContext = BehatHelper::getContext($scope, $environment, 'SpacesContext');
|
||||
$this->authAppContext = BehatHelper::getContext($scope, $environment, 'AuthAppContext');
|
||||
|
||||
$scenarioLine = $scope->getScenario()->getLine();
|
||||
$featureFile = $scope->getFeature()->getFile();
|
||||
|
88
tests/acceptance/features/apiAuthApp/tokenUsage.feature
Normal file
88
tests/acceptance/features/apiAuthApp/tokenUsage.feature
Normal file
@ -0,0 +1,88 @@
|
||||
Feature: create auth-app token
|
||||
As a user
|
||||
I want to create auth-app Tokens
|
||||
So that I can let 3rd party apps use my account
|
||||
|
||||
Background:
|
||||
Given user "Alice" has been created with default attributes
|
||||
And using auth-app token
|
||||
|
||||
|
||||
Scenario: admin creates user using auth-app token
|
||||
Given user "Admin" has created auth-app token with expiration time "1h" using the auth-app API
|
||||
When the user "Admin" creates a new user with the following attributes using the Graph API:
|
||||
| userName | Brian |
|
||||
| displayName | This is another Brian |
|
||||
| email | brian@example.com |
|
||||
| password | brian123 |
|
||||
| accountEnabled | true |
|
||||
Then the HTTP status code should be "201"
|
||||
And the JSON response should contain space called "Alice Hansen" and match
|
||||
"""
|
||||
{
|
||||
"type": "object",
|
||||
"required": [
|
||||
"accountEnabled",
|
||||
"displayName",
|
||||
"id",
|
||||
"mail",
|
||||
"onPremisesSamAccountName",
|
||||
"surname",
|
||||
"userType"
|
||||
],
|
||||
"properties": {
|
||||
"accountEnabled": { "const": true },
|
||||
"displayName": { "const": "This is another Brian" },
|
||||
"id": { "pattern": "%user_id_pattern%" },
|
||||
"mail": { "const": "brian@example.com" },
|
||||
"onPremisesSamAccountName": { "const": "Brian" },
|
||||
"surname": { "const":"Brian" },
|
||||
"userType": { "const":"Member" }
|
||||
}
|
||||
}
|
||||
"""
|
||||
And user "Brian" should be able to upload file "filesForUpload/lorem.txt" to "lorem.txt"
|
||||
|
||||
|
||||
Scenario: user lists their drives using auth-app token
|
||||
Given user "Alice" has created auth-app token with expiration time "1h" using the auth-app API
|
||||
When user "Alice" lists all available spaces via the Graph API
|
||||
Then the HTTP status code should be "200"
|
||||
And the JSON response should contain space called "Alice Hansen" and match
|
||||
"""
|
||||
{
|
||||
"type": "object",
|
||||
"required": [
|
||||
"driveType",
|
||||
"driveAlias",
|
||||
"name",
|
||||
"id",
|
||||
"quota",
|
||||
"root",
|
||||
"webUrl"
|
||||
],
|
||||
"properties": {
|
||||
"name": { "const": "Alice Hansen" },
|
||||
"driveType": { "const": "personal" },
|
||||
"driveAlias": { "const": "personal/alice" },
|
||||
"id": { "pattern": "%space_id_pattern%" },
|
||||
"quota": {
|
||||
"type": "object",
|
||||
"required": ["state"],
|
||||
"properties": {
|
||||
"state": { "const": "normal" }
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"type": "object",
|
||||
"required": ["webDavUrl"],
|
||||
"properties": {
|
||||
"webDavUrl": { "const": "%base_url%/dav/spaces/%space_id%" }
|
||||
}
|
||||
},
|
||||
"webUrl": {
|
||||
"const": "%base_url%/f/%space_id%"
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
Loading…
x
Reference in New Issue
Block a user