@@ -438,6 +438,71 @@ suite('sendNotification', function() {
438
438
} ) ;
439
439
} ) ;
440
440
441
+ test ( 'userPublicKey argument isn\'t a string' , function ( ) {
442
+ return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , {
443
+ userPublicKey : userPublicKey ,
444
+ userAuth : urlBase64 . encode ( userAuth ) ,
445
+ payload : 'hello' ,
446
+ } )
447
+ . then ( function ( body ) {
448
+ assert ( false , 'sendNotification promise resolved' ) ;
449
+ } , function ( ) {
450
+ assert ( true , 'sendNotification promise rejected' ) ;
451
+ } ) ;
452
+ } ) ;
453
+
454
+ test ( 'userAuth argument isn\'t a string' , function ( ) {
455
+ return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , {
456
+ userPublicKey : urlBase64 . encode ( userPublicKey ) ,
457
+ userAuth : userAuth ,
458
+ payload : 'hello' ,
459
+ } )
460
+ . then ( function ( body ) {
461
+ assert ( false , 'sendNotification promise resolved' ) ;
462
+ } , function ( ) {
463
+ assert ( true , 'sendNotification promise rejected' ) ;
464
+ } ) ;
465
+ } ) ;
466
+
467
+ test ( 'userPublicKey argument is too long' , function ( ) {
468
+ return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , {
469
+ userPublicKey : urlBase64 . encode ( Buffer . concat ( [ userPublicKey , new Buffer ( 1 ) ] ) ) ,
470
+ userAuth : urlBase64 . encode ( userAuth ) ,
471
+ payload : 'hello' ,
472
+ } )
473
+ . then ( function ( body ) {
474
+ assert ( false , 'sendNotification promise resolved' ) ;
475
+ } , function ( ) {
476
+ assert ( true , 'sendNotification promise rejected' ) ;
477
+ } ) ;
478
+ } ) ;
479
+
480
+ test ( 'userPublicKey argument is too short' , function ( ) {
481
+ return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , {
482
+ userPublicKey : urlBase64 . encode ( userPublicKey . slice ( 1 ) ) ,
483
+ userAuth : urlBase64 . encode ( userAuth ) ,
484
+ payload : 'hello' ,
485
+ } )
486
+ . then ( function ( body ) {
487
+ assert ( false , 'sendNotification promise resolved' ) ;
488
+ } , function ( ) {
489
+ assert ( true , 'sendNotification promise rejected' ) ;
490
+ } ) ;
491
+ } ) ;
492
+
493
+ test ( 'userAuth argument is too short' , function ( ) {
494
+ return webPush . sendNotification ( 'https://127.0.0.1:' + serverPort , {
495
+ userPublicKey : urlBase64 . encode ( userPublicKey ) ,
496
+ userAuth : urlBase64 . encode ( userAuth . slice ( 1 ) ) ,
497
+ payload : 'hello' ,
498
+ } )
499
+ . then ( function ( body ) {
500
+ assert ( false , 'sendNotification promise resolved' ) ;
501
+ } , function ( ) {
502
+ assert ( true , 'sendNotification promise rejected' ) ;
503
+ } ) ;
504
+ } ) ;
505
+
441
506
test ( 'TTL with old interface' , function ( ) {
442
507
return startServer ( undefined , 5 )
443
508
. then ( function ( ) {
0 commit comments