Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Fix missing proxy auth #42

Merged
merged 3 commits into from Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions __tests__/proxy.test.ts
Expand Up @@ -2,6 +2,7 @@ import * as http from 'http'
import * as httpm from '../_out'
import * as pm from '../_out/proxy'
import * as proxy from 'proxy'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index.ts

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests/proxy.test.ts

import * as tunnelm from 'tunnel'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests/proxy.test.ts


let _proxyConnects: string[]
let _proxyServer: http.Server
Expand Down Expand Up @@ -195,6 +196,26 @@ describe('proxy', () => {
expect(obj.url).toBe('https://httpbin.org/get')
expect(_proxyConnects).toHaveLength(0)
})

it('proxyAuth not set in tunnel agent when authentication is not provided', async () => {
process.env['https_proxy'] = 'http://127.0.0.1:8080'
const httpClient = new httpm.HttpClient()
let agent: tunnelm.TunnelingAgent = httpClient.getAgent('https://some-url')
console.log(agent)
expect(agent.proxyOptions.host).toBe('127.0.0.1')
expect(agent.proxyOptions.port).toBe('8080')
expect(agent.proxyOptions.proxyAuth).toBe(undefined)
})

it('proxyAuth is set in tunnel agent when authentication is provided', async () => {
process.env['https_proxy'] = 'http://user:password@127.0.0.1:8080'
const httpClient = new httpm.HttpClient()
let agent: tunnelm.TunnelingAgent = httpClient.getAgent('https://some-url')
console.log(agent)
expect(agent.proxyOptions.host).toBe('127.0.0.1')
expect(agent.proxyOptions.port).toBe('8080')
expect(agent.proxyOptions.proxyAuth).toBe('user:password')
})
})

function _clearVars() {
Expand Down
2 changes: 1 addition & 1 deletion index.ts
Expand Up @@ -642,7 +642,7 @@ export class HttpClient {
maxSockets: maxSockets,
keepAlive: this._keepAlive,
proxy: {
proxyAuth: `${proxyUrl.username}:${proxyUrl.password}`,
...((proxyUrl.username || proxyUrl.password) && { proxyAuth: `${proxyUrl.username}:${proxyUrl.password}` }),
bryanmacfarlane marked this conversation as resolved.
Show resolved Hide resolved
pravipati marked this conversation as resolved.
Show resolved Hide resolved
host: proxyUrl.hostname,
port: proxyUrl.port
}
Expand Down