Skip to content
Snippets Groups Projects
Unverified Commit dd462359 authored by jose-ws's avatar jose-ws Committed by GitHub
Browse files

feat(proxy): lowercase proxy env (#10025)

parent e7506fef
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,9 @@ describe('proxy', () => { ...@@ -7,7 +7,9 @@ describe('proxy', () => {
beforeEach(() => { beforeEach(() => {
delete process.env.HTTP_PROXY; delete process.env.HTTP_PROXY;
delete process.env.http_proxy;
delete process.env.HTTPS_PROXY; delete process.env.HTTPS_PROXY;
delete process.env.https_proxy;
delete process.env.NO_PROXY; delete process.env.NO_PROXY;
delete process.env.no_proxy; delete process.env.no_proxy;
}); });
...@@ -17,11 +19,35 @@ describe('proxy', () => { ...@@ -17,11 +19,35 @@ describe('proxy', () => {
bootstrap(); bootstrap();
expect(hasProxy()).toBeTrue(); 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', () => { it('respects HTTPS_PROXY', () => {
process.env.HTTPS_PROXY = httpsProxy; process.env.HTTPS_PROXY = httpsProxy;
bootstrap(); bootstrap();
expect(hasProxy()).toBeTrue(); 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', () => { it('does nothing', () => {
process.env.no_proxy = noProxy; process.env.no_proxy = noProxy;
bootstrap(); bootstrap();
......
...@@ -14,6 +14,10 @@ export function bootstrap(): void { ...@@ -14,6 +14,10 @@ export function bootstrap(): void {
) { ) {
process.env[envVar] = process.env[envVar.toLowerCase()]; process.env[envVar] = process.env[envVar.toLowerCase()];
} }
if (process.env[envVar]) {
process.env[envVar.toLowerCase()] = process.env[envVar];
}
}); });
if ( if (
......
...@@ -21,18 +21,16 @@ describe('getChildProcess environment when trustlevel set to low', () => { ...@@ -21,18 +21,16 @@ describe('getChildProcess environment when trustlevel set to low', () => {
envVars.forEach((env) => delete process.env[env]); envVars.forEach((env) => delete process.env[env]);
}); });
it('returns default environment variables', () => { it('returns default environment variables', () => {
expect(getChildProcessEnv()).toMatchInlineSnapshot(` expect(getChildProcessEnv()).toMatchObject({
Object { DOCKER_HOST: 'DOCKER_HOST',
"DOCKER_HOST": "DOCKER_HOST", HOME: 'HOME',
"HOME": "HOME", HTTPS_PROXY: 'HTTPS_PROXY',
"HTTPS_PROXY": "HTTPS_PROXY", HTTP_PROXY: 'HTTP_PROXY',
"HTTP_PROXY": "HTTP_PROXY", LANG: 'LANG',
"LANG": "LANG", LC_ALL: 'LC_ALL',
"LC_ALL": "LC_ALL", NO_PROXY: 'NO_PROXY',
"NO_PROXY": "NO_PROXY", PATH: 'PATH',
"PATH": "PATH", });
}
`);
}); });
it('returns environment variable only if defined', () => { it('returns environment variable only if defined', () => {
delete process.env.PATH; delete process.env.PATH;
...@@ -40,19 +38,17 @@ describe('getChildProcess environment when trustlevel set to low', () => { ...@@ -40,19 +38,17 @@ describe('getChildProcess environment when trustlevel set to low', () => {
}); });
it('returns custom environment variables if passed and defined', () => { it('returns custom environment variables if passed and defined', () => {
process.env.FOOBAR = 'FOOBAR'; process.env.FOOBAR = 'FOOBAR';
expect(getChildProcessEnv(['FOOBAR'])).toMatchInlineSnapshot(` expect(getChildProcessEnv(['FOOBAR'])).toMatchObject({
Object { DOCKER_HOST: 'DOCKER_HOST',
"DOCKER_HOST": "DOCKER_HOST", FOOBAR: 'FOOBAR',
"FOOBAR": "FOOBAR", HOME: 'HOME',
"HOME": "HOME", HTTPS_PROXY: 'HTTPS_PROXY',
"HTTPS_PROXY": "HTTPS_PROXY", HTTP_PROXY: 'HTTP_PROXY',
"HTTP_PROXY": "HTTP_PROXY", LANG: 'LANG',
"LANG": "LANG", LC_ALL: 'LC_ALL',
"LC_ALL": "LC_ALL", NO_PROXY: 'NO_PROXY',
"NO_PROXY": "NO_PROXY", PATH: 'PATH',
"PATH": "PATH", });
}
`);
delete process.env.LANG; delete process.env.LANG;
}); });
......
...@@ -4,6 +4,9 @@ const basicEnvVars = [ ...@@ -4,6 +4,9 @@ const basicEnvVars = [
'HTTP_PROXY', 'HTTP_PROXY',
'HTTPS_PROXY', 'HTTPS_PROXY',
'NO_PROXY', 'NO_PROXY',
'http_proxy',
'https_proxy',
'no_proxy',
'HOME', 'HOME',
'PATH', 'PATH',
'LC_ALL', 'LC_ALL',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment