diff options
author | Luis Miguel Cabral <luis.miguel.cabral@pearson.com> | 2015-05-11 12:20:39 +0200 |
---|---|---|
committer | Luis Miguel Cabral <luis.miguel.cabral@pearson.com> | 2015-05-11 12:20:39 +0200 |
commit | 95fa9ae8ff71e3fc697befda39d9530cc15e5e8e (patch) | |
tree | 0731bdbf757345a466484ffa50639440e44b04c3 /tests | |
parent | 61ff1780af6a0200f18711d897a52eb1aa53729d (diff) | |
download | php-jwt-95fa9ae8ff71e3fc697befda39d9530cc15e5e8e.zip php-jwt-95fa9ae8ff71e3fc697befda39d9530cc15e5e8e.tar.gz php-jwt-95fa9ae8ff71e3fc697befda39d9530cc15e5e8e.tar.bz2 |
Changed the leeway to be a static variable
Diffstat (limited to 'tests')
-rw-r--r-- | tests/JWTTest.php | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/tests/JWTTest.php b/tests/JWTTest.php index b685ce4..ae59455 100644 --- a/tests/JWTTest.php +++ b/tests/JWTTest.php @@ -38,7 +38,7 @@ class JWTTest extends PHPUnit_Framework_TestCase public function testExpiredToken() { $this->setExpectedException('ExpiredException'); - $timeInPast = time() - JWT::LEEWAYTIME - 20; + $timeInPast = time() - 20; $payload = array( "message" => "abc", "exp" => $timeInPast // time in the past @@ -50,7 +50,7 @@ class JWTTest extends PHPUnit_Framework_TestCase public function testBeforeValidTokenWithNbf() { $this->setExpectedException('BeforeValidException'); - $timeInFuture = time() + JWT::LEEWAYTIME + 20; + $timeInFuture = time() + 20; $payload = array( "message" => "abc", "nbf" => $timeInFuture // time in the future @@ -62,7 +62,7 @@ class JWTTest extends PHPUnit_Framework_TestCase public function testBeforeValidTokenWithIat() { $this->setExpectedException('BeforeValidException'); - $timeInFuture = time() + JWT::LEEWAYTIME + 20; + $timeInFuture = time() + 20; $payload = array( "message" => "abc", "iat" => $timeInFuture // time in the future @@ -75,7 +75,30 @@ class JWTTest extends PHPUnit_Framework_TestCase { $payload = array( "message" => "abc", - "exp" => time() + 20); // time in the future + "exp" => time() + JWT::$leeway + 20); // time in the future + $encoded = JWT::encode($payload, 'my_key'); + $decoded = JWT::decode($encoded, 'my_key', array('HS256')); + $this->assertEquals($decoded->message, 'abc'); + } + + public function testValidTokenWithLeeway() + { + JWT::$leeway = 60; + $payload = array( + "message" => "abc", + "exp" => time() - 20); // time in the past + $encoded = JWT::encode($payload, 'my_key'); + $decoded = JWT::decode($encoded, 'my_key', array('HS256')); + $this->assertEquals($decoded->message, 'abc'); + } + + public function testExpiredTokenWithLeeway() + { + JWT::$leeway = 60; + $payload = array( + "message" => "abc", + "exp" => time() - 70); // time far in the past + $this->setExpectedException('ExpiredException'); $encoded = JWT::encode($payload, 'my_key'); $decoded = JWT::decode($encoded, 'my_key', array('HS256')); $this->assertEquals($decoded->message, 'abc'); |