@@ -9,8 +9,12 @@ const webPush = require('../src/index');
99const vapidHelper = require ( '../src/vapid-helper' ) ;
1010
1111const VALID_AUDIENCE = 'https://example.com' ;
12- const VALID_SUBJECT_MAILTO = 'mailto: [email protected] ' ; 13- const VALID_SUBJECT_URL = 'https://exampe.com/contact' ;
12+ const VALID_SUBJECT_MAILTO = 'mailto:[email protected] ' ; 13+ const VALID_SUBJECT_LOCALHOST_MAILTO = 'mailto:user@localhost' ;
14+ const VALID_SUBJECT_URL = 'https://example.com/contact' ;
15+ const WARN_SUBJECT_LOCALHOST_URL = 'https://localhost' ;
16+ const INVALID_SUBJECT_URL_1 = 'http://example.gov' ;
17+ const INVALID_SUBJECT_URL_2 = 'ftp://example.net' ;
1418const VALID_PUBLIC_KEY = urlBase64 . encode ( Buffer . alloc ( 65 ) ) ;
1519const VALID_UNSAFE_BASE64_PUBLIC_KEY = Buffer . alloc ( 65 ) . toString ( 'base64' ) ;
1620const VALID_PRIVATE_KEY = urlBase64 . encode ( Buffer . alloc ( 32 ) ) ;
@@ -101,6 +105,14 @@ suite('Test Vapid Helpers', function() {
101105 function ( ) {
102106 vapidHelper . getVapidHeaders ( 'Not a URL' , VALID_SUBJECT_MAILTO , VALID_PUBLIC_KEY , VALID_PRIVATE_KEY ) ;
103107 } ,
108+ function ( ) {
109+ // http URL protocol
110+ vapidHelper . getVapidHeaders ( VALID_AUDIENCE , INVALID_SUBJECT_URL_1 , VALID_PUBLIC_KEY , VALID_PRIVATE_KEY ) ;
111+ } ,
112+ function ( ) {
113+ // ftp URL protocol
114+ vapidHelper . getVapidHeaders ( VALID_AUDIENCE , INVALID_SUBJECT_URL_2 , VALID_PUBLIC_KEY , VALID_PRIVATE_KEY ) ;
115+ } ,
104116 function ( ) {
105117 vapidHelper . getVapidHeaders ( VALID_AUDIENCE , 'Some Random String' , VALID_PUBLIC_KEY , VALID_PRIVATE_KEY ) ;
106118 } ,
@@ -168,9 +180,17 @@ suite('Test Vapid Helpers', function() {
168180 function ( contentEncoding ) {
169181 return vapidHelper . getVapidHeaders ( VALID_AUDIENCE , VALID_SUBJECT_URL , VALID_PUBLIC_KEY , VALID_PRIVATE_KEY , contentEncoding ) ;
170182 } ,
183+ function ( contentEncoding ) {
184+ // localhost https: subject; should pass, since we don't throw an error for this, just warn to console
185+ return vapidHelper . getVapidHeaders ( VALID_AUDIENCE , WARN_SUBJECT_LOCALHOST_URL , VALID_PUBLIC_KEY , VALID_PRIVATE_KEY , contentEncoding ) ;
186+ } ,
171187 function ( contentEncoding ) {
172188 return vapidHelper . getVapidHeaders ( VALID_AUDIENCE , VALID_SUBJECT_MAILTO , VALID_PUBLIC_KEY , VALID_PRIVATE_KEY , contentEncoding ) ;
173189 } ,
190+ function ( contentEncoding ) {
191+ // localhost mailto: subject
192+ return vapidHelper . getVapidHeaders ( VALID_AUDIENCE , VALID_SUBJECT_LOCALHOST_MAILTO , VALID_PUBLIC_KEY , VALID_PRIVATE_KEY , contentEncoding ) ;
193+ } ,
174194 function ( contentEncoding ) {
175195 return vapidHelper . getVapidHeaders ( VALID_AUDIENCE , VALID_SUBJECT_URL , VALID_PUBLIC_KEY , VALID_PRIVATE_KEY , contentEncoding , VALID_EXPIRATION ) ;
176196 } ,
0 commit comments