summaryrefslogtreecommitdiffstats
path: root/tests/JWTTest.php
diff options
context:
space:
mode:
authorChris Raynor <chris@firebase.com>2014-06-25 14:20:33 -0700
committerChris Raynor <chris@firebase.com>2014-06-25 14:20:33 -0700
commitfa7e362eeeec5ee808124626c3f1a612aadbce52 (patch)
treea1c7d6cf401cd7d9d9e2dcce28a831f51c5223f0 /tests/JWTTest.php
parent47fc8a335817834c6ac5b0030097e81468a4a06c (diff)
parentc5e07e0c0e8f7c2b0f33f23482d6672eb7798ed2 (diff)
downloadphp-jwt-fa7e362eeeec5ee808124626c3f1a612aadbce52.zip
php-jwt-fa7e362eeeec5ee808124626c3f1a612aadbce52.tar.gz
php-jwt-fa7e362eeeec5ee808124626c3f1a612aadbce52.tar.bz2
Merge pull request #11 from firebase/BambooHR-master
Bamboo hr master
Diffstat (limited to 'tests/JWTTest.php')
-rw-r--r--tests/JWTTest.php32
1 files changed, 25 insertions, 7 deletions
diff --git a/tests/JWTTest.php b/tests/JWTTest.php
index ae65f02..ee131d4 100644
--- a/tests/JWTTest.php
+++ b/tests/JWTTest.php
@@ -29,24 +29,42 @@ class JWTTest extends PHPUnit_Framework_TestCase {
JWT::jsonDecode('this is not valid JSON string');
}
- function testExpiredToken(){
+ function testExpiredToken() {
$this->setExpectedException('UnexpectedValueException');
$payload = array(
- "message"=> "abc",
- "exp"=> time()-20); // time in the past
+ "message" => "abc",
+ "exp" => time() - 20); // time in the past
$encoded = JWT::encode($payload, 'my_key');
JWT::decode($encoded);
}
- function testValidToken(){
+ function testValidToken() {
$payload = array(
- "message"=> "abc",
- "exp"=> time()+20); // time in the future
+ "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');
}
-
+
+ function testRSEncodeDecode() {
+ $privKey = openssl_pkey_new(array('digest_alg' => 'sha256',
+ 'private_key_bits' => 1024,
+ 'private_key_type' => OPENSSL_KEYTYPE_RSA));
+ $msg = JWT::encode('abc', $privKey, 'RS256');
+ $pubKey = openssl_pkey_get_details($privKey);
+ $pubKey = $pubKey['key'];
+ $decoded = JWT::decode($msg, $pubKey, true);
+ $this->assertEquals($decoded, 'abc');
+ }
+
+ function testKIDChooser() {
+ $keys = array('1' => 'my_key', '2' => 'my_key2');
+ $msg = JWT::encode('abc', $keys['1'], 'HS256', '1');
+ $decoded = JWT::decode($msg, $keys, true);
+ $this->assertEquals($decoded, 'abc');
+ }
+
}
?>