Skip to content

Commit

Permalink
Merge branch '7.0' into 7.1
Browse files Browse the repository at this point in the history
* 7.0:
  fix merge
  Add test for AccessTokenHeaderRegex and adjust regex
  • Loading branch information
xabbuh committed Apr 19, 2024
2 parents 924e4d8 + bee1999 commit 02c1e3c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 46 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(
private readonly string $tokenType = 'Bearer',
) {
$this->regex = sprintf(
'/^%s([a-zA-Z0-9\-_\+~\/\.]+)$/',
'/^%s([a-zA-Z0-9\-_\+~\/\.]+=*)$/',
'' === $this->tokenType ? '' : preg_quote($this->tokenType).'\s+'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Security\Core\User\InMemoryUserProvider;
use Symfony\Component\Security\Http\AccessToken\AccessTokenExtractorInterface;
use Symfony\Component\Security\Http\AccessToken\AccessTokenHandlerInterface;
use Symfony\Component\Security\Http\AccessToken\HeaderAccessTokenExtractor;
use Symfony\Component\Security\Http\Authenticator\AccessTokenAuthenticator;
use Symfony\Component\Security\Http\Authenticator\FallbackUserLoader;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
Expand Down Expand Up @@ -159,4 +160,31 @@ public function testAuthenticateWithFallbackUserLoader()

$this->assertEquals('test', $passport->getUser()->getUserIdentifier());
}

/**
* @dataProvider provideAccessTokenHeaderRegex
*/
public function testAccessTokenHeaderRegex(string $input, ?string $expectedToken)
{
// Given
$extractor = new HeaderAccessTokenExtractor();
$request = Request::create('/test', 'GET', [], [], [], ['HTTP_AUTHORIZATION' => $input]);

// When
$token = $extractor->extractAccessToken($request);

// Then
$this->assertEquals($expectedToken, $token);
}

public function provideAccessTokenHeaderRegex(): array
{
return [
['Bearer token', 'token'],
['Bearer mF_9.B5f-4.1JqM', 'mF_9.B5f-4.1JqM'],
['Bearer d3JvbmdfcmVnZXhwX2V4bWFwbGU=', 'd3JvbmdfcmVnZXhwX2V4bWFwbGU='],
['Bearer Not Valid', null],
['Bearer (NotOK123)', null],
];
}
}

0 comments on commit 02c1e3c

Please sign in to comment.