@@ -9,8 +9,12 @@ const webPush = require('../src/index');
9
9
const vapidHelper = require ( '../src/vapid-helper' ) ;
10
10
11
11
const 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' ;
14
18
const VALID_PUBLIC_KEY = urlBase64 . encode ( Buffer . alloc ( 65 ) ) ;
15
19
const VALID_UNSAFE_BASE64_PUBLIC_KEY = Buffer . alloc ( 65 ) . toString ( 'base64' ) ;
16
20
const VALID_PRIVATE_KEY = urlBase64 . encode ( Buffer . alloc ( 32 ) ) ;
@@ -101,6 +105,14 @@ suite('Test Vapid Helpers', function() {
101
105
function ( ) {
102
106
vapidHelper . getVapidHeaders ( 'Not a URL' , VALID_SUBJECT_MAILTO , VALID_PUBLIC_KEY , VALID_PRIVATE_KEY ) ;
103
107
} ,
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
+ } ,
104
116
function ( ) {
105
117
vapidHelper . getVapidHeaders ( VALID_AUDIENCE , 'Some Random String' , VALID_PUBLIC_KEY , VALID_PRIVATE_KEY ) ;
106
118
} ,
@@ -168,9 +180,17 @@ suite('Test Vapid Helpers', function() {
168
180
function ( contentEncoding ) {
169
181
return vapidHelper . getVapidHeaders ( VALID_AUDIENCE , VALID_SUBJECT_URL , VALID_PUBLIC_KEY , VALID_PRIVATE_KEY , contentEncoding ) ;
170
182
} ,
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
+ } ,
171
187
function ( contentEncoding ) {
172
188
return vapidHelper . getVapidHeaders ( VALID_AUDIENCE , VALID_SUBJECT_MAILTO , VALID_PUBLIC_KEY , VALID_PRIVATE_KEY , contentEncoding ) ;
173
189
} ,
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
+ } ,
174
194
function ( contentEncoding ) {
175
195
return vapidHelper . getVapidHeaders ( VALID_AUDIENCE , VALID_SUBJECT_URL , VALID_PUBLIC_KEY , VALID_PRIVATE_KEY , contentEncoding , VALID_EXPIRATION ) ;
176
196
} ,
0 commit comments