|
23 | 23 | use Behat\Behat\Context\Context;
|
24 | 24 | use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
25 | 25 | use TestHelpers\BehatHelper;
|
| 26 | +use PHPUnit\Framework\Assert; |
26 | 27 | use TestHelpers\AuthAppHelper;
|
27 | 28 |
|
28 | 29 | require_once 'bootstrap.php';
|
|
32 | 33 | */
|
33 | 34 | class AuthAppContext implements Context {
|
34 | 35 | private FeatureContext $featureContext;
|
| 36 | + private array $lastHttpStatusCodesArray = []; |
35 | 37 |
|
36 | 38 | /**
|
37 | 39 | * @BeforeScenario
|
@@ -154,4 +156,66 @@ public function theAdministratorCreatesAppTokenForUserWithExpirationTimeViaAuthA
|
154 | 156 | )
|
155 | 157 | );
|
156 | 158 | }
|
| 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 | + } |
157 | 221 | }
|
0 commit comments