summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLuis Miguel Cabral <luis.miguel.cabral@pearson.com>2015-04-09 13:02:54 +0200
committerLuis Miguel Cabral <luis.miguel.cabral@pearson.com>2015-04-09 13:02:54 +0200
commit61ff1780af6a0200f18711d897a52eb1aa53729d (patch)
tree8a2bd57de21b357b11f2870714256dc53febf272 /tests
parent0cb1d5a8c4efd6576814247617fc8463042c6fc7 (diff)
downloadphp-jwt-61ff1780af6a0200f18711d897a52eb1aa53729d.zip
php-jwt-61ff1780af6a0200f18711d897a52eb1aa53729d.tar.gz
php-jwt-61ff1780af6a0200f18711d897a52eb1aa53729d.tar.bz2
Provide a leeway time in the verification of timestamps to account for clock skew
Diffstat (limited to 'tests')
-rw-r--r--tests/JWTTest.php12
1 files changed, 9 insertions, 3 deletions
diff --git a/tests/JWTTest.php b/tests/JWTTest.php
index c48427d..b685ce4 100644
--- a/tests/JWTTest.php
+++ b/tests/JWTTest.php
@@ -38,9 +38,11 @@ class JWTTest extends PHPUnit_Framework_TestCase
public function testExpiredToken()
{
$this->setExpectedException('ExpiredException');
+ $timeInPast = time() - JWT::LEEWAYTIME - 20;
$payload = array(
"message" => "abc",
- "exp" => time() - 20); // time in the past
+ "exp" => $timeInPast // time in the past
+ );
$encoded = JWT::encode($payload, 'my_key');
JWT::decode($encoded, 'my_key', array('HS256'));
}
@@ -48,9 +50,11 @@ class JWTTest extends PHPUnit_Framework_TestCase
public function testBeforeValidTokenWithNbf()
{
$this->setExpectedException('BeforeValidException');
+ $timeInFuture = time() + JWT::LEEWAYTIME + 20;
$payload = array(
"message" => "abc",
- "nbf" => time() + 20); // time in the future
+ "nbf" => $timeInFuture // time in the future
+ );
$encoded = JWT::encode($payload, 'my_key');
JWT::decode($encoded, 'my_key', array('HS256'));
}
@@ -58,9 +62,11 @@ class JWTTest extends PHPUnit_Framework_TestCase
public function testBeforeValidTokenWithIat()
{
$this->setExpectedException('BeforeValidException');
+ $timeInFuture = time() + JWT::LEEWAYTIME + 20;
$payload = array(
"message" => "abc",
- "iat" => time() + 20); // time in the future
+ "iat" => $timeInFuture // time in the future
+ );
$encoded = JWT::encode($payload, 'my_key');
JWT::decode($encoded, 'my_key', array('HS256'));
}