Skip to content

Commit

Permalink
Fix ci 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhelias authored and chalasr committed Feb 12, 2023
1 parent 8f23254 commit be8ed34
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ jobs:
- name: CONDING STANDARDS (RECTOR)
run: |
vendor/bin/rector process --ansi --dry-run --xdebug
2 changes: 1 addition & 1 deletion Command/GenerateTokenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions Services/JWSProvider/LcobucciJWSProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
);

Expand All @@ -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))
);

Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/CompleteTokenAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -129,6 +129,6 @@ protected function assertSuccessful(Response $response)

protected function accessSecuredRoute()
{
static::$client->request('GET', '/api/secured');
static::$client->jsonRequest('GET', '/api/secured');
}
}
10 changes: 5 additions & 5 deletions Tests/Functional/GetTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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".');
Expand All @@ -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()));
Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion Tests/Functional/Utils/CallableEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/app/config/security_in_memory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/app/config/security_lexik_jwt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Tests/Services/JWSProvider/LcobucciJWSProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public function testCreateWithEcdsa()
->expects($this->once())
->method('loadKey')
->with('private')
->willReturn(<<<EOF
->willReturn(
<<<EOF
-----BEGIN EC PRIVATE KEY-----
MIHcAgEBBEIB+EYtmPtvg88MzxsRzgDGlKh+Z/iU99nmgKUjnw7+3eePeNQjaALU
DH+P7PNnF9nwfmQGTUBgQwtznmLAQcVdB3GgBwYFK4EEACOhgYkDgYYABAFp/WFf
Expand All @@ -87,7 +88,7 @@ public function testCreateWithEcdsa()
TkeeWHzDF5tKLvuO0HGEX9N7Fn0dOBWZYVSDk/iaZw==
-----END EC PRIVATE KEY-----
EOF
);
);
$keyLoaderMock
->expects($this->once())
->method('getPassphrase')
Expand Down
3 changes: 1 addition & 2 deletions TokenExtractor/ChainTokenExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
</filter>

<php>
<env name="SYMFONY_PHPUNIT_VERSION" value="9.5"></env>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0&amp;max[direct]=27"></env>
</php>
</phpunit>
22 changes: 15 additions & 7 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
]);
};

0 comments on commit be8ed34

Please sign in to comment.