@@ -12,8 +12,6 @@ const jws = require('jws');
12
12
const mocha = require ( 'mocha' ) ;
13
13
const WebPushConstants = require ( '../src/web-push-constants.js' ) ;
14
14
15
- process . env . NODE_TLS_REJECT_UNAUTHORIZED = '0' ;
16
-
17
15
suite ( 'sendNotification' , function ( ) {
18
16
test ( 'is defined' , function ( ) {
19
17
const webPush = require ( '../src/index' ) ;
@@ -22,9 +20,18 @@ suite('sendNotification', function() {
22
20
23
21
let server ;
24
22
let serverPort ;
23
+ const pem = fs . readFileSync ( 'test/data/certs/cert.pem' ) ;
25
24
let requestBody ;
26
25
let requestDetails ;
27
- let originalHTTPSRequest = https . request ;
26
+
27
+ const originalHTTPSRequest = https . request ;
28
+
29
+ // https request mock to accept self-signed certificate.
30
+ // Probably worth switching with proxyquire and sinon.
31
+ const certHTTPSRequest = function ( options , listener ) {
32
+ options . rejectUnauthorized = false ;
33
+ return originalHTTPSRequest . call ( https , options , listener ) ;
34
+ } ;
28
35
29
36
mocha . beforeEach ( function ( ) {
30
37
requestBody = null ;
@@ -35,7 +42,7 @@ suite('sendNotification', function() {
35
42
delete require . cache [ path . join ( __dirname , '..' , 'src' , 'web-push-lib.js' ) ] ;
36
43
37
44
// Reset https request mock
38
- https . request = originalHTTPSRequest ;
45
+ https . request = certHTTPSRequest ;
39
46
40
47
let returnPromise = Promise . resolve ( ) ;
41
48
if ( ! server ) {
@@ -62,8 +69,6 @@ suite('sendNotification', function() {
62
69
const vapidKeys = require ( '../src/vapid-helper' ) . generateVAPIDKeys ( ) ;
63
70
64
71
function startServer ( ) {
65
- const pem = fs . readFileSync ( 'test/data/certs/cert.pem' ) ;
66
-
67
72
const options = {
68
73
key : pem ,
69
74
cert : pem
@@ -452,7 +457,7 @@ suite('sendNotification', function() {
452
457
options . port = serverPort ;
453
458
options . path = '/' ;
454
459
455
- return originalHTTPSRequest . call ( https , options , listener ) ;
460
+ return certHTTPSRequest . call ( https , options , listener ) ;
456
461
} ;
457
462
458
463
// Set the default endpoint if it's not already configured
0 commit comments