@@ -5,22 +5,22 @@ class JWTTest extends PHPUnit_Framework_TestCase
5
5
public function testEncodeDecode ()
6
6
{
7
7
$ msg = JWT ::encode ('abc ' , 'my_key ' );
8
- $ this ->assertEquals (JWT ::decode ($ msg , 'my_key ' ), 'abc ' );
8
+ $ this ->assertEquals (JWT ::decode ($ msg , 'my_key ' , array ( ' HS256 ' ) ), 'abc ' );
9
9
}
10
10
11
11
public function testDecodeFromPython ()
12
12
{
13
13
$ msg = 'eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.Iio6aHR0cDovL2FwcGxpY2F0aW9uL2NsaWNreT9ibGFoPTEuMjMmZi5vbz00NTYgQUMwMDAgMTIzIg.E_U8X2YpMT5K1cEiT_3-IvBYfrdIFIeVYeOqre_Z5Cg ' ;
14
14
$ this ->assertEquals (
15
- JWT ::decode ($ msg , 'my_key ' ),
15
+ JWT ::decode ($ msg , 'my_key ' , array ( ' HS256 ' ) ),
16
16
'*:http://application/clicky?blah=1.23&f.oo=456 AC000 123 '
17
17
);
18
18
}
19
19
20
20
public function testUrlSafeCharacters ()
21
21
{
22
22
$ encoded = JWT ::encode ('f? ' , 'a ' );
23
- $ this ->assertEquals ('f? ' , JWT ::decode ($ encoded , 'a ' ));
23
+ $ this ->assertEquals ('f? ' , JWT ::decode ($ encoded , 'a ' , array ( ' HS256 ' ) ));
24
24
}
25
25
26
26
public function testMalformedUtf8StringsFail ()
@@ -42,7 +42,7 @@ public function testExpiredToken()
42
42
"message " => "abc " ,
43
43
"exp " => time () - 20 ); // time in the past
44
44
$ encoded = JWT ::encode ($ payload , 'my_key ' );
45
- JWT ::decode ($ encoded , 'my_key ' );
45
+ JWT ::decode ($ encoded , 'my_key ' , array ( ' HS256 ' ) );
46
46
}
47
47
48
48
public function testBeforeValidTokenWithNbf ()
@@ -52,7 +52,7 @@ public function testBeforeValidTokenWithNbf()
52
52
"message " => "abc " ,
53
53
"nbf " => time () + 20 ); // time in the future
54
54
$ encoded = JWT ::encode ($ payload , 'my_key ' );
55
- JWT ::decode ($ encoded , 'my_key ' );
55
+ JWT ::decode ($ encoded , 'my_key ' , array ( ' HS256 ' ) );
56
56
}
57
57
58
58
public function testBeforeValidTokenWithIat ()
@@ -62,7 +62,7 @@ public function testBeforeValidTokenWithIat()
62
62
"message " => "abc " ,
63
63
"iat " => time () + 20 ); // time in the future
64
64
$ encoded = JWT ::encode ($ payload , 'my_key ' );
65
- JWT ::decode ($ encoded , 'my_key ' );
65
+ JWT ::decode ($ encoded , 'my_key ' , array ( ' HS256 ' ) );
66
66
}
67
67
68
68
public function testValidToken ()
@@ -71,7 +71,7 @@ public function testValidToken()
71
71
"message " => "abc " ,
72
72
"exp " => time () + 20 ); // time in the future
73
73
$ encoded = JWT ::encode ($ payload , 'my_key ' );
74
- $ decoded = JWT ::decode ($ encoded , 'my_key ' );
74
+ $ decoded = JWT ::decode ($ encoded , 'my_key ' , array ( ' HS256 ' ) );
75
75
$ this ->assertEquals ($ decoded ->message , 'abc ' );
76
76
}
77
77
@@ -83,7 +83,7 @@ public function testValidTokenWithNbf()
83
83
"exp " => time () + 20 , // time in the future
84
84
"nbf " => time () - 20 );
85
85
$ encoded = JWT ::encode ($ payload , 'my_key ' );
86
- $ decoded = JWT ::decode ($ encoded , 'my_key ' );
86
+ $ decoded = JWT ::decode ($ encoded , 'my_key ' , array ( ' HS256 ' ) );
87
87
$ this ->assertEquals ($ decoded ->message , 'abc ' );
88
88
}
89
89
@@ -94,28 +94,26 @@ public function testInvalidToken()
94
94
"exp " => time () + 20 ); // time in the future
95
95
$ encoded = JWT ::encode ($ payload , 'my_key ' );
96
96
$ this ->setExpectedException ('SignatureInvalidException ' );
97
- $ decoded = JWT ::decode ($ encoded , 'my_key2 ' );
97
+ $ decoded = JWT ::decode ($ encoded , 'my_key2 ' , array ( ' HS256 ' ) );
98
98
}
99
99
100
100
public function testRSEncodeDecode ()
101
101
{
102
102
$ privKey = openssl_pkey_new (array ('digest_alg ' => 'sha256 ' ,
103
103
'private_key_bits ' => 1024 ,
104
104
'private_key_type ' => OPENSSL_KEYTYPE_RSA ));
105
- //JWT::setOnlyAllowedMethod('RS256');
106
105
$ msg = JWT ::encode ('abc ' , $ privKey , 'RS256 ' );
107
106
$ pubKey = openssl_pkey_get_details ($ privKey );
108
107
$ pubKey = $ pubKey ['key ' ];
109
- $ decoded = JWT ::decode ($ msg , $ pubKey , true );
108
+ $ decoded = JWT ::decode ($ msg , $ pubKey , array ( ' RS256 ' ) );
110
109
$ this ->assertEquals ($ decoded , 'abc ' );
111
110
}
112
111
113
112
public function testKIDChooser ()
114
113
{
115
114
$ keys = array ('1 ' => 'my_key ' , '2 ' => 'my_key2 ' );
116
- //JWT::setOnlyAllowedMethod('HS256');
117
115
$ msg = JWT ::encode ('abc ' , $ keys ['1 ' ], 'HS256 ' , '1 ' );
118
- $ decoded = JWT ::decode ($ msg , $ keys , true );
116
+ $ decoded = JWT ::decode ($ msg , $ keys , array ( ' HS256 ' ) );
119
117
$ this ->assertEquals ($ decoded , 'abc ' );
120
118
}
121
119
}
0 commit comments