From dd462359b41b80ebbdd40d22a6ac63d0cb0e9acc Mon Sep 17 00:00:00 2001 From: jose-ws <80274739+jose-ws@users.noreply.github.com> Date: Wed, 19 May 2021 07:37:27 -0400 Subject: [PATCH] feat(proxy): lowercase proxy env (#10025) --- lib/proxy.spec.ts | 26 ++++++++++++++++++++++ lib/proxy.ts | 4 ++++ lib/util/exec/env.spec.ts | 46 ++++++++++++++++++--------------------- lib/util/exec/env.ts | 3 +++ 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/lib/proxy.spec.ts b/lib/proxy.spec.ts index c999ed909f..408b9a275d 100644 --- a/lib/proxy.spec.ts +++ b/lib/proxy.spec.ts @@ -7,7 +7,9 @@ describe('proxy', () => { beforeEach(() => { delete process.env.HTTP_PROXY; + delete process.env.http_proxy; delete process.env.HTTPS_PROXY; + delete process.env.https_proxy; delete process.env.NO_PROXY; delete process.env.no_proxy; }); @@ -17,11 +19,35 @@ describe('proxy', () => { bootstrap(); expect(hasProxy()).toBeTrue(); }); + it('copies upper case HTTP_PROXY to http_proxy', () => { + process.env.HTTP_PROXY = httpProxy; + bootstrap(); + expect(hasProxy()).toBeTrue(); + expect(process.env.HTTP_PROXY).toBeDefined(); + expect(process.env.http_proxy).toBeDefined(); + + expect(process.env.HTTPS_PROXY).toBeUndefined(); + expect(process.env.https_proxy).toBeUndefined(); + expect(process.env.NO_PROXY).toBeUndefined(); + expect(process.env.no_proxy).toBeUndefined(); + }); it('respects HTTPS_PROXY', () => { process.env.HTTPS_PROXY = httpsProxy; bootstrap(); expect(hasProxy()).toBeTrue(); }); + it('copies upper case HTTPS_PROXY to https_proxy', () => { + process.env.HTTPS_PROXY = httpsProxy; + bootstrap(); + expect(hasProxy()).toBeTrue(); + expect(process.env.HTTPS_PROXY).toBeDefined(); + expect(process.env.https_proxy).toBeDefined(); + + expect(process.env.HTTP_PROXY).toBeUndefined(); + expect(process.env.http_proxy).toBeUndefined(); + expect(process.env.NO_PROXY).toBeUndefined(); + expect(process.env.no_proxy).toBeUndefined(); + }); it('does nothing', () => { process.env.no_proxy = noProxy; bootstrap(); diff --git a/lib/proxy.ts b/lib/proxy.ts index a1f7ca6d61..cb577b55c3 100644 --- a/lib/proxy.ts +++ b/lib/proxy.ts @@ -14,6 +14,10 @@ export function bootstrap(): void { ) { process.env[envVar] = process.env[envVar.toLowerCase()]; } + + if (process.env[envVar]) { + process.env[envVar.toLowerCase()] = process.env[envVar]; + } }); if ( diff --git a/lib/util/exec/env.spec.ts b/lib/util/exec/env.spec.ts index ebc1c16900..b0e67ddf96 100644 --- a/lib/util/exec/env.spec.ts +++ b/lib/util/exec/env.spec.ts @@ -21,18 +21,16 @@ describe('getChildProcess environment when trustlevel set to low', () => { envVars.forEach((env) => delete process.env[env]); }); it('returns default environment variables', () => { - expect(getChildProcessEnv()).toMatchInlineSnapshot(` - Object { - "DOCKER_HOST": "DOCKER_HOST", - "HOME": "HOME", - "HTTPS_PROXY": "HTTPS_PROXY", - "HTTP_PROXY": "HTTP_PROXY", - "LANG": "LANG", - "LC_ALL": "LC_ALL", - "NO_PROXY": "NO_PROXY", - "PATH": "PATH", - } - `); + expect(getChildProcessEnv()).toMatchObject({ + DOCKER_HOST: 'DOCKER_HOST', + HOME: 'HOME', + HTTPS_PROXY: 'HTTPS_PROXY', + HTTP_PROXY: 'HTTP_PROXY', + LANG: 'LANG', + LC_ALL: 'LC_ALL', + NO_PROXY: 'NO_PROXY', + PATH: 'PATH', + }); }); it('returns environment variable only if defined', () => { delete process.env.PATH; @@ -40,19 +38,17 @@ describe('getChildProcess environment when trustlevel set to low', () => { }); it('returns custom environment variables if passed and defined', () => { process.env.FOOBAR = 'FOOBAR'; - expect(getChildProcessEnv(['FOOBAR'])).toMatchInlineSnapshot(` - Object { - "DOCKER_HOST": "DOCKER_HOST", - "FOOBAR": "FOOBAR", - "HOME": "HOME", - "HTTPS_PROXY": "HTTPS_PROXY", - "HTTP_PROXY": "HTTP_PROXY", - "LANG": "LANG", - "LC_ALL": "LC_ALL", - "NO_PROXY": "NO_PROXY", - "PATH": "PATH", - } - `); + expect(getChildProcessEnv(['FOOBAR'])).toMatchObject({ + DOCKER_HOST: 'DOCKER_HOST', + FOOBAR: 'FOOBAR', + HOME: 'HOME', + HTTPS_PROXY: 'HTTPS_PROXY', + HTTP_PROXY: 'HTTP_PROXY', + LANG: 'LANG', + LC_ALL: 'LC_ALL', + NO_PROXY: 'NO_PROXY', + PATH: 'PATH', + }); delete process.env.LANG; }); diff --git a/lib/util/exec/env.ts b/lib/util/exec/env.ts index faffd61bf8..480338560e 100644 --- a/lib/util/exec/env.ts +++ b/lib/util/exec/env.ts @@ -4,6 +4,9 @@ const basicEnvVars = [ 'HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY', + 'http_proxy', + 'https_proxy', + 'no_proxy', 'HOME', 'PATH', 'LC_ALL', -- GitLab