diff --git a/lib/proxy.spec.ts b/lib/proxy.spec.ts index c999ed909f9d3d7d3836ada0a3e98e92a96ea19e..408b9a275d51715c0b5672249d0ce7b60a5d9ab1 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 a1f7ca6d61a8a835877b97e0229509de0eaccf99..cb577b55c3f2adaadddc274cb8ee5d43f9d622e5 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 ebc1c16900a513423e15850c6bbda3dc6f69f9bc..b0e67ddf965d81d016159a6db4e86e4dea7a698c 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 faffd61bf8152631c87d651775975781671f743b..480338560ec826e584d7cf3591c6427f35a3d443 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',