Skip to content

Commit b18a750

Browse files
committed
Better fix
1 parent 122c278 commit b18a750

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static function (stdClass $userGroup): string {
146146
)]
147147
public function testThatGroupsActionReturnExpectedWithValidApiKey(string $token, string $role): void
148148
{
149-
$client = $this->getApiKeyClient($role);
149+
$client = $this->getApiKeyClient($token);
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-
'Invalid API key',
168+
'JWT Token not found',
169169
$responseContent->message,
170170
'Response message was not expected' . $info,
171171
);

tests/E2E/TestCase/Auth.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace App\Tests\E2E\TestCase;
1010

11+
use App\Enum\Role;
1112
use App\Utils\JSON;
1213
use JsonException;
1314
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
@@ -58,10 +59,13 @@ public function getAuthorizationHeadersForUser(string $username, string $passwor
5859
*/
5960
public function getAuthorizationHeadersForApiKey(string $role): array
6061
{
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+
6165
return [
6266
...$this->getContentTypeHeader(),
6367
...[
64-
'HTTP_AUTHORIZATION' => 'ApiKey ' . str_pad($role, 40, '_'),
68+
'HTTP_AUTHORIZATION' => 'ApiKey ' . $token,
6569
],
6670
];
6771
}

0 commit comments

Comments
 (0)