Skip to content

Commit 372d387

Browse files
committed
fix: empty options no longer disable certificate checks
1 parent 79dacfa commit 372d387

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/eventsource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function EventSource (url, eventSourceInitDict) {
103103

104104
// Legacy: this should be specified as `eventSourceInitDict.https.rejectUnauthorized`,
105105
// but for now exists as a backwards-compatibility layer
106-
options.rejectUnauthorized = !(eventSourceInitDict && !eventSourceInitDict.rejectUnauthorized)
106+
options.rejectUnauthorized = !(eventSourceInitDict && typeof eventSourceInitDict.rejectUnauthorized === 'boolean' && !eventSourceInitDict.rejectUnauthorized)
107107

108108
if (eventSourceInitDict && eventSourceInitDict.createConnection !== undefined) {
109109
options.createConnection = eventSourceInitDict.createConnection

test/eventsource_test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,20 @@ describe('HTTPS Support', function () {
705705
}
706706
})
707707
})
708+
709+
it('fails to connect to self signed servers when options are provided but options.rejectUnauthorized is not specified', function (done) {
710+
createHttpsServer(function (err, server) {
711+
if (err) return done(err)
712+
713+
var es = new EventSource(server.url, {})
714+
es.onopen = function () {
715+
done(new Error('the socket should not have been opened, since options.rejectUnauthorized was not set to true'))
716+
}
717+
es.onerror = function () {
718+
done()
719+
}
720+
})
721+
})
708722
})
709723

710724
describe('HTTPS Client Certificate Support', function () {

0 commit comments

Comments
 (0)