Skip to content

Fix bug in proxy where HTTPS_PROXY became 'undefined' #3913

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

Merged
merged 4 commits into from
Apr 9, 2019
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
8 changes: 6 additions & 2 deletions packages/server/lib/util/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ const copyLowercaseEnvToUppercase = (name: string) => {
}

const normalizeEnvironmentProxy = () => {
if (!process.env.HTTPS_PROXY) {
if (process.env.HTTP_PROXY === 'false' || process.env.HTTP_PROXY === '0' || !process.env.HTTP_PROXY) {
delete process.env.HTTP_PROXY
}

if (!process.env.HTTPS_PROXY && process.env.HTTP_PROXY) {
// request library will use HTTP_PROXY as a fallback for HTTPS urls, but
// proxy-from-env will not, so let's just force it to fall back like this
process.env.HTTPS_PROXY = process.env.HTTP_PROXY
Expand All @@ -27,7 +31,7 @@ const normalizeEnvironmentProxy = () => {
export const loadSystemProxySettings = () => {
['NO_PROXY', 'HTTP_PROXY', 'HTTPS_PROXY'].forEach(copyLowercaseEnvToUppercase)

if (process.env.HTTP_PROXY) {
if (typeof process.env.HTTP_PROXY !== 'undefined') {
normalizeEnvironmentProxy()

return
Expand Down
3 changes: 3 additions & 0 deletions packages/server/test/spec_helper.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ hasOnly = false

backup.apply(@, arguments)

originalEnv = process.env
env = _.clone(process.env)

sinon.usingPromise(Promise)
Expand Down Expand Up @@ -78,6 +79,8 @@ before ->
appData.ensure()

beforeEach ->
@originalEnv = originalEnv

nock.disableNetConnect()
nock.enableNetConnect(/localhost/)

Expand Down
31 changes: 26 additions & 5 deletions packages/server/test/unit/args_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,14 @@ describe "lib/util/args", ->

context "with proxy", ->
beforeEach ->
@beforeEnv = Object.assign({}, process.env)
process.env = @originalEnv
delete process.env.HTTP_PROXY
delete process.env.HTTPS_PROXY
delete process.env.NO_PROXY
delete process.env.http_proxy
delete process.env.https_proxy
delete process.env.no_proxy


it "sets options from environment", ->
process.env.HTTP_PROXY = "http://foo-bar.baz:123"
process.env.NO_PROXY = "a,b,c"
Expand All @@ -337,6 +336,31 @@ describe "lib/util/args", ->
expect(options.proxyBypassList).to.eq "d,e,f"
expect(options.proxyBypassList).to.eq process.env.NO_PROXY

['', 'false', '0'].forEach (override) ->
it "doesn't load from Windows registry if HTTP_PROXY overridden with string '#{override}'", ->
sinon.stub(getWindowsProxyUtil, "getWindowsProxy").returns()
sinon.stub(os, "platform").returns("win32")
process.env.HTTP_PROXY = override
options = @setup()
expect(getWindowsProxyUtil.getWindowsProxy).to.not.beCalled
expect(options.proxySource).to.be.undefined
expect(options.proxyServer).to.be.undefined
expect(options.proxyBypassList).to.be.undefined
expect(process.env.HTTP_PROXY).to.be.undefined
expect(process.env.HTTPS_PROXY).to.be.undefined
expect(process.env.NO_PROXY).to.eq "localhost"

it "doesn't mess with env vars if Windows registry doesn't have proxy", ->
sinon.stub(getWindowsProxyUtil, "getWindowsProxy").returns()
sinon.stub(os, "platform").returns("win32")
options = @setup()
expect(options.proxySource).to.be.undefined
expect(options.proxyServer).to.be.undefined
expect(options.proxyBypassList).to.be.undefined
expect(process.env.HTTP_PROXY).to.be.undefined
expect(process.env.HTTPS_PROXY).to.be.undefined
expect(process.env.NO_PROXY).to.eq "localhost"

it "sets a default NO_PROXY", ->
process.env.HTTP_PROXY = "http://foo-bar.baz:123"
options = @setup()
Expand All @@ -361,6 +385,3 @@ describe "lib/util/args", ->
expect(options.proxySource).to.be.undefined
expect(options.proxyServer).to.eq process.env.HTTP_PROXY
expect(options.proxyBypassList).to.eq process.env.NO_PROXY

afterEach ->
Object.assign(process.env, @beforeEnv)