Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only][full-ci] adding test for create token for non-existing user and deleting token by a different user #10993

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions tests/acceptance/bootstrap/AuthAppContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*/
class AuthAppContext implements Context {
private FeatureContext $featureContext;
private array $createdAuthAppToken = [];

/**
* @BeforeScenario
Expand Down Expand Up @@ -83,6 +84,7 @@ public function userHasCreatedAppTokenWithExpirationTime(string $user, string $e
["expiry" => $expiration]
);
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response);
$this->createdAuthAppToken[] = $response;
}

/**
Expand Down Expand Up @@ -129,25 +131,28 @@ public function theAdministratorHasCreatedAppTokenWithExpirationTimeImpersonatin
. "HTTP status code 200 is not the expected value " . $response->getStatusCode(),
$response
);
$this->createdAuthAppToken[] = $response;
}

/**
* @When the administrator creates app token for user :impersonatedUser with expiration time :expiration using the auth-app API
* @When user :user creates app token for user :impersonatedUser with expiration time :expiration using the auth-app API
*
* @param string $user
* @param string $impersonatedUser
* @param string $expiration
*
* @return void
*/
public function theAdministratorCreatesAppTokenForUserWithExpirationTimeViaAuthAppApi(
string $user,
string $impersonatedUser,
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),
[
"expiry" => $expiration,
"userName" => $this->featureContext->getActualUsername($impersonatedUser)
Expand Down Expand Up @@ -207,4 +212,26 @@ public function userShouldHaveAuthAppTokens(string $user, int $count): void {
);
}

/**
* @When user :user tries to deletes last created auth-app tokens using the auth-app API
*
* @param string $user
*
* @return void
*/
public function userTriesToDeletesLastCreatedAuthAppTokensUsingTheAuthAppApi(string $user): void {
$baseUrl = $this->featureContext->getBaseUrl();
$user = $this->featureContext->getActualUsername($user);
$password = $this->featureContext->getPasswordForUser($user);
$response = \end($this->createdAuthAppToken);
$authAppTokens = json_decode($response->getBody()->getContents());
$deleteResponse = AuthAppHelper::deleteAppAuthToken(
$baseUrl,
$user,
$password,
$authAppTokens->token
);
$this->featureContext->setResponse($deleteResponse);
$this->featureContext->pushToLastHttpStatusCodesArray((string)$deleteResponse->getStatusCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -324,5 +324,13 @@ The expected failures in this file are from features in the owncloud/ocis repo.
- [apiServiceAvailability/serviceAvailabilityCheck.feature:116](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiServiceAvailability/serviceAvailabilityCheck.feature#L116)
- [apiServiceAvailability/serviceAvailabilityCheck.feature:125](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiServiceAvailability/serviceAvailabilityCheck.feature#L125)

#### [server returns status code 500 when creating token for non-existent user (Impersonation)](https://github.com/owncloud/ocis/issues/10815)
- [apiAuthApp/token.feature:135](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiAuthApp/token.feature#L135)
- [apiAuthApp/token.feature:141](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiAuthApp/token.feature#L141)

#### [Server returns status code 500 when deleting auth-app token of a different user](https://github.com/owncloud/ocis/issues/10921)
- [apiAuthApp/token.feature:148](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiAuthApp/token.feature#L148)
- [apiAuthApp/token.feature:154](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiAuthApp/token.feature#L154)

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.
30 changes: 28 additions & 2 deletions tests/acceptance/features/apiAuthApp/token.feature
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Feature: create auth-app token
@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
When user "Admin" 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
"""
Expand Down Expand Up @@ -129,4 +129,30 @@ Feature: create auth-app token
"minItems": 0,
"maxItems": 0
}
"""
"""

@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 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 the administrator has created app token for user "Alice" with expiration time "72h" using the auth-app API
When user "Admin" tries to deletes last created auth-app tokens using the auth-app API
Then the HTTP status code should be "403"

@issue-10921
Scenario: try to delete auth-app token by admin user
Given user "Alice" has created app token with expiration time "72h" using the auth-app API
When user "Admin" tries to deletes last created auth-app tokens 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 user
Given user "Brian" has been created with default attributes
And user "Brian" has created app token with expiration time "72h" using the auth-app API
When user "Admin" tries to deletes last created auth-app tokens using the auth-app API
Then the HTTP status code should be "403"