Skip to content

Commit d9bfdda

Browse files
authored
Merge pull request #10660 from owncloud/test-auth-app-token
[tests-only][full-ci] adding test for creating auth token for an app using cli
2 parents a5f3ce3 + 558839f commit d9bfdda

File tree

5 files changed

+96
-21
lines changed

5 files changed

+96
-21
lines changed

tests/acceptance/bootstrap/AuthAppContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function userCreatesAppTokenWithExpirationTimeUsingTheAuthAppApi(string $
6868
}
6969

7070
/**
71-
* @Given user :user has created app token with expiration time :expiration
71+
* @Given user :user has created app token with expiration time :expiration using the auth-app API
7272
*
7373
* @param string $user
7474
* @param string $expiration

tests/acceptance/bootstrap/CliContext.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,45 @@ public function theAdministratorChecksTheBackupConsistencyUsingTheCli():void {
121121
];
122122
$this->featureContext->setResponse(CliHelper::runCommand($body));
123123
}
124+
125+
/**
126+
* @When the administrator creates app token for user :user with expiration time :expirationTime using the auth-app CLI
127+
*
128+
* @param string $user
129+
* @param string $expirationTime
130+
*
131+
* @return void
132+
*/
133+
public function theAdministratorCreatesAppTokenForUserWithExpirationTimeUsingTheAuthAppCLI(string $user, string $expirationTime): void {
134+
$user = $this->featureContext->getActualUserName($user);
135+
$command = "auth-app create --user-name=$user --expiration=$expirationTime";
136+
$body = [
137+
"command" => $command
138+
];
139+
$this->featureContext->setResponse(CliHelper::runCommand($body));
140+
}
141+
142+
/**
143+
* @Given user :user has created app token with expiration time :expirationTime using the auth-app CLI
144+
*
145+
* @param string $user
146+
* @param string $expirationTime
147+
*
148+
* @return void
149+
*/
150+
public function userHasCreatedAppTokenWithExpirationTimeUsingTheAuthAppCLI(string $user, string $expirationTime): void {
151+
$user = $this->featureContext->getActualUserName($user);
152+
$command = "auth-app create --user-name=$user --expiration=$expirationTime";
153+
$body = [
154+
"command" => $command
155+
];
156+
157+
$response = CliHelper::runCommand($body);
158+
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
159+
$jsonResponse = $this->featureContext->getJsonDecodedResponse($response);
160+
Assert::assertSame("OK", $jsonResponse["status"]);
161+
Assert::assertSame(0, $jsonResponse["exitCode"], "Expected exit code to be 0, but got " . $jsonResponse["exitCode"]);
162+
}
124163

125164
/**
126165
* @When the administrator removes all the file versions using the CLI

tests/acceptance/config/behat.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ default:
431431
contexts:
432432
- FeatureContext: *common_feature_context_params
433433
- AuthAppContext:
434+
- CliContext:
434435

435436
cliCommands:
436437
paths:
Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
Feature: create auth token
1+
Feature: create auth-app token
22
As a user
3-
I want to create App Tokens
3+
I want to create auth-app Tokens
44
So that I can use 3rd party apps
55

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

99

10-
Scenario: user creates app token
10+
Scenario: user creates auth-app token
1111
When user "Alice" creates app token with expiration time "72h" using the auth-app API
1212
Then the HTTP status code should be "200"
1313
And the JSON data of the response should match
@@ -22,7 +22,6 @@ Feature: create auth token
2222
],
2323
"properties": {
2424
"token": {
25-
"type": "string",
2625
"pattern": "^[a-zA-Z0-9]{16}$"
2726
},
2827
"label": {
@@ -34,8 +33,8 @@ Feature: create auth token
3433

3534

3635
Scenario: user lists app tokens
37-
Given user "Alice" has created app token with expiration time "72h"
38-
And user "Alice" has created app token with expiration time "2h"
36+
Given user "Alice" has created app token with expiration time "72h" using the auth-app API
37+
And user "Alice" has created app token with expiration time "72h" using the auth-app CLI
3938
When user "Alice" lists all created tokens using the auth-app API
4039
Then the HTTP status code should be "200"
4140
And the JSON data of the response should match
@@ -46,22 +45,42 @@ Feature: create auth token
4645
"maxItems": 2,
4746
"uniqueItems": true,
4847
"items": {
49-
"type": "object",
50-
"required": [
51-
"token",
52-
"expiration_date",
53-
"created_date",
54-
"label"
55-
],
56-
"properties": {
57-
"token": {
58-
"type": "string",
59-
"pattern": "^\\$2a\\$11\\$[A-Za-z0-9./]{53}$"
48+
"oneOf": [
49+
{
50+
"type": "object",
51+
"required": [
52+
"token",
53+
"expiration_date",
54+
"created_date",
55+
"label"
56+
],
57+
"properties": {
58+
"token": {
59+
"pattern": "^\\$2a\\$11\\$[A-Za-z0-9./]{53}$"
60+
},
61+
"label": {
62+
"const": "Generated via API"
63+
}
64+
}
6065
},
61-
"label": {
62-
"const": "Generated via API"
66+
{
67+
"type": "object",
68+
"required": [
69+
"token",
70+
"expiration_date",
71+
"created_date",
72+
"label"
73+
],
74+
"properties": {
75+
"token": {
76+
"pattern": "^\\$2a\\$11\\$[A-Za-z0-9./]{53}$"
77+
},
78+
"label": {
79+
"const": "Generated via CLI"
80+
}
81+
}
6382
}
64-
}
83+
]
6584
}
6685
}
6786
"""
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@env-config
2+
Feature: create auth-app token
3+
As an admin
4+
I want to create auth-app Tokens
5+
So that I can use 3rd party apps
6+
7+
8+
Scenario: creates auth-app token via CLI
9+
Given the following configs have been set:
10+
| config | value |
11+
| OCIS_ADD_RUN_SERVICES | auth-app |
12+
| PROXY_ENABLE_APP_AUTH | true |
13+
And user "Alice" has been created with default attributes
14+
When the administrator creates app token for user "Alice" with expiration time "72h" using the auth-app CLI
15+
Then the command should be successful
16+
And the command output should contain "App token created for Alice"

0 commit comments

Comments
 (0)