Skip to content

Commit c6583dc

Browse files
committed
Merge pull request firebase#36 from firebase/cr-additional-tests
Add a few add'l tests - more forthcoming
2 parents d137805 + 4e15ea5 commit c6583dc

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/JWTTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ public function testValidToken()
7575
$this->assertEquals($decoded->message, 'abc');
7676
}
7777

78+
public function testValidTokenWithList()
79+
{
80+
$payload = array(
81+
"message" => "abc",
82+
"exp" => time() + 20); // time in the future
83+
$encoded = JWT::encode($payload, 'my_key');
84+
$decoded = JWT::decode($encoded, 'my_key', array('HS256', 'HS512'));
85+
$this->assertEquals($decoded->message, 'abc');
86+
}
87+
7888
public function testValidTokenWithNbf()
7989
{
8090
$payload = array(
@@ -116,4 +126,25 @@ public function testKIDChooser()
116126
$decoded = JWT::decode($msg, $keys, array('HS256'));
117127
$this->assertEquals($decoded, 'abc');
118128
}
129+
130+
public function testNoneAlgorithm()
131+
{
132+
$msg = JWT::encode('abc', 'my_key');
133+
$this->setExpectedException('DomainException');
134+
JWT::decode($msg, 'my_key', array('none'));
135+
}
136+
137+
public function testIncorrectAlgorithm()
138+
{
139+
$msg = JWT::encode('abc', 'my_key');
140+
$this->setExpectedException('DomainException');
141+
JWT::decode($msg, 'my_key', array('RS256'));
142+
}
143+
144+
public function testMissingAlgorithm()
145+
{
146+
$msg = JWT::encode('abc', 'my_key');
147+
$this->setExpectedException('DomainException');
148+
JWT::decode($msg, 'my_key');
149+
}
119150
}

0 commit comments

Comments
 (0)