Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: respect NODE_TLS_REJECT_UNAUTHORIZED #146

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ const fetch = async (url, opts) => {
clearTimeout(reqTimeout)
}

if (process.env['NODE_TLS_REJECT_UNAUTHORIZED'] === '0') {
options.agent = options.agent || new https.Agent()
options.agent.options.rejectUnauthorized = false
}

// send request
const req = send(options)

Expand Down
6 changes: 6 additions & 0 deletions test/https-with-ca-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ t.test('make https request with rejectUnauthorized:false, succeeds', async t =>
t.equal(await (await fetch(`${base}hello`, { rejectUnauthorized: false })).text(),
'GET /hello'))

t.test("make https request with process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0', succeeds", async t => {
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'
t.equal(await (await fetch(`${base}hello`)).text(), 'GET /hello')
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = undefined
})

t.test('make https request with ca, succeeds', async t =>
t.equal(await (await fetch(`${base}hello`, { ca })).text(),
'GET /hello'))