@@ -19,12 +19,6 @@ public function setExpectedException($exceptionName, $message = '', $code = null
19
19
}
20
20
}
21
21
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
-
28
22
public function testDecodeFromPython ()
29
23
{
30
24
$ msg = 'eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.Iio6aHR0cDovL2FwcGxpY2F0aW9uL2NsaWNreT9ibGFoPTEuMjMmZi5vbz00NTYgQUMwMDAgMTIzIg.E_U8X2YpMT5K1cEiT_3-IvBYfrdIFIeVYeOqre_Z5Cg ' ;
@@ -217,18 +211,6 @@ public function testEmptyKeyFails()
217
211
JWT ::decode ($ encoded , '' , array ('HS256 ' ));
218
212
}
219
213
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
-
232
214
public function testKIDChooser ()
233
215
{
234
216
$ keys = array ('1 ' => 'my_key ' , '2 ' => 'my_key2 ' );
@@ -285,35 +267,46 @@ public function testInvalidSignatureEncoding()
285
267
JWT ::decode ($ msg , 'secret ' , array ('HS256 ' ));
286
268
}
287
269
288
- /**
289
- * @runInSeparateProcess
290
- */
291
- public function testEncodeAndDecodeEcdsaToken ()
270
+ public function testHSEncodeDecode ()
292
271
{
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
+ }
300
275
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 ' );
302
286
}
303
287
304
288
/**
305
289
* @runInSeparateProcess
290
+ * @dataProvider provideEncodeDecode
306
291
*/
307
- public function testEncodeAndDecodeEcdsa384Token ( )
292
+ public function testEncodeDecode ( $ privateKeyFile , $ publicKeyFile , $ alg )
308
293
{
309
- $ privateKey = file_get_contents (__DIR__ . ' /ecdsa384-private.pem ' );
294
+ $ privateKey = file_get_contents ($ privateKeyFile );
310
295
$ payload = array ('foo ' => 'bar ' );
311
- $ encoded = JWT ::encode ($ payload , $ privateKey , ' ES384 ' );
296
+ $ encoded = JWT ::encode ($ payload , $ privateKey , $ alg );
312
297
313
298
// 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 ));
316
301
317
302
$ this ->assertEquals ('bar ' , $ decoded ->foo );
318
303
}
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
+ }
319
312
}
0 commit comments