From be8ed345892458d1aafb5434b931b4104e63b703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20H=C3=A9lias?= Date: Fri, 10 Feb 2023 22:06:45 +0100 Subject: [PATCH] Fix ci 2.x --- .github/workflows/ci.yml | 4 ++-- .github/workflows/coding-standards.yml | 1 - Command/GenerateTokenCommand.php | 2 +- Services/JWSProvider/LcobucciJWSProvider.php | 6 +++-- .../CompleteTokenAuthenticationTest.php | 4 ++-- Tests/Functional/GetTokenTest.php | 10 ++++----- Tests/Functional/TestCase.php | 2 +- .../Utils/CallableEventSubscriber.php | 1 - .../app/config/security_in_memory.yml | 4 ++-- .../app/config/security_lexik_jwt.yml | 4 ++-- .../JWSProvider/LcobucciJWSProviderTest.php | 5 +++-- TokenExtractor/ChainTokenExtractor.php | 3 +-- composer.json | 4 ++-- phpunit.xml.dist | 1 + rector.php | 22 +++++++++++++------ 15 files changed, 41 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11333e6a..8ce9ccd9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,8 +13,8 @@ jobs: matrix: include: # Lowest Deps - - php: 7.1 - symfony: 4.4.* + - php: 7.2 + symfony: 5.4.* composer-flags: '--prefer-stable --prefer-lowest' can-fail: false # LTS with latest stable PHP diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 2e2ddbf8..ad8eba60 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -36,4 +36,3 @@ jobs: - name: CONDING STANDARDS (RECTOR) run: | vendor/bin/rector process --ansi --dry-run --xdebug - diff --git a/Command/GenerateTokenCommand.php b/Command/GenerateTokenCommand.php index af8ac7d3..f7eb7a00 100644 --- a/Command/GenerateTokenCommand.php +++ b/Command/GenerateTokenCommand.php @@ -91,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $payload = []; - + if (null !== $input->getOption('ttl') && ((int) $input->getOption('ttl')) == 0) { $payload['exp'] = 0; } elseif (null !== $input->getOption('ttl') && ((int) $input->getOption('ttl')) > 0) { diff --git a/Services/JWSProvider/LcobucciJWSProvider.php b/Services/JWSProvider/LcobucciJWSProvider.php index 8b0f748e..1f2900f8 100644 --- a/Services/JWSProvider/LcobucciJWSProvider.php +++ b/Services/JWSProvider/LcobucciJWSProvider.php @@ -23,6 +23,7 @@ use Lcobucci\JWT\Token\RegisteredClaims; use Lcobucci\JWT\Validation\Constraint\LooseValidAt; use Lcobucci\JWT\Validation\Constraint\SignedWith; +use Lcobucci\JWT\Validation\Constraint\ValidAt; use Lcobucci\JWT\Validation\Validator; use Lcobucci\JWT\ValidationData; use Lexik\Bundle\JWTAuthenticationBundle\Services\KeyLoader\KeyLoaderInterface; @@ -259,10 +260,11 @@ private function verify(Token $jwt) } $validator = new Validator(); + $classValidator = class_exists(LooseValidAt::class) ? LooseValidAt::class : ValidAt::class; $isValid = $validator->validate( $jwt, - new LooseValidAt($this->clock, new \DateInterval("PT{$this->clockSkew}S")), + new $classValidator($this->clock, new \DateInterval("PT{$this->clockSkew}S")), new SignedWith($this->signer, $key) ); @@ -275,7 +277,7 @@ private function verify(Token $jwt) foreach ($publicKeys as $key) { $isValid = $validator->validate( $jwt, - new LooseValidAt($this->clock, new \DateInterval("PT{$this->clockSkew}S")), + new $classValidator($this->clock, new \DateInterval("PT{$this->clockSkew}S")), new SignedWith($this->signer, InMemory::plainText($key)) ); diff --git a/Tests/Functional/CompleteTokenAuthenticationTest.php b/Tests/Functional/CompleteTokenAuthenticationTest.php index 72a6e92e..1716d477 100644 --- a/Tests/Functional/CompleteTokenAuthenticationTest.php +++ b/Tests/Functional/CompleteTokenAuthenticationTest.php @@ -59,7 +59,7 @@ public function testAccessSecuredRouteWithoutToken() public function testAccessSecuredRouteWithInvalidToken($token = 'dummy') { - static::$client->request('GET', '/api/secured', [], [], ['HTTP_AUTHORIZATION' => "Bearer $token"]); + static::$client->jsonRequest('GET', '/api/secured', [], ['HTTP_AUTHORIZATION' => "Bearer $token"]); $response = static::$client->getResponse(); @@ -129,6 +129,6 @@ protected function assertSuccessful(Response $response) protected function accessSecuredRoute() { - static::$client->request('GET', '/api/secured'); + static::$client->jsonRequest('GET', '/api/secured'); } } diff --git a/Tests/Functional/GetTokenTest.php b/Tests/Functional/GetTokenTest.php index cb452abe..bc438f3f 100644 --- a/Tests/Functional/GetTokenTest.php +++ b/Tests/Functional/GetTokenTest.php @@ -18,7 +18,7 @@ class GetTokenTest extends TestCase public function testGetToken() { static::$client = static::createClient(); - static::$client->request('POST', '/login_check', ['_username' => 'lexik', '_password' => 'dummy']); + static::$client->jsonRequest('POST', '/login_check', ['username' => 'lexik', 'password' => 'dummy']); $response = static::$client->getResponse(); @@ -45,8 +45,8 @@ public function testGetTokenWithListener() $payloadTested->payload = $e->getPayload(); }); - static::$client->request('POST', '/login_check', ['_username' => 'lexik', '_password' => 'dummy']); - static::$client->request('GET', '/api/secured', [], [], ['HTTP_AUTHORIZATION' => 'Bearer ' . $this->getToken(static::$client->getResponse())]); + static::$client->jsonRequest('POST', '/login_check', ['username' => 'lexik', 'password' => 'dummy']); + static::$client->jsonRequest('GET', '/api/secured', [], ['HTTP_AUTHORIZATION' => 'Bearer ' . $this->getToken(static::$client->getResponse())]); $this->assertArrayHasKey('added_data', $payloadTested->payload, 'The payload should contains a "added_data" claim.'); $this->assertSame('still visible after the event', $payloadTested->payload['added_data'], 'The "added_data" claim should be equal to "still visible after the event".'); @@ -62,7 +62,7 @@ public function testGetTokenWithCustomClaim() $e->setHeader($e->getHeader() + ['foo' => 'bar']); }); - static::$client->request('POST', '/login_check', ['_username' => 'lexik', '_password' => 'dummy']); + static::$client->jsonRequest('POST', '/login_check', ['username' => 'lexik', 'password' => 'dummy']); $decoder = static::$kernel->getContainer()->get('lexik_jwt_authentication.encoder'); $payload = $decoder->decode($token = $this->getToken(static::$client->getResponse())); @@ -83,7 +83,7 @@ public function testGetTokenWithCustomClaim() public function testGetTokenFromInvalidCredentials() { static::$client = static::createClient(); - static::$client->request('POST', '/login_check', ['_username' => 'lexik', '_password' => 'wrong']); + static::$client->jsonRequest('POST', '/login_check', ['username' => 'lexik', 'password' => 'wrong']); $response = static::$client->getResponse(); diff --git a/Tests/Functional/TestCase.php b/Tests/Functional/TestCase.php index 4dc50bc1..e66d7d1c 100644 --- a/Tests/Functional/TestCase.php +++ b/Tests/Functional/TestCase.php @@ -43,7 +43,7 @@ protected static function getAuthenticatedToken() { $client = static::$client ?: static::createClient(); - $client->request('POST', '/login_check', ['_username' => 'lexik', '_password' => 'dummy']); + $client->jsonRequest('POST', '/login_check', ['username' => 'lexik', 'password' => 'dummy']); $response = $client->getResponse(); $responseBody = json_decode($response->getContent(), true); diff --git a/Tests/Functional/Utils/CallableEventSubscriber.php b/Tests/Functional/Utils/CallableEventSubscriber.php index bd668121..36e38e29 100644 --- a/Tests/Functional/Utils/CallableEventSubscriber.php +++ b/Tests/Functional/Utils/CallableEventSubscriber.php @@ -10,7 +10,6 @@ use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTInvalidEvent; use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTNotFoundEvent; use Lexik\Bundle\JWTAuthenticationBundle\Events; -use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class CallableEventSubscriber implements EventSubscriberInterface diff --git a/Tests/Functional/app/config/security_in_memory.yml b/Tests/Functional/app/config/security_in_memory.yml index 6484557c..eeff5932 100644 --- a/Tests/Functional/app/config/security_in_memory.yml +++ b/Tests/Functional/app/config/security_in_memory.yml @@ -10,8 +10,8 @@ security: pattern: ^/login stateless: true provider: in_memory - form_login: - check_path: /login_check + json_login: + check_path: login_check require_previous_session: false success_handler: lexik_jwt_authentication.handler.authentication_success failure_handler: lexik_jwt_authentication.handler.authentication_failure diff --git a/Tests/Functional/app/config/security_lexik_jwt.yml b/Tests/Functional/app/config/security_lexik_jwt.yml index a6b196ef..c683ee73 100644 --- a/Tests/Functional/app/config/security_lexik_jwt.yml +++ b/Tests/Functional/app/config/security_lexik_jwt.yml @@ -10,8 +10,8 @@ security: pattern: ^/login stateless: true provider: in_memory - form_login: - check_path: /login_check + json_login: + check_path: login_check require_previous_session: false success_handler: lexik_jwt_authentication.handler.authentication_success failure_handler: lexik_jwt_authentication.handler.authentication_failure diff --git a/Tests/Services/JWSProvider/LcobucciJWSProviderTest.php b/Tests/Services/JWSProvider/LcobucciJWSProviderTest.php index d02a2fcc..274d4837 100644 --- a/Tests/Services/JWSProvider/LcobucciJWSProviderTest.php +++ b/Tests/Services/JWSProvider/LcobucciJWSProviderTest.php @@ -78,7 +78,8 @@ public function testCreateWithEcdsa() ->expects($this->once()) ->method('loadKey') ->with('private') - ->willReturn(<<willReturn( + <<expects($this->once()) ->method('getPassphrase') diff --git a/TokenExtractor/ChainTokenExtractor.php b/TokenExtractor/ChainTokenExtractor.php index 4d6b2751..98c0b54d 100644 --- a/TokenExtractor/ChainTokenExtractor.php +++ b/TokenExtractor/ChainTokenExtractor.php @@ -36,8 +36,7 @@ public function addExtractor(TokenExtractorInterface $extractor) /** * Removes a token extractor from the map. * - * @param \Closure $filter A function taking an extractor as argument, - used to find the extractor to remove, + * @param \Closure $filter A function taking an extractor as argument, used to find the extractor to remove. * * @return bool True in case of success, false otherwise */ diff --git a/composer.json b/composer.json index 27c774a9..435f8d8b 100644 --- a/composer.json +++ b/composer.json @@ -52,9 +52,9 @@ "symfony/translation-contracts": "^1.0|^2.0|^3.0" }, "require-dev": { - "symfony/browser-kit": "^4.4|^5.3|^6.0", + "symfony/browser-kit": "^5.4|^6.0", "symfony/console": "^4.4|^5.3|^6.0", - "symfony/dom-crawler": "^4.4|^5.3|^6.0", + "symfony/dom-crawler": "^5.4|^6.0", "symfony/filesystem": "^4.4|^5.3|^6.0", "symfony/framework-bundle": "^4.4|^5.3|^6.0", "symfony/phpunit-bridge": "^4.4|^5.3|^6.0", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f6d1b063..28e8d939 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -28,6 +28,7 @@ + diff --git a/rector.php b/rector.php index f91cb3a5..912bec57 100644 --- a/rector.php +++ b/rector.php @@ -4,34 +4,42 @@ use Rector\Config\RectorConfig; use Rector\Core\ValueObject\PhpVersion; -use Rector\Doctrine\Set\DoctrineSetList; -use Rector\Php74\Rector\Property\TypedPropertyRector; +use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector; +use Rector\PHPUnit\Rector\Class_\AddSeeTestAnnotationRector; use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; use Rector\Symfony\Set\SymfonyLevelSetList; use Rector\Symfony\Set\SymfonySetList; +use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector; return static function (RectorConfig $rectorConfig): void { $rectorConfig->sets([ LevelSetList::UP_TO_PHP_71, SymfonyLevelSetList::UP_TO_SYMFONY_44, - SymfonySetList::SYMFONY_STRICT, SymfonySetList::SYMFONY_CODE_QUALITY, SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION, ]); $rectorConfig->phpVersion(PhpVersion::PHP_71); - $rectorConfig->importShortClasses(); + $rectorConfig->importShortClasses(false); + $rectorConfig->importNames(); $rectorConfig->bootstrapFiles([ __DIR__ . '/vendor/autoload.php', ]); + $rectorConfig->parallel(); $rectorConfig->paths([__DIR__]); $rectorConfig->skip([ + // Path __DIR__ . '/.github', + __DIR__ . '/DependencyInjection/Configuration.php', __DIR__ . '/Tests/DependencyInjection/LexikJWTAuthenticationExtensionTest.php', __DIR__ . '/vendor', - ]); - $services = $rectorConfig->services(); - $services->set(TypedPropertyRector::class); + // Rules + AddSeeTestAnnotationRector::class, + JsonThrowOnErrorRector::class, + ReturnNeverTypeRector::class => [ + __DIR__ . '/Security/User/JWTUserProvider.php', + ], + ]); };