Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: stop ignoring NODE_TLS_REJECT_UNAUTHORIZED when strictSSL is not defined #316

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ const conditionalHeaders = [
const configureOptions = (opts) => {
const { strictSSL, ...options } = { ...opts }
options.method = options.method ? options.method.toUpperCase() : 'GET'
options.rejectUnauthorized = strictSSL !== false

if (strictSSL === undefined || strictSSL === null) {
options.rejectUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED !== '0'
} else {
options.rejectUnauthorized = strictSSL !== false
}

if (!options.retry) {
options.retry = { retries: 0 }
Expand Down
24 changes: 24 additions & 0 deletions test/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,30 @@
'should treat strictSSL: null as true just like tls.connect')
})

t.test('when NODE_TLS_REJECT_UNAUTHORIZED is defined', async (t) => {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
Dismissed Show dismissed Hide dismissed

t.same(configureOptions({ }).rejectUnauthorized, false,
'should return rejectUnauthorized false when NODE_TLS_REJECT_UNAUTHORIZED="0" ' +
'and strictSSL is undefined')

t.same(configureOptions({ strictSSL: null }).rejectUnauthorized, false,
'should return rejectUnauthorized false when NODE_TLS_REJECT_UNAUTHORIZED="0" ' +
'and strictSSL is null')

t.same(configureOptions({ strictSSL: true }).rejectUnauthorized, true,
'should return rejectUnauthorized true when NODE_TLS_REJECT_UNAUTHORIZED="0" ' +
'and strictSSL is true')

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1'

t.same(configureOptions({ strictSSL: false }).rejectUnauthorized, false,
'should return rejectUnauthorized false when NODE_TLS_REJECT_UNAUTHORIZED="1" ' +
'and strictSSL is false')

process.env.NODE_TLS_REJECT_UNAUTHORIZED = undefined
})

t.test('should set dns property correctly', async (t) => {
t.test('no property given', async (t) => {
const actualOpts = { method: 'GET' }
Expand Down
Loading