From ac5c136f048e8c6f44ec6b2dbb198fb14d0c7fa1 Mon Sep 17 00:00:00 2001 From: Niraj Acharya Date: Wed, 12 Feb 2025 12:29:19 +0545 Subject: [PATCH] adding test for create token for non-existing user and deleting token by a different user --- tests/acceptance/bootstrap/AuthAppContext.php | 23 +++++++++++++++ ...ected-failures-localAPI-on-OCIS-storage.md | 8 ++++++ .../features/apiAuthApp/token.feature | 28 ++++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/tests/acceptance/bootstrap/AuthAppContext.php b/tests/acceptance/bootstrap/AuthAppContext.php index d3dfa6b871d..cf035472d67 100644 --- a/tests/acceptance/bootstrap/AuthAppContext.php +++ b/tests/acceptance/bootstrap/AuthAppContext.php @@ -33,6 +33,7 @@ require_once 'bootstrap.php'; */ class AuthAppContext implements Context { private FeatureContext $featureContext; + private string $lastCreatedToken; /** * @BeforeScenario @@ -83,6 +84,7 @@ class AuthAppContext implements Context { ["expiry" => $expiration] ); $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); + $this->lastCreatedToken = json_decode($response->getBody()->getContents())->token; } /** @@ -131,6 +133,7 @@ class AuthAppContext implements Context { . "HTTP status code 200 is not the expected value " . $response->getStatusCode(), $response ); + $this->lastCreatedToken = json_decode($response->getBody()->getContents())->token; } /** @@ -237,4 +240,24 @@ class AuthAppContext implements Context { ) ); } + /** + * @When user :user tries to delete the last created auth-app token using the auth-app API + * + * @param string $user + * + * @return void + */ + public function userTriesToDeleteLastCreatedAuthAppTokensUsingTheAuthAppApi(string $user): void { + $baseUrl = $this->featureContext->getBaseUrl(); + $user = $this->featureContext->getActualUsername($user); + $password = $this->featureContext->getPasswordForUser($user); + $deleteResponse = AuthAppHelper::deleteAppAuthToken( + $baseUrl, + $user, + $password, + $this->lastCreatedToken, + ); + $this->featureContext->setResponse($deleteResponse); + $this->featureContext->pushToLastHttpStatusCodesArray((string)$deleteResponse->getStatusCode()); + } } diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index d55d844441c..b8fa2f408c0 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -342,5 +342,13 @@ The expected failures in this file are from features in the owncloud/ocis repo. - [apiOcm/deleteFederatedConnections.feature:123](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/deleteFederatedConnections.feature#L123) - [apiOcm/deleteFederatedConnections.feature:130](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/deleteFederatedConnections.feature#L130) +#### [server returns status code 500 when creating token for non-existent user (Impersonation)](https://github.com/owncloud/ocis/issues/10815) +- [apiAuthApp/token.feature:250](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiAuthApp/token.feature#L250) +- [apiAuthApp/token.feature:256](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiAuthApp/token.feature#L256) + +#### [Server returns status code 500 when deleting auth-app token of a different user](https://github.com/owncloud/ocis/issues/10921) +- [apiAuthApp/token.feature:263](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiAuthApp/token.feature#L263) +- [apiAuthApp/token.feature:269](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiAuthApp/token.feature#L269) + Note: always have an empty line at the end of this file. The bash script that processes this file requires that the last line has a newline on the end. diff --git a/tests/acceptance/features/apiAuthApp/token.feature b/tests/acceptance/features/apiAuthApp/token.feature index 64c658ea6e0..f08ec30bb2d 100644 --- a/tests/acceptance/features/apiAuthApp/token.feature +++ b/tests/acceptance/features/apiAuthApp/token.feature @@ -244,4 +244,30 @@ Feature: create auth-app token And the content in the response should include the following content: """ error parsing expiry. Use e.g. 30m or 72h - """ \ No newline at end of file + """ + + @env-config @issue-10815 + Scenario: try to create auth-app token for non-existing user + Given the config "AUTH_APP_ENABLE_IMPERSONATION" has been set to "true" + When user "Admin" creates auth-app token for user "Brian" with expiration time "72h" using the auth-app API + Then the HTTP status code should be "403" + + @env-config @issue-10815 + Scenario: try to create auth-app token for non-existing user with impersonation enabled + Given the config "AUTH_APP_ENABLE_IMPERSONATION" has been set to "true" + And user "Admin" has created auth-app token for user "Alice" with expiration time "72h" using the auth-app API + When user "Admin" tries to delete the last created auth-app token using the auth-app API + Then the HTTP status code should be "403" + + @issue-10921 + Scenario: try to delete auth-app token of a normal user by admin user + Given user "Alice" has created auth-app token with expiration time "72h" using the auth-app API + When user "Admin" tries to delete the last created auth-app token using the auth-app API + Then the HTTP status code should be "403" + + @issue-10921 + Scenario: try to delete auth-app token of a user by another non-admin user + Given user "Brian" has been created with default attributes + And user "Brian" has created auth-app token with expiration time "72h" using the auth-app API + When user "Admin" tries to delete the last created auth-app token using the auth-app API + Then the HTTP status code should be "403" \ No newline at end of file