@@ -11,10 +11,32 @@ var pub = fs.readFileSync(path.join(__dirname, 'pub.pem'), 'utf8');
11
11
12
12
var TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIiLCJpYXQiOjE0MjY1NDY5MTl9.ETgkTn8BaxIX4YqvUWVFPmum3moNZ7oARZtSBXb_vP4' ;
13
13
14
- describe ( 'signing with pub key as symmetric' , function ( ) {
15
- it ( 'should not verify' , function ( ) {
16
- expect ( function ( ) {
17
- jwt . verify ( TOKEN , pub ) ;
18
- } ) . to . throw ( JsonWebTokenError , / i n v a l i d s i g n a t u r e / ) ;
14
+ describe ( 'when setting a wrong `header.alg`' , function ( ) {
15
+
16
+ describe ( 'signing with pub key as symmetric' , function ( ) {
17
+ it ( 'should not verify' , function ( ) {
18
+ expect ( function ( ) {
19
+ jwt . verify ( TOKEN , pub ) ;
20
+ } ) . to . throw ( JsonWebTokenError , / i n v a l i d a l g o r i t h m / ) ;
21
+ } ) ;
22
+ } ) ;
23
+
24
+ describe ( 'signing with pub key as HS256 and whitelisting only RS256' , function ( ) {
25
+ it ( 'should not verify' , function ( ) {
26
+ expect ( function ( ) {
27
+ jwt . verify ( TOKEN , pub , { algorithms : [ 'RS256' ] } ) ;
28
+ } ) . to . throw ( JsonWebTokenError , / i n v a l i d a l g o r i t h m / ) ;
29
+ } ) ;
19
30
} ) ;
20
- } ) ;
31
+
32
+ describe ( 'signing with HS256 and checking with HS384' , function ( ) {
33
+ it ( 'should not verify' , function ( ) {
34
+ expect ( function ( ) {
35
+ var token = jwt . sign ( { foo : 'bar' } , 'secret' , { algorithm : 'HS256' } ) ;
36
+ jwt . verify ( token , 'some secret' , { algorithms : [ 'HS384' ] } ) ;
37
+ } ) . to . throw ( JsonWebTokenError , / i n v a l i d a l g o r i t h m / ) ;
38
+ } ) ;
39
+ } ) ;
40
+
41
+
42
+ } ) ;
0 commit comments