1 | <?php |
||
20 | class AuthenticatorTest extends \PHPUnit_Framework_TestCase |
||
21 | { |
||
22 | // @codingStandardsIgnoreStart |
||
23 | |||
24 | /** |
||
25 | * Created using jwt.io |
||
26 | */ |
||
27 | const TEST_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtleU9uZSJ9.eyJwcm4iOiJqb2huIiwiaXNzIjoiaHR0cDovL2FwaS5zZXJ2ZXIxLmNvbS9vYXV0aDIvdG9rZW4ifQ._jXjAWMzwwG1v5N3ZOEUoLGSINtmwLsvQdfYkYAcWiY'; |
||
28 | |||
29 | const JKEY_CLASS = 'KleijnWeb\JwtBundle\Authenticator\JwtKey'; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | private static $keyConfig = [ |
||
35 | 'keyOne' => |
||
36 | [ |
||
37 | 'issuer' => 'http://api.server1.com/oauth2/token', |
||
38 | 'secret' => 'A Pre-Shared Key', |
||
39 | 'type' => 'HS256', |
||
40 | ], |
||
41 | 'keyTwo' => |
||
42 | [ |
||
43 | 'issuer' => 'http://api.server2.com/oauth2/token', |
||
44 | 'type' => 'RS256', |
||
45 | 'secret' => 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0F', |
||
46 | ], |
||
47 | ]; |
||
48 | |||
49 | // @codingStandardsIgnoreEnd |
||
50 | |||
51 | /** |
||
52 | * @var JwtKey[] |
||
53 | */ |
||
54 | private $keys = []; |
||
55 | |||
56 | protected function setUp() |
||
57 | { |
||
58 | foreach (self::$keyConfig as $keyId => $config) { |
||
59 | $config['kid'] = $keyId; |
||
60 | $this->keys[$keyId] = new JwtKey($config); |
||
61 | } |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @test |
||
66 | */ |
||
67 | public function getGetKeysUsingIndexesInConfig() |
||
74 | |||
75 | /** |
||
76 | * @test |
||
77 | */ |
||
78 | public function willGetSingleKeyWhenKeyIdIsNull() |
||
87 | |||
88 | /** |
||
89 | * @test |
||
90 | * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException |
||
91 | */ |
||
92 | public function willFailWhenTryingToGetKeyWithoutIdWhenThereAreMoreThanOne() |
||
98 | |||
99 | /** |
||
100 | * @test |
||
101 | * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException |
||
102 | */ |
||
103 | public function willFailWhenTryingToGetUnknownKey() |
||
109 | |||
110 | /** |
||
111 | * @test |
||
112 | */ |
||
113 | public function authenticateTokenWillSetUserFetchedFromUserProviderOnToken() |
||
130 | |||
131 | /** |
||
132 | * @test |
||
133 | */ |
||
134 | public function supportsPreAuthToken() |
||
142 | |||
143 | /** |
||
144 | * @test |
||
145 | * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException |
||
146 | */ |
||
147 | public function willFailWhenApiKeyNotFoundInHeader() |
||
153 | |||
154 | /** |
||
155 | * @test |
||
156 | */ |
||
157 | public function canGetAnonTokenWithClaims() |
||
167 | |||
168 | /** |
||
169 | * @param array $claims |
||
170 | * |
||
171 | * @return JwtToken |
||
172 | */ |
||
173 | private function createToken(array $claims) |
||
185 | } |
||
186 |