@@ -19,12 +19,6 @@ public function setExpectedException($exceptionName, $message = '', $code = null
1919 }
2020 }
2121
22- public function testEncodeDecode ()
23- {
24- $ msg = JWT ::encode ('abc ' , 'my_key ' );
25- $ this ->assertEquals (JWT ::decode ($ msg , 'my_key ' , array ('HS256 ' )), 'abc ' );
26- }
27-
2822 public function testDecodeFromPython ()
2923 {
3024 $ msg = 'eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.Iio6aHR0cDovL2FwcGxpY2F0aW9uL2NsaWNreT9ibGFoPTEuMjMmZi5vbz00NTYgQUMwMDAgMTIzIg.E_U8X2YpMT5K1cEiT_3-IvBYfrdIFIeVYeOqre_Z5Cg ' ;
@@ -217,18 +211,6 @@ public function testEmptyKeyFails()
217211 JWT ::decode ($ encoded , '' , array ('HS256 ' ));
218212 }
219213
220- public function testRSEncodeDecode ()
221- {
222- $ privKey = openssl_pkey_new (array ('digest_alg ' => 'sha256 ' ,
223- 'private_key_bits ' => 1024 ,
224- 'private_key_type ' => OPENSSL_KEYTYPE_RSA ));
225- $ msg = JWT ::encode ('abc ' , $ privKey , 'RS256 ' );
226- $ pubKey = openssl_pkey_get_details ($ privKey );
227- $ pubKey = $ pubKey ['key ' ];
228- $ decoded = JWT ::decode ($ msg , $ pubKey , array ('RS256 ' ));
229- $ this ->assertEquals ($ decoded , 'abc ' );
230- }
231-
232214 public function testKIDChooser ()
233215 {
234216 $ keys = array ('1 ' => 'my_key ' , '2 ' => 'my_key2 ' );
@@ -285,35 +267,46 @@ public function testInvalidSignatureEncoding()
285267 JWT ::decode ($ msg , 'secret ' , array ('HS256 ' ));
286268 }
287269
288- /**
289- * @runInSeparateProcess
290- */
291- public function testEncodeAndDecodeEcdsaToken ()
270+ public function testHSEncodeDecode ()
292271 {
293- $ privateKey = file_get_contents (__DIR__ . '/ecdsa-private.pem ' );
294- $ payload = array ('foo ' => 'bar ' );
295- $ encoded = JWT ::encode ($ payload , $ privateKey , 'ES256 ' );
296-
297- // Verify decoding succeeds
298- $ publicKey = file_get_contents (__DIR__ . '/ecdsa-public.pem ' );
299- $ decoded = JWT ::decode ($ encoded , $ publicKey , array ('ES256 ' ));
272+ $ msg = JWT ::encode ('abc ' , 'my_key ' );
273+ $ this ->assertEquals (JWT ::decode ($ msg , 'my_key ' , array ('HS256 ' )), 'abc ' );
274+ }
300275
301- $ this ->assertEquals ('bar ' , $ decoded ->foo );
276+ public function testRSEncodeDecode ()
277+ {
278+ $ privKey = openssl_pkey_new (array ('digest_alg ' => 'sha256 ' ,
279+ 'private_key_bits ' => 1024 ,
280+ 'private_key_type ' => OPENSSL_KEYTYPE_RSA ));
281+ $ msg = JWT ::encode ('abc ' , $ privKey , 'RS256 ' );
282+ $ pubKey = openssl_pkey_get_details ($ privKey );
283+ $ pubKey = $ pubKey ['key ' ];
284+ $ decoded = JWT ::decode ($ msg , $ pubKey , array ('RS256 ' ));
285+ $ this ->assertEquals ($ decoded , 'abc ' );
302286 }
303287
304288 /**
305289 * @runInSeparateProcess
290+ * @dataProvider provideEncodeDecode
306291 */
307- public function testEncodeAndDecodeEcdsa384Token ( )
292+ public function testEncodeDecode ( $ privateKeyFile , $ publicKeyFile , $ alg )
308293 {
309- $ privateKey = file_get_contents (__DIR__ . ' /ecdsa384-private.pem ' );
294+ $ privateKey = file_get_contents ($ privateKeyFile );
310295 $ payload = array ('foo ' => 'bar ' );
311- $ encoded = JWT ::encode ($ payload , $ privateKey , ' ES384 ' );
296+ $ encoded = JWT ::encode ($ payload , $ privateKey , $ alg );
312297
313298 // Verify decoding succeeds
314- $ publicKey = file_get_contents (__DIR__ . ' /ecdsa384-public.pem ' );
315- $ decoded = JWT ::decode ($ encoded , $ publicKey , array (' ES384 ' ));
299+ $ publicKey = file_get_contents ($ publicKeyFile );
300+ $ decoded = JWT ::decode ($ encoded , $ publicKey , array ($ alg ));
316301
317302 $ this ->assertEquals ('bar ' , $ decoded ->foo );
318303 }
304+
305+ public function provideEncodeDecode ()
306+ {
307+ return array (
308+ array (__DIR__ . '/ecdsa-private.pem ' , __DIR__ . '/ecdsa-public.pem ' , 'ES256 ' ),
309+ array (__DIR__ . '/ecdsa384-private.pem ' , __DIR__ . '/ecdsa384-public.pem ' , 'ES384 ' ),
310+ );
311+ }
319312}
0 commit comments