1 | <?php |
||
19 | class AuthenticatorTest extends \PHPUnit_Framework_TestCase |
||
20 | { |
||
21 | // @codingStandardsIgnoreStart |
||
22 | |||
23 | /** |
||
24 | * Created using jwt.io |
||
25 | */ |
||
26 | const TEST_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtleU9uZSJ9.eyJwcm4iOiJqb2huIiwiaXNzIjoiaHR0cDovL2FwaS5zZXJ2ZXIxLmNvbS9vYXV0aDIvdG9rZW4ifQ._jXjAWMzwwG1v5N3ZOEUoLGSINtmwLsvQdfYkYAcWiY'; |
||
27 | |||
28 | const JKEY_CLASS = 'KleijnWeb\JwtBundle\Authenticator\JwtKey'; |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | private static $keyConfig = [ |
||
34 | 'keyOne' => |
||
35 | [ |
||
36 | 'issuer' => 'http://api.server1.com/oauth2/token', |
||
37 | 'secret' => 'A Pre-Shared Key', |
||
38 | 'type' => 'HS256', |
||
39 | ], |
||
40 | 'keyTwo' => |
||
41 | [ |
||
42 | 'issuer' => 'http://api.server2.com/oauth2/token', |
||
43 | 'type' => 'RS256', |
||
44 | 'secret' => 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0F', |
||
45 | ], |
||
46 | ]; |
||
47 | |||
48 | // @codingStandardsIgnoreEnd |
||
49 | |||
50 | /** |
||
51 | * @var JwtKey[] |
||
52 | */ |
||
53 | private $keys = []; |
||
54 | |||
55 | protected function setUp() |
||
62 | |||
63 | /** |
||
64 | * @test |
||
65 | */ |
||
66 | public function getGetKeysUsingIndexesInConfig() |
||
73 | |||
74 | /** |
||
75 | * @test |
||
76 | */ |
||
77 | public function willGetSingleKeyWhenKeyIdIsNull() |
||
86 | |||
87 | /** |
||
88 | * @test |
||
89 | * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException |
||
90 | */ |
||
91 | public function willFailWhenTryingToGetKeyWithoutIdWhenThereAreMoreThanOne() |
||
97 | |||
98 | /** |
||
99 | * @test |
||
100 | * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException |
||
101 | */ |
||
102 | public function willFailWhenTryingToGetUnknownKey() |
||
108 | |||
109 | /** |
||
110 | * @test |
||
111 | * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException |
||
112 | */ |
||
113 | public function willFailWhenTryingToGetUserNameFromClaimsWithoutPrn() |
||
119 | |||
120 | /** |
||
121 | * @test |
||
122 | */ |
||
123 | public function canGetUserNameFromClaims() |
||
129 | |||
130 | /** |
||
131 | * @test |
||
132 | */ |
||
133 | public function authenticateTokenWillSetUserFetchedFromUserProviderOnToken() |
||
148 | |||
149 | /** |
||
150 | * @test |
||
151 | */ |
||
152 | public function supportsPreAuthToken() |
||
160 | |||
161 | /** |
||
162 | * @test |
||
163 | * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException |
||
164 | */ |
||
165 | public function willFailWhenApiKeyNotFoundInHeader() |
||
171 | |||
172 | /** |
||
173 | * @test |
||
174 | */ |
||
175 | public function canGetAnonTokenWithClaims() |
||
185 | } |
||
186 |