summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRedian Ibra <redian@dred.com>2014-04-11 15:14:48 +0100
committerRedian Ibra <redian@dred.com>2014-04-11 15:14:48 +0100
commit2490881237021b9b0e6abbb4c6221ed461e227ff (patch)
treefb24fd3f0f49e1dfbea3cb1d23563d553fbb70df
parent280bf6b9cded67f0edc1ed724fef6c18cbb6edf4 (diff)
downloadphp-jwt-2490881237021b9b0e6abbb4c6221ed461e227ff.zip
php-jwt-2490881237021b9b0e6abbb4c6221ed461e227ff.tar.gz
php-jwt-2490881237021b9b0e6abbb4c6221ed461e227ff.tar.bz2
Writing some unittests to make sure the token expiry logic works as it should.
-rw-r--r--tests/JWTTest.php19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/JWTTest.php b/tests/JWTTest.php
index a649051..ae65f02 100644
--- a/tests/JWTTest.php
+++ b/tests/JWTTest.php
@@ -28,6 +28,25 @@ class JWTTest extends PHPUnit_Framework_TestCase {
$this->setExpectedException('DomainException');
JWT::jsonDecode('this is not valid JSON string');
}
+
+ function testExpiredToken(){
+ $this->setExpectedException('UnexpectedValueException');
+ $payload = array(
+ "message"=> "abc",
+ "exp"=> time()-20); // time in the past
+ $encoded = JWT::encode($payload, 'my_key');
+ JWT::decode($encoded);
+ }
+
+ function testValidToken(){
+ $payload = array(
+ "message"=> "abc",
+ "exp"=> time()+20); // time in the future
+ $encoded = JWT::encode($payload, 'my_key');
+ $decoded = JWT::decode($encoded, 'my_key');
+ $this->assertEquals($decoded->message, 'abc');
+ }
+
}
?>