Skip to content

Commit 072f2be

Browse files
committed
Next step is to change that getAuthorizationHeadersForApiKey(string $role) to getAuthorizationHeadersForApiKey(Role $role)
1 parent 1cbce2c commit 072f2be

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

tests/E2E/Controller/v1/Profile/GroupsControllerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ static function (stdClass $userGroup): string {
142142
*/
143143
#[DataProvider('dataProviderTestThatGroupsActionReturnExpectedWithValidApiKey')]
144144
#[TestDox(
145-
'Test that `GET /v1/profile/groups` request returns `401` with valid `$token` API key token ($role - ROLE)'
145+
'Test that `GET /v1/profile/groups` request returns `401` with valid `$token` API key token ($role - role)'
146146
)]
147147
public function testThatGroupsActionReturnExpectedWithValidApiKey(string $token, string $role): void
148148
{
149-
$client = $this->getApiKeyClient($token);
149+
$client = $this->getApiKeyClient($role);
150150
$client->request('GET', $this->baseUrl);
151151

152152
$response = $client->getResponse();
@@ -165,7 +165,7 @@ public function testThatGroupsActionReturnExpectedWithValidApiKey(string $token,
165165
self::assertSame(401, $responseContent->code, 'Response code was not expected' . $info);
166166
self::assertTrue(property_exists($responseContent, 'message'), 'Response does not contain "message"' . $info);
167167
self::assertSame(
168-
'JWT Token not found',
168+
'Invalid API key',
169169
$responseContent->message,
170170
'Response message was not expected' . $info,
171171
);
@@ -202,13 +202,13 @@ public static function dataProviderTestThatGroupsActionReturnExpectedWithValidAp
202202
{
203203
$rolesService = self::getRolesService();
204204

205-
if (getenv('USE_ALL_USER_COMBINATIONS') === 'yes') {
205+
#if (getenv('USE_ALL_USER_COMBINATIONS') === 'yes') {
206206
foreach ($rolesService->getRoles() as $role) {
207207
yield [str_pad($rolesService->getShort($role), 40, '_'), $role];
208208
}
209-
} else {
209+
#} else {
210210
yield [str_pad($rolesService->getShort(Role::LOGGED->value), 40, '_'), Role::LOGGED->value];
211-
}
211+
#}
212212
}
213213

214214
/**

tests/E2E/Controller/v1/Profile/IndexControllerTest.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ public function testThatProfileActionReturns401WithInvalidApiKey(): void
112112
* @throws JsonException
113113
*/
114114
#[DataProvider('dataProviderTestThatProfileActionReturnsExpectedWithValidApiKeyToken')]
115-
#[TestDox('Test that `GET /v1/profile` request returns `401` with valid `$token` API key token')]
116-
public function testThatProfileActionReturnsExpectedWithValidApiKeyToken(string $token): void
115+
#[TestDox('Test that `GET /v1/profile` request returns `401` with valid `$token` API key token ($role - role)')]
116+
public function testThatProfileActionReturnsExpectedWithValidApiKeyToken(string $token, string $role): void
117117
{
118-
$client = $this->getApiKeyClient($token);
118+
119+
$client = $this->getApiKeyClient($role);
119120
$client->request('GET', $this->baseUrl);
120121

121122
$response = $client->getResponse();
@@ -134,7 +135,7 @@ public function testThatProfileActionReturnsExpectedWithValidApiKeyToken(string
134135
self::assertSame(401, $responseContent->code, 'Response code was not expected' . $info);
135136
self::assertTrue(property_exists($responseContent, 'message'), 'Response does not contain "message"' . $info);
136137
self::assertSame(
137-
'JWT Token not found',
138+
'Invalid API key',
138139
$responseContent->message,
139140
'Response message was not expected' . $info,
140141
);
@@ -175,13 +176,13 @@ public static function dataProviderTestThatProfileActionReturnsExpectedWithValid
175176
{
176177
$rolesService = self::getRolesService();
177178

178-
if (getenv('USE_ALL_USER_COMBINATIONS') === 'yes') {
179+
#if (getenv('USE_ALL_USER_COMBINATIONS') === 'yes') {
179180
foreach ($rolesService->getRoles() as $role) {
180-
yield [str_pad($rolesService->getShort($role), 40, '_')];
181+
yield [str_pad($rolesService->getShort($role), 40, '_'), $role];
181182
}
182-
} else {
183-
yield [str_pad($rolesService->getShort(Role::LOGGED->value), 40, '_')];
184-
}
183+
#} else {
184+
yield [str_pad($rolesService->getShort(Role::LOGGED->value), 40, '_'), Role::LOGGED->value];
185+
#}
185186
}
186187

187188
/**

tests/E2E/Controller/v1/Profile/RolesControllerTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ public function testThatRolesActionReturnsExpected(string $u, string $p, Stringa
113113
* @throws JsonException
114114
*/
115115
#[DataProvider('dataProviderTestThatRolesActionReturnsExpectedWithValidApiKey')]
116-
#[TestDox('Test that `GET /v1/profile/roles` request returns `401` with valid API key `$token` token')]
117-
public function testThatRolesActionReturnsExpectedWithValidApiKey(string $token): void
116+
#[TestDox(
117+
'Test that `GET /v1/profile/roles` request returns `401` with valid API key `$token` token ($role - role)'
118+
)]
119+
public function testThatRolesActionReturnsExpectedWithValidApiKey(string $token, string $role): void
118120
{
119-
$client = $this->getApiKeyClient($token);
121+
$client = $this->getApiKeyClient($role);
120122
$client->request('GET', $this->baseUrl);
121123

122124
$response = $client->getResponse();
@@ -135,7 +137,7 @@ public function testThatRolesActionReturnsExpectedWithValidApiKey(string $token)
135137
self::assertSame(401, $responseContent->code, 'Response code was not expected' . $info);
136138
self::assertTrue(property_exists($responseContent, 'message'), 'Response does not contain "message"' . $info);
137139
self::assertSame(
138-
'JWT Token not found',
140+
'Invalid API key',
139141
$responseContent->message,
140142
'Response message was not expected' . $info,
141143
);
@@ -212,7 +214,7 @@ public static function dataProviderTestThatRolesActionReturnsExpected(): Generat
212214
}
213215

214216
/**
215-
* @return Generator<array-key, array{0: string}>
217+
* @return Generator<array-key, array{0: string, 1: string}>
216218
*
217219
* @throws Throwable
218220
*/
@@ -222,10 +224,10 @@ public static function dataProviderTestThatRolesActionReturnsExpectedWithValidAp
222224

223225
if (getenv('USE_ALL_USER_COMBINATIONS') === 'yes') {
224226
foreach ($rolesService->getRoles() as $role) {
225-
yield [str_pad($rolesService->getShort($role), 40, '_')];
227+
yield [str_pad($rolesService->getShort($role), 40, '_'), $role];
226228
}
227229
} else {
228-
yield [str_pad($rolesService->getShort(Role::LOGGED->value), 40, '_')];
230+
yield [str_pad($rolesService->getShort(Role::LOGGED->value), 40, '_'), Role::LOGGED->value];
229231
}
230232
}
231233

tests/E2E/TestCase/Auth.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,10 @@ public function getAuthorizationHeadersForUser(string $username, string $passwor
5959
*/
6060
public function getAuthorizationHeadersForApiKey(string $role): array
6161
{
62-
// If role is not valid role enum value then we assume that it's API key token
63-
$token = (Role::tryFrom($role) === null ? $role : str_pad($role, 40, '_'));
64-
6562
return [
6663
...$this->getContentTypeHeader(),
6764
...[
68-
'HTTP_AUTHORIZATION' => 'ApiKey ' . $token,
65+
'HTTP_AUTHORIZATION' => 'ApiKey ' . str_pad($role, 40, '_'),
6966
],
7067
];
7168
}

0 commit comments

Comments
 (0)