Skip to content

Commit

Permalink
Merge pull request #10660 from owncloud/test-auth-app-token
Browse files Browse the repository at this point in the history
[tests-only][full-ci] adding test for creating auth token for an app using cli
  • Loading branch information
S-Panta authored Dec 24, 2024
2 parents a5f3ce3 + 558839f commit d9bfdda
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 21 deletions.
2 changes: 1 addition & 1 deletion tests/acceptance/bootstrap/AuthAppContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function userCreatesAppTokenWithExpirationTimeUsingTheAuthAppApi(string $
}

/**
* @Given user :user has created app token with expiration time :expiration
* @Given user :user has created app token with expiration time :expiration using the auth-app API
*
* @param string $user
* @param string $expiration
Expand Down
39 changes: 39 additions & 0 deletions tests/acceptance/bootstrap/CliContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,45 @@ public function theAdministratorChecksTheBackupConsistencyUsingTheCli():void {
];
$this->featureContext->setResponse(CliHelper::runCommand($body));
}

/**
* @When the administrator creates app token for user :user with expiration time :expirationTime using the auth-app CLI
*
* @param string $user
* @param string $expirationTime
*
* @return void
*/
public function theAdministratorCreatesAppTokenForUserWithExpirationTimeUsingTheAuthAppCLI(string $user, string $expirationTime): void {
$user = $this->featureContext->getActualUserName($user);
$command = "auth-app create --user-name=$user --expiration=$expirationTime";
$body = [
"command" => $command
];
$this->featureContext->setResponse(CliHelper::runCommand($body));
}

/**
* @Given user :user has created app token with expiration time :expirationTime using the auth-app CLI
*
* @param string $user
* @param string $expirationTime
*
* @return void
*/
public function userHasCreatedAppTokenWithExpirationTimeUsingTheAuthAppCLI(string $user, string $expirationTime): void {
$user = $this->featureContext->getActualUserName($user);
$command = "auth-app create --user-name=$user --expiration=$expirationTime";
$body = [
"command" => $command
];

$response = CliHelper::runCommand($body);
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
$jsonResponse = $this->featureContext->getJsonDecodedResponse($response);
Assert::assertSame("OK", $jsonResponse["status"]);
Assert::assertSame(0, $jsonResponse["exitCode"], "Expected exit code to be 0, but got " . $jsonResponse["exitCode"]);
}

/**
* @When the administrator removes all the file versions using the CLI
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ default:
contexts:
- FeatureContext: *common_feature_context_params
- AuthAppContext:
- CliContext:

cliCommands:
paths:
Expand Down
59 changes: 39 additions & 20 deletions tests/acceptance/features/apiAuthApp/token.feature
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Feature: create auth token
Feature: create auth-app token
As a user
I want to create App Tokens
I want to create auth-app Tokens
So that I can use 3rd party apps

Background:
Given user "Alice" has been created with default attributes


Scenario: user creates app token
Scenario: user creates auth-app token
When user "Alice" creates app token 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 All @@ -22,7 +22,6 @@ Feature: create auth token
],
"properties": {
"token": {
"type": "string",
"pattern": "^[a-zA-Z0-9]{16}$"
},
"label": {
Expand All @@ -34,8 +33,8 @@ Feature: create auth token


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"
Given user "Alice" has created app token 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
When user "Alice" lists all created tokens using the auth-app API
Then the HTTP status code should be "200"
And the JSON data of the response should match
Expand All @@ -46,22 +45,42 @@ Feature: create auth token
"maxItems": 2,
"uniqueItems": true,
"items": {
"type": "object",
"required": [
"token",
"expiration_date",
"created_date",
"label"
],
"properties": {
"token": {
"type": "string",
"pattern": "^\\$2a\\$11\\$[A-Za-z0-9./]{53}$"
"oneOf": [
{
"type": "object",
"required": [
"token",
"expiration_date",
"created_date",
"label"
],
"properties": {
"token": {
"pattern": "^\\$2a\\$11\\$[A-Za-z0-9./]{53}$"
},
"label": {
"const": "Generated via API"
}
}
},
"label": {
"const": "Generated via API"
{
"type": "object",
"required": [
"token",
"expiration_date",
"created_date",
"label"
],
"properties": {
"token": {
"pattern": "^\\$2a\\$11\\$[A-Za-z0-9./]{53}$"
},
"label": {
"const": "Generated via CLI"
}
}
}
}
]
}
}
"""
16 changes: 16 additions & 0 deletions tests/acceptance/features/cliCommands/authAppToken.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@env-config
Feature: create auth-app token
As an admin
I want to create auth-app Tokens
So that I can use 3rd party apps


Scenario: creates auth-app token via CLI
Given the following configs have been set:
| config | value |
| OCIS_ADD_RUN_SERVICES | auth-app |
| PROXY_ENABLE_APP_AUTH | true |
And user "Alice" has been created with default attributes
When the administrator creates app token for user "Alice" with expiration time "72h" using the auth-app CLI
Then the command should be successful
And the command output should contain "App token created for Alice"

0 comments on commit d9bfdda

Please sign in to comment.