Skip to content

Commit

Permalink
Merge pull request #323 from evanshortiss/master
Browse files Browse the repository at this point in the history
fix: empty options no longer disable certificate checks
  • Loading branch information
web2solutions committed Aug 9, 2023
2 parents 79dacfa + 372d387 commit db562b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/eventsource.js
Expand Up @@ -103,7 +103,7 @@ function EventSource (url, eventSourceInitDict) {

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

if (eventSourceInitDict && eventSourceInitDict.createConnection !== undefined) {
options.createConnection = eventSourceInitDict.createConnection
Expand Down
14 changes: 14 additions & 0 deletions test/eventsource_test.js
Expand Up @@ -705,6 +705,20 @@ describe('HTTPS Support', function () {
}
})
})

it('fails to connect to self signed servers when options are provided but options.rejectUnauthorized is not specified', function (done) {
createHttpsServer(function (err, server) {
if (err) return done(err)

var es = new EventSource(server.url, {})
es.onopen = function () {
done(new Error('the socket should not have been opened, since options.rejectUnauthorized was not set to true'))
}
es.onerror = function () {
done()
}
})
})
})

describe('HTTPS Client Certificate Support', function () {
Expand Down

0 comments on commit db562b8

Please sign in to comment.