File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,14 @@ function sendNotification(endpoint, params) {
148
148
console . warn ( 'You are using the old, deprecated, interface of the `sendNotification` function.' . bold . red ) ;
149
149
}
150
150
151
+ if ( typeof userPublicKey !== 'undefined' && typeof userPublicKey !== 'string' ) {
152
+ throw new Error ( 'userPublicKey should be a base64-encoded string.' ) ;
153
+ }
154
+
155
+ if ( typeof userAuth !== 'undefined' && typeof userAuth !== 'string' ) {
156
+ throw new Error ( 'userAuth should be a base64-encoded string.' ) ;
157
+ }
158
+
151
159
const isGCM = endpoint . indexOf ( 'https://android.googleapis.com/gcm/send' ) === 0 ;
152
160
153
161
var urlParts = url . parse ( endpoint ) ;
Original file line number Diff line number Diff line change @@ -421,6 +421,32 @@ suite('sendNotification', function() {
421
421
} ) ;
422
422
} ) ;
423
423
424
+ test ( 'invalid userPublicKey arguments' , function ( ) {
425
+ return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , {
426
+ userPublicKey : userPublicKey ,
427
+ userAuth : urlBase64 . encode ( userAuth ) ,
428
+ payload : 'hello' ,
429
+ } )
430
+ . then ( function ( body ) {
431
+ assert ( false , 'sendNotification promise resolved' ) ;
432
+ } , function ( ) {
433
+ assert ( true , 'sendNotification promise rejected' ) ;
434
+ } ) ;
435
+ } ) ;
436
+
437
+ test ( 'invalid userAuth arguments' , function ( ) {
438
+ return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , {
439
+ userPublicKey : urlBase64 . encode ( userPublicKey ) ,
440
+ userAuth : userAuth ,
441
+ payload : 'hello' ,
442
+ } )
443
+ . then ( function ( body ) {
444
+ assert ( false , 'sendNotification promise resolved' ) ;
445
+ } , function ( ) {
446
+ assert ( true , 'sendNotification promise rejected' ) ;
447
+ } ) ;
448
+ } ) ;
449
+
424
450
test ( 'TTL with old interface' , function ( ) {
425
451
return startServer ( undefined , 5 )
426
452
. then ( function ( ) {
You can’t perform that action at this time.
0 commit comments