mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-09-08 11:53:07 -04:00
Merge pull request #10733 from owncloud/test-auth-app-token-api-impersonation
[tests-only][full-ci] add test for creating auth token for an app using impersonation api
This commit is contained in:
4 files changed
+111
-11
No files matched your search
@@ -61,7 +61,7 @@ class AuthAppHelper {
|
|||||||
* @param string $baseUrl
|
* @param string $baseUrl
|
||||||
* @param string $user
|
* @param string $user
|
||||||
* @param string $password
|
* @param string $password
|
||||||
* @param string $expiration
|
* @param array $params
|
||||||
*
|
*
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
@@ -69,9 +69,10 @@ class AuthAppHelper {
|
|||||||
string $baseUrl,
|
string $baseUrl,
|
||||||
string $user,
|
string $user,
|
||||||
string $password,
|
string $password,
|
||||||
string $expiration
|
array $params,
|
||||||
): ResponseInterface {
|
): ResponseInterface {
|
||||||
$url = $baseUrl . self::getAuthAppEndpoint() . "?expiry=$expiration";
|
$url = $baseUrl . self::getAuthAppEndpoint() . "?"
|
||||||
|
. http_build_query($params);
|
||||||
return HttpRequestHelper::sendRequest(
|
return HttpRequestHelper::sendRequest(
|
||||||
$url,
|
$url,
|
||||||
null,
|
null,
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
use Behat\Behat\Context\Context;
|
use Behat\Behat\Context\Context;
|
||||||
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
||||||
use TestHelpers\BehatHelper;
|
use TestHelpers\BehatHelper;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
|
||||||
use TestHelpers\AuthAppHelper;
|
use TestHelpers\AuthAppHelper;
|
||||||
|
|
||||||
require_once 'bootstrap.php';
|
require_once 'bootstrap.php';
|
||||||
@@ -62,7 +61,7 @@ class AuthAppContext implements Context {
|
|||||||
$this->featureContext->getBaseUrl(),
|
$this->featureContext->getBaseUrl(),
|
||||||
$this->featureContext->getActualUsername($user),
|
$this->featureContext->getActualUsername($user),
|
||||||
$this->featureContext->getPasswordForUser($user),
|
$this->featureContext->getPasswordForUser($user),
|
||||||
$expiration,
|
["expiry" => $expiration],
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -80,7 +79,7 @@ class AuthAppContext implements Context {
|
|||||||
$this->featureContext->getBaseUrl(),
|
$this->featureContext->getBaseUrl(),
|
||||||
$this->featureContext->getActualUsername($user),
|
$this->featureContext->getActualUsername($user),
|
||||||
$this->featureContext->getPasswordForUser($user),
|
$this->featureContext->getPasswordForUser($user),
|
||||||
$expiration,
|
["expiry" => $expiration]
|
||||||
);
|
);
|
||||||
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response);
|
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response);
|
||||||
}
|
}
|
||||||
@@ -101,4 +100,58 @@ class AuthAppContext implements Context {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Given the administrator has created app token for user :impersonatedUser with expiration time :expiration using the auth-app API
|
||||||
|
*
|
||||||
|
* @param string $impersonatedUser
|
||||||
|
* @param string $expiration
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function theAdministratorHasCreatedAppTokenWithExpirationTimeImpersonatingUserUsingTheAuthAppApi(
|
||||||
|
string $impersonatedUser,
|
||||||
|
string $expiration,
|
||||||
|
): void {
|
||||||
|
$response = AuthAppHelper::createAppAuthToken(
|
||||||
|
$this->featureContext->getBaseUrl(),
|
||||||
|
$this->featureContext->getAdminUsername(),
|
||||||
|
$this->featureContext->getAdminPassword(),
|
||||||
|
[
|
||||||
|
"expiry" => $expiration,
|
||||||
|
"userName" => $this->featureContext->getActualUsername($impersonatedUser)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
$this->featureContext->theHTTPStatusCodeShouldBe(
|
||||||
|
200,
|
||||||
|
"Failed creating auth-app token\n"
|
||||||
|
. "HTTP status code 200 is not the expected value " . $response->getStatusCode(),
|
||||||
|
$response
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @When the administrator creates app token for user :impersonatedUser with expiration time :expiration using the auth-app API
|
||||||
|
*
|
||||||
|
* @param string $impersonatedUser
|
||||||
|
* @param string $expiration
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function theAdministratorCreatesAppTokenForUserWithExpirationTimeViaAuthAppApi(
|
||||||
|
string $impersonatedUser,
|
||||||
|
string $expiration,
|
||||||
|
): void {
|
||||||
|
$this->featureContext->setResponse(
|
||||||
|
AuthAppHelper::createAppAuthToken(
|
||||||
|
$this->featureContext->getBaseUrl(),
|
||||||
|
$this->featureContext->getAdminUsername(),
|
||||||
|
$this->featureContext->getAdminPassword(),
|
||||||
|
[
|
||||||
|
"expiry" => $expiration,
|
||||||
|
"userName" => $this->featureContext->getActualUsername($impersonatedUser)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -441,6 +441,7 @@ default:
|
|||||||
- FeatureContext: *common_feature_context_params
|
- FeatureContext: *common_feature_context_params
|
||||||
- AuthAppContext:
|
- AuthAppContext:
|
||||||
- CliContext:
|
- CliContext:
|
||||||
|
- OcisConfigContext:
|
||||||
|
|
||||||
cliCommands:
|
cliCommands:
|
||||||
paths:
|
paths:
|
||||||
|
|||||||
@@ -31,9 +31,11 @@ Feature: create auth-app token
|
|||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@env-config
|
||||||
Scenario: user lists app tokens
|
Scenario: user lists auth-app tokens generated by different auth-app api
|
||||||
Given user "Alice" has created app token with expiration time "72h" using the auth-app API
|
Given the config "AUTH_APP_ENABLE_IMPERSONATION" has been set to "true"
|
||||||
|
And user "Alice" has created app token with expiration time "72h" using the auth-app API
|
||||||
|
And the administrator has created app token for user "Alice" with expiration time "72h" using the auth-app API
|
||||||
And user "Alice" has created app token with expiration time "72h" using the auth-app CLI
|
And user "Alice" has created app token with expiration time "72h" using the auth-app CLI
|
||||||
When user "Alice" lists all created tokens using the auth-app API
|
When user "Alice" lists all created tokens using the auth-app API
|
||||||
Then the HTTP status code should be "200"
|
Then the HTTP status code should be "200"
|
||||||
@@ -41,8 +43,8 @@ Feature: create auth-app token
|
|||||||
"""
|
"""
|
||||||
{
|
{
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"minItems": 2,
|
"minItems": 3,
|
||||||
"maxItems": 2,
|
"maxItems": 3,
|
||||||
"uniqueItems": true,
|
"uniqueItems": true,
|
||||||
"items": {
|
"items": {
|
||||||
"oneOf": [
|
"oneOf": [
|
||||||
@@ -79,8 +81,51 @@ Feature: create auth-app token
|
|||||||
"const": "Generated via CLI"
|
"const": "Generated via CLI"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"token",
|
||||||
|
"expiration_date",
|
||||||
|
"created_date",
|
||||||
|
"label"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"token": {
|
||||||
|
"pattern": "^\\$2a\\$11\\$[A-Za-z0-9./]{53}$"
|
||||||
|
},
|
||||||
|
"label": {
|
||||||
|
"const": "Generated via Impersonation API"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@env-config
|
||||||
|
Scenario: admin creates auth-app token for other user
|
||||||
|
Given the config "AUTH_APP_ENABLE_IMPERSONATION" has been set to "true"
|
||||||
|
When the administrator creates app token for user "Alice" with expiration time "72h" using the auth-app API
|
||||||
|
Then the HTTP status code should be "200"
|
||||||
|
And the JSON data of the response should match
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"token",
|
||||||
|
"expiration_date",
|
||||||
|
"created_date",
|
||||||
|
"label"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"token": {
|
||||||
|
"pattern": "^[a-zA-Z0-9]{16}$"
|
||||||
|
},
|
||||||
|
"label": {
|
||||||
|
"const": "Generated via Impersonation API"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
Reference in new issue
Block a user