|
1 | 1 | <?php
|
2 |
| -use \Firebase\JWT\JWT; |
| 2 | +namespace Firebase\JWT; |
| 3 | + |
| 4 | +use ArrayObject; |
| 5 | +use PHPUnit_Framework_TestCase; |
3 | 6 |
|
4 | 7 | class JWTTest extends PHPUnit_Framework_TestCase
|
5 | 8 | {
|
| 9 | + public static $opensslVerifyReturnValue; |
| 10 | + |
6 | 11 | public function testEncodeDecode()
|
7 | 12 | {
|
8 | 13 | $msg = JWT::encode('abc', 'my_key');
|
@@ -253,12 +258,32 @@ public function testMissingAlgorithm()
|
253 | 258 | public function testAdditionalHeaders()
|
254 | 259 | {
|
255 | 260 | $msg = JWT::encode('abc', 'my_key', 'HS256', null, array('cty' => 'test-eit;v=1'));
|
256 |
| - $this->assertEquals(JWT::decode($msg, 'my_key', array('HS256')), 'abc'); |
| 261 | + $this->assertEquals(JWT::decode($msg, 'my_key', array('HS256')), 'abc'); |
257 | 262 | }
|
258 | 263 |
|
259 | 264 | public function testInvalidSegmentCount()
|
260 | 265 | {
|
261 | 266 | $this->setExpectedException('UnexpectedValueException');
|
262 | 267 | JWT::decode('brokenheader.brokenbody', 'my_key', array('HS256'));
|
263 | 268 | }
|
| 269 | + |
| 270 | + public function testVerifyError() |
| 271 | + { |
| 272 | + $this->setExpectedException('DomainException'); |
| 273 | + $pkey = openssl_pkey_new(); |
| 274 | + $msg = JWT::encode('abc', $pkey, 'RS256'); |
| 275 | + self::$opensslVerifyReturnValue = -1; |
| 276 | + JWT::decode($msg, $pkey, array('RS256')); |
| 277 | + } |
| 278 | +} |
| 279 | + |
| 280 | +/* |
| 281 | + * Allows the testing of openssl_verify with an error return value |
| 282 | + */ |
| 283 | +function openssl_verify($msg, $signature, $key, $algorithm) |
| 284 | +{ |
| 285 | + if (null !== JWTTest::$opensslVerifyReturnValue) { |
| 286 | + return JWTTest::$opensslVerifyReturnValue; |
| 287 | + } |
| 288 | + return \openssl_verify($msg, $signature, $key, $algorithm); |
264 | 289 | }
|
0 commit comments