@@ -29,8 +29,6 @@ suite('sendNotification', function() {
29
29
30
30
var userPublicKey = userCurve . generateKeys ( ) ;
31
31
var userPrivateKey = userCurve . getPrivateKey ( ) ;
32
-
33
- var intermediateUserAuth = crypto . randomBytes ( 12 ) ;
34
32
var userAuth = crypto . randomBytes ( 16 ) ;
35
33
36
34
var vapidKeys = webPush . generateVAPIDKeys ( ) ;
@@ -57,8 +55,6 @@ suite('sendNotification', function() {
57
55
assert . equal ( req . headers [ 'ttl' ] , TTL , 'TTL header correct' ) ;
58
56
}
59
57
60
- var cryptoHeader = ! ! req . headers [ 'encryption-key' ] ? 'encryption-key' : 'crypto-key' ;
61
-
62
58
if ( typeof message !== 'undefined' ) {
63
59
assert ( body . length > 0 ) ;
64
60
@@ -68,39 +64,24 @@ suite('sendNotification', function() {
68
64
if ( ! isGCM ) {
69
65
assert . equal ( req . headers [ 'content-type' ] , 'application/octet-stream' , 'Content-Type header correct' ) ;
70
66
71
- var keys = req . headers [ cryptoHeader ] . split ( ',' ) ;
67
+ var keys = req . headers [ 'crypto-key' ] . split ( ',' ) ;
72
68
var appServerPublicKey = keys . find ( function ( key ) {
73
69
return key . indexOf ( 'keyid=p256dh;dh=' ) === 0 ;
74
70
} ) . substring ( 'keyid=p256dh;dh=' . length ) ;
75
71
76
- if ( cryptoHeader === 'encryption-key' ) {
77
- assert . equal ( req . headers [ 'content-encoding' ] , 'aesgcm128' , 'Content-Encoding header correct' ) ;
78
-
79
- var sharedSecret = userCurve . computeSecret ( urlBase64 . decode ( appServerPublicKey ) ) ;
80
- ece . saveKey ( 'webpushKey' , sharedSecret ) ;
81
-
82
- var decrypted = ece . decrypt ( body , {
83
- keyid : 'webpushKey' ,
84
- salt : salt ,
85
- padSize : 1 ,
86
- } ) ;
87
- } else if ( cryptoHeader === 'crypto-key' ) {
88
- assert . equal ( req . headers [ 'content-encoding' ] , 'aesgcm' , 'Content-Encoding header correct' ) ;
89
-
90
- ece . saveKey ( 'webpushKey' , userCurve , 'P-256' ) ;
91
-
92
- var decrypted = ece . decrypt ( body , {
93
- keyid : 'webpushKey' ,
94
- dh : appServerPublicKey ,
95
- salt : salt ,
96
- authSecret : urlBase64 . encode ( userAuth ) ,
97
- padSize : 2 ,
98
- } ) ;
99
- } else {
100
- assert ( false , 'Invalid crypto header value' ) ;
101
- }
72
+ assert . equal ( req . headers [ 'content-encoding' ] , 'aesgcm' , 'Content-Encoding header correct' ) ;
73
+
74
+ ece . saveKey ( 'webpushKey' , userCurve , 'P-256' ) ;
75
+
76
+ var decrypted = ece . decrypt ( body , {
77
+ keyid : 'webpushKey' ,
78
+ dh : appServerPublicKey ,
79
+ salt : salt ,
80
+ authSecret : urlBase64 . encode ( userAuth ) ,
81
+ padSize : 2 ,
82
+ } ) ;
102
83
} else {
103
- assert . equal ( req . headers [ cryptoHeader ] . indexOf ( 'keyid=p256dh;dh=' ) , 0 , 'Encryption -Key header correct' ) ;
84
+ assert . equal ( req . headers [ 'crypto-key' ] . indexOf ( 'keyid=p256dh;dh=' ) , 0 , 'Crypto -Key header correct' ) ;
104
85
assert . equal ( req . headers [ 'content-encoding' ] , 'aesgcm' , 'Content-Encoding header correct' ) ;
105
86
var appServerPublicKey = req . headers [ 'crypto-key' ] . substring ( 'keyid=p256dh;dh=' . length ) ;
106
87
@@ -121,8 +102,7 @@ suite('sendNotification', function() {
121
102
}
122
103
123
104
if ( vapid ) {
124
- assert . equal ( cryptoHeader , 'crypto-key' ) ;
125
- var keys = req . headers [ cryptoHeader ] . split ( ',' ) ;
105
+ var keys = req . headers [ 'crypto-key' ] . split ( ',' ) ;
126
106
var vapidKey = keys . find ( function ( key ) {
127
107
return key . indexOf ( 'p256ecdsa=' ) === 0 ;
128
108
} ) ;
@@ -178,23 +158,7 @@ suite('sendNotification', function() {
178
158
} ) ;
179
159
}
180
160
181
- test ( 'send/receive string (old standard)' , function ( ) {
182
- return startServer ( 'hello' )
183
- . then ( function ( ) {
184
- return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , {
185
- userPublicKey : urlBase64 . encode ( userPublicKey ) ,
186
- payload : 'hello' ,
187
- } ) ;
188
- } )
189
- . then ( function ( body ) {
190
- assert ( true , 'sendNotification promise resolved' ) ;
191
- assert . equal ( body , 'ok' ) ;
192
- } , function ( e ) {
193
- assert ( false , 'sendNotification promise rejected with: ' + e ) ;
194
- } ) ;
195
- } ) ;
196
-
197
- test ( 'send/receive string (new standard)' , function ( ) {
161
+ test ( 'send/receive string' , function ( ) {
198
162
return startServer ( 'hello' )
199
163
. then ( function ( ) {
200
164
return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , {
@@ -233,6 +197,7 @@ suite('sendNotification', function() {
233
197
. then ( function ( ) {
234
198
return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , {
235
199
userPublicKey : urlBase64 . encode ( userPublicKey ) ,
200
+ userAuth : urlBase64 . encode ( userAuth ) ,
236
201
payload : new Buffer ( 'hello' ) ,
237
202
} ) ;
238
203
} )
@@ -248,6 +213,7 @@ suite('sendNotification', function() {
248
213
. then ( function ( ) {
249
214
return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , {
250
215
userPublicKey : urlBase64 . encode ( userPublicKey ) ,
216
+ userAuth : urlBase64 . encode ( userAuth ) ,
251
217
payload : '😁' ,
252
218
} ) ;
253
219
} )
@@ -265,6 +231,7 @@ suite('sendNotification', function() {
265
231
. then ( function ( ) {
266
232
return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , {
267
233
userPublicKey : urlBase64 . encode ( userPublicKey ) ,
234
+ userAuth : urlBase64 . encode ( userAuth ) ,
268
235
payload : '' ,
269
236
} ) ;
270
237
} )
@@ -320,6 +287,7 @@ suite('sendNotification', function() {
320
287
return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , {
321
288
TTL : 5 ,
322
289
userPublicKey : urlBase64 . encode ( userPublicKey ) ,
290
+ userAuth : urlBase64 . encode ( userAuth ) ,
323
291
payload : 'hello' ,
324
292
} ) ;
325
293
} )
@@ -479,53 +447,24 @@ suite('sendNotification', function() {
479
447
} ) ;
480
448
481
449
test ( 'TTL with old interface' , function ( ) {
482
- return startServer ( undefined , 5 )
483
- . then ( function ( ) {
484
- return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , 5 ) ;
485
- } )
450
+ return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , 5 )
486
451
. then ( function ( body ) {
487
- assert ( true , 'sendNotification promise resolved' ) ;
452
+ assert ( false , 'sendNotification promise resolved' ) ;
488
453
} , function ( ) {
489
- assert ( false , 'sendNotification promise rejected' ) ;
454
+ assert ( true , 'sendNotification promise rejected' ) ;
490
455
} ) ;
491
456
} ) ;
492
457
493
458
test ( 'payload with old interface' , function ( ) {
494
- return startServer ( 'hello' , 0 )
495
- . then ( function ( ) {
496
- return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , 0 , urlBase64 . encode ( userPublicKey ) , 'hello' ) ;
497
- } )
459
+ return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , 0 , urlBase64 . encode ( userPublicKey ) , 'hello' )
498
460
. then ( function ( body ) {
499
- assert ( true , 'sendNotification promise resolved' ) ;
500
- assert . equal ( body , 'ok' ) ;
461
+ assert ( false , 'sendNotification promise resolved' ) ;
501
462
} , function ( ) {
502
- assert ( false , 'sendNotification promise rejected' ) ;
503
- } ) ;
504
- } ) ;
505
-
506
- test ( 'send notification with message (old standard) with vapid' , function ( ) {
507
- return startServer ( 'hello' , undefined , undefined , undefined , false )
508
- . then ( function ( ) {
509
- return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , {
510
- userPublicKey : urlBase64 . encode ( userPublicKey ) ,
511
- payload : 'hello' ,
512
- vapid : {
513
- audience : 'https://www.mozilla.org/' ,
514
- subject :
'mailto:[email protected] ' ,
515
- privateKey : vapidKeys . privateKey ,
516
- publicKey : vapidKeys . publicKey ,
517
- } ,
518
- } ) ;
519
- } )
520
- . then ( function ( body ) {
521
- assert ( true , 'sendNotification promise resolved' ) ;
522
- assert . equal ( body , 'ok' ) ;
523
- } , function ( e ) {
524
- assert ( false , 'sendNotification promise rejected with ' + e ) ;
463
+ assert ( true , 'sendNotification promise rejected' ) ;
525
464
} ) ;
526
465
} ) ;
527
466
528
- test ( 'send notification with message (new standard) with vapid' , function ( ) {
467
+ test ( 'send notification with message with vapid' , function ( ) {
529
468
return startServer ( 'hello' , undefined , undefined , undefined , true )
530
469
. then ( function ( ) {
531
470
return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , {
@@ -561,11 +500,13 @@ suite('sendNotification', function() {
561
500
562
501
return startServer ( undefined , undefined , 200 , true )
563
502
. then ( function ( ) {
564
- return webPush . sendNotification ( 'https://android.googleapis.com/gcm/send/someSubscriptionID' , 5 , undefined , undefined , {
503
+ return webPush . sendNotification ( 'https://android.googleapis.com/gcm/send/someSubscriptionID' , {
504
+ vapid : {
565
505
audience : 'https://www.mozilla.org/' ,
566
506
subject :
'mailto:[email protected] ' ,
567
507
privateKey : vapidKeys . privateKey ,
568
508
publicKey : vapidKeys . publicKey ,
509
+ }
569
510
} ) ;
570
511
} )
571
512
. then ( function ( body ) {
0 commit comments