@@ -16,14 +16,14 @@ describe('JWT helpers', () => {
1616
1717 it ( 'round-trips through verifyJwt' , async ( ) => {
1818 const now = Math . floor ( Date . now ( ) / 1000 ) ;
19- const token = signJwt ( { sub : 'GTESTPUBLICKEY123' , iat : now , exp : now + 3600 } ) ;
19+ const token = signJwt ( { sub : 'GTESTPUBLICKEY123' , iat : now , exp : now + 3600 , iss : 'flowfi-api' , aud : 'flowfi-api' } ) ;
2020
2121 expect ( verifyJwt ( token ) ) . toEqual ( { publicKey : 'GTESTPUBLICKEY123' } ) ;
2222 } ) ;
2323
2424 it ( 'returns null for a tampered header' , async ( ) => {
2525 const now = Math . floor ( Date . now ( ) / 1000 ) ;
26- const token = signJwt ( { sub : 'GTESTPUBLICKEY123' , iat : now , exp : now + 3600 } ) ;
26+ const token = signJwt ( { sub : 'GTESTPUBLICKEY123' , iat : now , exp : now + 3600 , iss : 'flowfi-api' , aud : 'flowfi-api' } ) ;
2727 const parts = token . split ( '.' ) as [ string , string , string ] ;
2828 parts [ 0 ] = parts [ 0 ] . slice ( 0 , - 1 ) + ( parts [ 0 ] . slice ( - 1 ) === 'A' ? 'B' : 'A' ) ;
2929
@@ -32,7 +32,7 @@ describe('JWT helpers', () => {
3232
3333 it ( 'returns null for a tampered body' , async ( ) => {
3434 const now = Math . floor ( Date . now ( ) / 1000 ) ;
35- const token = signJwt ( { sub : 'GTESTPUBLICKEY123' , iat : now , exp : now + 3600 } ) ;
35+ const token = signJwt ( { sub : 'GTESTPUBLICKEY123' , iat : now , exp : now + 3600 , iss : 'flowfi-api' , aud : 'flowfi-api' } ) ;
3636 const parts = token . split ( '.' ) as [ string , string , string ] ;
3737 parts [ 1 ] = parts [ 1 ] . slice ( 0 , - 1 ) + ( parts [ 1 ] . slice ( - 1 ) === 'A' ? 'B' : 'A' ) ;
3838
@@ -41,7 +41,7 @@ describe('JWT helpers', () => {
4141
4242 it ( 'returns null for a tampered signature' , async ( ) => {
4343 const now = Math . floor ( Date . now ( ) / 1000 ) ;
44- const token = signJwt ( { sub : 'GTESTPUBLICKEY123' , iat : now , exp : now + 3600 } ) ;
44+ const token = signJwt ( { sub : 'GTESTPUBLICKEY123' , iat : now , exp : now + 3600 , iss : 'flowfi-api' , aud : 'flowfi-api' } ) ;
4545 const parts = token . split ( '.' ) as [ string , string , string ] ;
4646 // Replace the signature with invalid data to ensure verification fails
4747 parts [ 2 ] = 'invalid-signature-data-1234567890abcdef' ;
@@ -51,7 +51,21 @@ describe('JWT helpers', () => {
5151
5252 it ( 'returns null for an expired token' , async ( ) => {
5353 const now = Math . floor ( Date . now ( ) / 1000 ) ;
54- const token = signJwt ( { sub : 'GTESTPUBLICKEY123' , iat : now - 3600 , exp : now - 1 } ) ;
54+ const token = signJwt ( { sub : 'GTESTPUBLICKEY123' , iat : now - 3600 , exp : now - 1 , iss : 'flowfi-api' , aud : 'flowfi-api' } ) ;
55+
56+ expect ( verifyJwt ( token ) ) . toBeNull ( ) ;
57+ } ) ;
58+
59+ it ( 'returns null for a token with wrong audience' , async ( ) => {
60+ const now = Math . floor ( Date . now ( ) / 1000 ) ;
61+ const token = signJwt ( { sub : 'GTESTPUBLICKEY123' , iat : now , exp : now + 3600 , iss : 'flowfi-api' , aud : 'wrong-audience' } ) ;
62+
63+ expect ( verifyJwt ( token ) ) . toBeNull ( ) ;
64+ } ) ;
65+
66+ it ( 'returns null for a token with wrong issuer' , async ( ) => {
67+ const now = Math . floor ( Date . now ( ) / 1000 ) ;
68+ const token = signJwt ( { sub : 'GTESTPUBLICKEY123' , iat : now , exp : now + 3600 , iss : 'wrong-issuer' , aud : 'flowfi-api' } ) ;
5569
5670 expect ( verifyJwt ( token ) ) . toBeNull ( ) ;
5771 } ) ;
0 commit comments