@@ -245,7 +245,7 @@ suite('Test Generate Request Details', function() {
245
245
assert . equal ( details . headers . Urgency , extraOptions . headers . Urgency ) ;
246
246
} ) ;
247
247
248
- test ( 'Audience contains port' , function ( ) {
248
+ test ( 'Audience contains port with aes128gcm ' , function ( ) {
249
249
const subscription = {
250
250
endpoint : 'http://example.com:4242/life-universe-and-everything'
251
251
} ;
@@ -261,6 +261,34 @@ suite('Test Generate Request Details', function() {
261
261
const requestDetails = webPush . generateRequestDetails ( subscription , null , extraOptions ) ;
262
262
const authHeader = requestDetails . headers . Authorization ;
263
263
264
+ // Get the Encoded JWT Token from the Authorization Header
265
+ // and decoded it using `jws.decode`
266
+ // to get the value of audience in jwt payload
267
+ const jwtContents = authHeader . match ( / v a p i d \s t = ( [ ^ , ] * ) / ) [ 1 ] ;
268
+ const decodedContents = jws . decode ( jwtContents ) ;
269
+ const audience = decodedContents . payload . aud ;
270
+
271
+ assert . ok ( audience , 'Audience exists' ) ;
272
+ assert . equal ( audience , 'http://example.com:4242' , 'Audience contains expected value with port' ) ;
273
+ } ) ;
274
+
275
+ test ( 'Audience contains port with aesgcm' , function ( ) {
276
+ const subscription = {
277
+ endpoint : 'http://example.com:4242/life-universe-and-everything'
278
+ } ;
279
+
280
+ const extraOptions = {
281
+ vapidDetails : {
282
+ subject :
'mailto:[email protected] ' ,
283
+ publicKey : vapidKeys . publicKey ,
284
+ privateKey : vapidKeys . privateKey
285
+ } ,
286
+ contentEncoding : 'aesgcm'
287
+ } ;
288
+
289
+ const requestDetails = webPush . generateRequestDetails ( subscription , null , extraOptions ) ;
290
+ const authHeader = requestDetails . headers . Authorization ;
291
+
264
292
// Get the Encoded JWT Token from the Authorization Header
265
293
// and decoded it using `jws.decode`
266
294
// to get the value of audience in jwt payload
0 commit comments