Skip to content

Commit c344afd

Browse files
committed
adding test for deleting auth token using cli
1 parent c73d253 commit c344afd

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

tests/acceptance/TestHelpers/AuthAppHelper.php

+25
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,29 @@ public static function deleteAppAuthToken(
105105
$password,
106106
);
107107
}
108+
109+
/**
110+
* @param string $baseUrl
111+
* @param string $user
112+
* @param string $password
113+
* @param string $expiration
114+
* @param string $impersonatorUser
115+
*
116+
* @return ResponseInterface
117+
*/
118+
public static function createAuthAppTokenViaImpersonationAPI(
119+
string $baseUrl,
120+
string $user,
121+
string $password,
122+
string $expiration,
123+
string $impersonatorUser
124+
): ResponseInterface {
125+
$url = $baseUrl . self::getAuthAppEndpoint() . "?expiry=$expiration&userName=$impersonatorUser";
126+
return HttpRequestHelper::post(
127+
$url,
128+
null,
129+
$user,
130+
$password,
131+
);
132+
}
108133
}

tests/acceptance/bootstrap/AuthAppContext.php

+64
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Behat\Behat\Context\Context;
2424
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
2525
use TestHelpers\BehatHelper;
26+
use PHPUnit\Framework\Assert;
2627
use TestHelpers\AuthAppHelper;
2728

2829
require_once 'bootstrap.php';
@@ -32,6 +33,7 @@
3233
*/
3334
class AuthAppContext implements Context {
3435
private FeatureContext $featureContext;
36+
private array $lastHttpStatusCodesArray = [];
3537

3638
/**
3739
* @BeforeScenario
@@ -154,4 +156,66 @@ public function theAdministratorCreatesAppTokenForUserWithExpirationTimeViaAuthA
154156
)
155157
);
156158
}
159+
160+
/**
161+
* @When user :user delets all created auth-app token
162+
*
163+
* @param string $user
164+
*
165+
* @return void
166+
*/
167+
public function userDeletsAllCreatedAuthAppToken(string $user): void {
168+
$responses = AuthAppHelper::listAllAppAuthTokensForUser(
169+
$this->featureContext->getBaseUrl(),
170+
$this->featureContext->getActualUsername($user),
171+
$this->featureContext->getPasswordForUser($user),
172+
);
173+
$responses = json_decode($responses->getBody()->getContents());
174+
foreach ($responses as $response) {
175+
$deleteResponse = AuthAppHelper::deleteAppAuthToken(
176+
$this->featureContext->getBaseUrl(),
177+
$this->featureContext->getActualUsername($user),
178+
$this->featureContext->getPasswordForUser($user),
179+
$response->token
180+
);
181+
$this->lastHttpStatusCodesArray[] = $deleteResponse->getStatusCode();
182+
}
183+
}
184+
185+
/**
186+
* @When the HTTP status code of responses on each endpoint should be :statusCodes
187+
*
188+
* @param string $statusCodes a comma-separated string of expected HTTP status codes
189+
*
190+
* @return void
191+
* @throws Exception
192+
*/
193+
public function checkTheHTTPStatusCodeOfResponsesOnEachEndpoint(string $statusCodes): void {
194+
Assert::assertTrue(
195+
$statusCodes === implode(',', $this->lastHttpStatusCodesArray)
196+
);
197+
$this->lastHttpStatusCodesArray = [];
198+
}
199+
200+
/**
201+
* @Given the administrator has created app token with expiration time :expiration Impersonating user :impersonatedUser using the auth-app Impersonation API
202+
*
203+
* @param string $expiration
204+
* @param string $impersonatedUser
205+
*
206+
* @return void
207+
*/
208+
public function theAdministratorHasCreatedAppTokenWithExpirationTimeImpersonatingUserUsingTheApi(
209+
string $expiration,
210+
string $impersonatedUser
211+
): void {
212+
$response = AuthAppHelper::createAuthAppTokenViaImpersonationAPI(
213+
$this->featureContext->getBaseUrl(),
214+
$this->featureContext->getAdminUsername(),
215+
$this->featureContext->getAdminPassword(),
216+
$expiration,
217+
$this->featureContext->getActualUsername($impersonatedUser),
218+
);
219+
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response);
220+
}
157221
}

tests/acceptance/features/apiAuthApp/token.feature

+9
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,12 @@ Feature: create auth-app token
129129
}
130130
}
131131
"""
132+
133+
@env-config
134+
Scenario: user deleats auth-app token
135+
Given the config "AUTH_APP_ENABLE_IMPERSONATION" has been set to "true"
136+
And user "Alice" has created app token with expiration time "72h" using the auth-app API
137+
And the administrator has created app token with expiration time "72h" Impersonating user "Alice" using the auth-app Impersonation API
138+
And user "Alice" has created app token with expiration time "72h" using the auth-app CLI
139+
When user "Alice" delets all created auth-app token
140+
Then the HTTP status code of responses on each endpoint should be "200,200,200"

0 commit comments

Comments
 (0)