diff options
author | Luis Miguel Cabral <luis.miguel.cabral@pearson.com> | 2015-05-15 09:14:45 +0200 |
---|---|---|
committer | Luis Miguel Cabral <luis.miguel.cabral@pearson.com> | 2015-05-15 09:14:45 +0200 |
commit | 452f7c92cd6beaa272eb822e87a73b4b51d7a29e (patch) | |
tree | 989c9101b65ba09e13988a80a307704e5b8aac06 | |
parent | 3d9bd0ab1f738e354bd9c420c9564f5d4500c93c (diff) | |
download | php-jwt-452f7c92cd6beaa272eb822e87a73b4b51d7a29e.zip php-jwt-452f7c92cd6beaa272eb822e87a73b4b51d7a29e.tar.gz php-jwt-452f7c92cd6beaa272eb822e87a73b4b51d7a29e.tar.bz2 |
Added tests with leeway value in nbf and iat
-rw-r--r-- | tests/JWTTest.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/JWTTest.php b/tests/JWTTest.php index 42fb5f9..da9975c 100644 --- a/tests/JWTTest.php +++ b/tests/JWTTest.php @@ -120,6 +120,50 @@ class JWTTest extends PHPUnit_Framework_TestCase $this->assertEquals($decoded->message, 'abc'); } + public function testValidTokenWithNbfLeeway() + { + JWT::$leeway = 60; + $payload = array( + "message" => "abc", + "nbf" => time() + 20); // not before in near (leeway) future + $encoded = JWT::encode($payload, 'my_key'); + $decoded = JWT::decode($encoded, 'my_key', array('HS256')); + $this->assertEquals($decoded->message, 'abc'); + } + + public function testInvalidTokenWithNbfLeeway() + { + JWT::$leeway = 60; + $payload = array( + "message" => "abc", + "nbf" => time() + 65); // not before too far in future + $encoded = JWT::encode($payload, 'my_key'); + $this->setExpectedException('BeforeValidException'); + $decoded = JWT::decode($encoded, 'my_key', array('HS256')); + } + + public function testValidTokenWithIatLeeway() + { + JWT::$leeway = 60; + $payload = array( + "message" => "abc", + "iat" => time() + 20); // issued in near (leeway) future + $encoded = JWT::encode($payload, 'my_key'); + $decoded = JWT::decode($encoded, 'my_key', array('HS256')); + $this->assertEquals($decoded->message, 'abc'); + } + + public function testInvalidTokenWithIatLeeway() + { + JWT::$leeway = 60; + $payload = array( + "message" => "abc", + "iat" => time() + 65); // issued too far in future + $encoded = JWT::encode($payload, 'my_key'); + $this->setExpectedException('BeforeValidException'); + $decoded = JWT::decode($encoded, 'my_key', array('HS256')); + } + public function testInvalidToken() { $payload = array( |