diff --git a/.drone.star b/.drone.star index 7fa4f5a7a89..2b9be9b12ea 100644 --- a/.drone.star +++ b/.drone.star @@ -247,6 +247,7 @@ config = { "apiAuthApp", ], "skip": False, + "withRemotePhp": [True], "extraServerEnvironment": { "OCIS_ADD_RUN_SERVICES": "auth-app", "PROXY_ENABLE_APP_AUTH": True, diff --git a/tests/acceptance/TestHelpers/AuthAppHelper.php b/tests/acceptance/TestHelpers/AuthAppHelper.php index f308280b24c..61d76d5ddd4 100644 --- a/tests/acceptance/TestHelpers/AuthAppHelper.php +++ b/tests/acceptance/TestHelpers/AuthAppHelper.php @@ -28,11 +28,10 @@ * A helper class for managing Auth App API requests */ class AuthAppHelper { - /** * @return string */ - public static function getAuthAppEndpoint():string { + public static function getAuthAppEndpoint(): string { return "/auth-app/tokens"; } @@ -43,7 +42,7 @@ public static function getAuthAppEndpoint():string { * * @return ResponseInterface */ - public static function listAllAppAuthToken(string $baseUrl, string $user, string $password) : ResponseInterface { + public static function listAllAppAuthTokensForUser(string $baseUrl, string $user, string $password): ResponseInterface { $url = $baseUrl . self::getAuthAppEndpoint(); return HttpRequestHelper::sendRequest( $url, @@ -62,7 +61,7 @@ public static function listAllAppAuthToken(string $baseUrl, string $user, string * * @return ResponseInterface */ - public static function createAppAuthToken(string $baseUrl, string $user, string $password, string $expiration) : ResponseInterface { + public static function createAppAuthToken(string $baseUrl, string $user, string $password, string $expiration): ResponseInterface { $url = $baseUrl . self::getAuthAppEndpoint() . "?expiry=$expiration"; return HttpRequestHelper::sendRequest( $url, @@ -81,7 +80,7 @@ public static function createAppAuthToken(string $baseUrl, string $user, string * * @return ResponseInterface */ - public static function deleteAppAuthToken(string $baseUrl, string $user, string $password, string $token) : ResponseInterface { + public static function deleteAppAuthToken(string $baseUrl, string $user, string $password, string $token): ResponseInterface { $url = $baseUrl . self::getAuthAppEndpoint() . "?token=$token"; return HttpRequestHelper::sendRequest( $url, diff --git a/tests/acceptance/bootstrap/AuthAppContext.php b/tests/acceptance/bootstrap/AuthAppContext.php index 50f77a28ade..f8ec6577a19 100644 --- a/tests/acceptance/bootstrap/AuthAppContext.php +++ b/tests/acceptance/bootstrap/AuthAppContext.php @@ -33,7 +33,6 @@ */ class AuthAppContext implements Context { private FeatureContext $featureContext; - private array $allCreatedTokens = []; /** * @BeforeScenario @@ -50,89 +49,56 @@ public function before(BeforeScenarioScope $scope): void { } /** - * @When the administrator creates app token with expiration time :expiration using the API + * @When user :user creates app token with expiration time :expiration using the API * + * @param string $user * @param string $expiration * * @return void */ - public function theAdministratorCreatesAppTokenForUserWithExpirationTimeUsingTheApi(string $expiration): void { + public function userCreatesAppTokenWithExpirationTimeUsingTheApi(string $user, string $expiration): void { $this->featureContext->setResponse( AuthAppHelper::createAppAuthToken( $this->featureContext->getBaseUrl(), - $this->featureContext->getAdminUsername(), - $this->featureContext->getAdminPassword(), + $this->featureContext->getActualUsername($user), + $this->featureContext->getPasswordForUser($user), $expiration, ) ); } /** - * @Given the administrator has created app token with expiration time :expiration using the API + * @Given user :user has created app token with expiration time :expiration * + * @param string $user * @param string $expiration * * @return void */ - public function theAdministratorHasCreatedAppTokenWithExpirationTimeUsingTheApi(string $expiration): void { + public function userHasCreatedAppTokenWithExpirationTime(string $user, string $expiration): void { $response = AuthAppHelper::createAppAuthToken( $this->featureContext->getBaseUrl(), - $this->featureContext->getAdminUsername(), - $this->featureContext->getAdminPassword(), + $this->featureContext->getActualUsername($user), + $this->featureContext->getPasswordForUser($user), $expiration, ); $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); } /** - * @When admin lists all created tokens + * @When user :user lists all created tokens using auth API + * + * @param string $user * * @return void */ - public function adminListsAllCreatedTokens(): void { + public function userListsAllCreatedTokensUsingAuthApi(string $user): void { $this->featureContext->setResponse( - AuthAppHelper::listAllAppAuthToken( + AuthAppHelper::listAllAppAuthTokensForUser( $this->featureContext->getBaseUrl(), - $this->featureContext->getAdminUsername(), - $this->featureContext->getAdminPassword(), + $this->featureContext->getActualUsername($user), + $this->featureContext->getPasswordForUser($user), ) ); } - - /** - * @return void - */ - public function deleteAllToken() : void { - $response = AuthAppHelper::listAllAppAuthToken( - $this->featureContext->getBaseUrl(), - $this->featureContext->getAdminUsername(), - $this->featureContext->getAdminPassword(), - ); - $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); - $rawBody = $response->getBody()->getContents(); - $tokens = json_decode($rawBody); - foreach ($tokens as $token) { - $this->featureContext->theHTTPStatusCodeShouldBe( - 200, - "", - AuthAppHelper::deleteAppAuthToken( - $this->featureContext->getBaseUrl(), - $this->featureContext->getAdminUsername(), - $this->featureContext->getAdminPassword(), - $token->token - ) - ); - } - } - - /** - * @AfterScenario - * - * @return void - * - * @throws Exception|GuzzleException - */ - public function cleanDataAfterTests(): void { - $this->deleteAllToken(); - } } diff --git a/tests/acceptance/bootstrap/FeatureContext.php b/tests/acceptance/bootstrap/FeatureContext.php index 1b11fe8d34b..b7144e1e97b 100644 --- a/tests/acceptance/bootstrap/FeatureContext.php +++ b/tests/acceptance/bootstrap/FeatureContext.php @@ -1132,9 +1132,11 @@ private function validateSchemaArray(JsonSchema $schemaObj): void { Assert::fail("'$validator' should be an object not an array"); } Assert::assertFalse($value->allOf || $value->anyOf, "'allOf' and 'anyOf' are not allowed in array"); - Assert::assertNotNull($value->oneOf, "'oneOf' is required to assert more than one elements"); - Assert::assertTrue(\is_array($value->oneOf), "'oneOf' should be an array"); - Assert::assertEquals($schemaObj->maxItems, \count($value->oneOf), "Expected " . $schemaObj->maxItems . " 'oneOf' items but got " . \count($value->oneOf)); + if ($value->oneOf) { + Assert::assertNotNull($value->oneOf, "'oneOf' is required to assert more than one elements"); + Assert::assertTrue(\is_array($value->oneOf), "'oneOf' should be an array"); + Assert::assertEquals($schemaObj->maxItems, \count($value->oneOf), "Expected " . $schemaObj->maxItems . " 'oneOf' items but got " . \count($value->oneOf)); + } } Assert::assertTrue(\is_object($value), "'$validator' should be an object when expecting 1 element"); break; @@ -1226,7 +1228,7 @@ public function throwJsonSchemaException(JsonSchemaException $e): void { $errors = $this->getJsonSchemaErrors($e); $messages = ["JSON Schema validation failed:"]; - $previousPointer = ''; + $previousPointer = null; $errorCount = 0; foreach ($errors as $error) { $expected = $error->constraint; @@ -1236,6 +1238,9 @@ public function throwJsonSchemaException(JsonSchemaException $e): void { $dataPointer = \str_replace("/", ".", \trim($error->getDataPointer(), "/")); $pointer = \str_contains($schemaPointer, "additionalProperties") ? $dataPointer : $schemaPointer; + if ($pointer === '') { + $pointer = "{root}"; + } if ($pointer === $previousPointer) { continue; } diff --git a/tests/acceptance/features/apiAuthApp/token.feature b/tests/acceptance/features/apiAuthApp/token.feature index 5b2673d84ce..ba2d69fcb42 100644 --- a/tests/acceptance/features/apiAuthApp/token.feature +++ b/tests/acceptance/features/apiAuthApp/token.feature @@ -1,11 +1,14 @@ Feature: create auth token - As a admin + As a user I want to create App Tokens So that I can use 3rd party apps + Background: + Given user "Alice" has been created with default attributes - Scenario: admin creates app token - When the administrator creates app token with expiration time "72h" using the API + + Scenario: user creates app token + When user "Alice" creates app token with expiration time "72h" using the API Then the HTTP status code should be "200" And the JSON data of the response should match """ @@ -30,16 +33,18 @@ Feature: create auth token """ - Scenario: admin lists app token - Given the administrator has created app token with expiration time "72h" using the API - When admin lists all created tokens + Scenario: user lists app tokens + Given user "Alice" has created app token with expiration time "72h" + And user "Alice" has created app token with expiration time "2h" + When user "Alice" lists all created tokens using auth API Then the HTTP status code should be "200" And the JSON data of the response should match """ { "type": "array", - "minItems": 1, - "maxItems": 1, + "minItems": 2, + "maxItems": 2, + "uniqueItems": true, "items": { "type": "object", "required": [