Skip to content

Commit

Permalink
Merge pull request #655 from salesforcecli/sh/add-proxy-envs
Browse files Browse the repository at this point in the history
fix: add proxy envs to telemetry
  • Loading branch information
WillieRuemmele authored Jul 22, 2024
2 parents 8d56c5b + a2f8ca3 commit 82324fb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/gatherEnvs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ const isOurEnv = (key: string): boolean =>
key.startsWith('JSFORCE_') ||
key === 'FORCE_OPEN_URL' ||
key === 'FORCE_SHOW_SPINNER' ||
key === 'FORCE_SPINNER_DELAY';
key === 'FORCE_SPINNER_DELAY' ||
key === 'HTTPS_PROXY' ||
key === 'HTTP_PROXY' ||
key === 'https_proxy' ||
key === 'http_proxy';

/** we do some automatic SFDX => SF and we don't want 2 of all of those */
const isNotDuplicatedAcrossCLIs = (key: string, index: number, array: string[]): boolean =>
Expand Down
54 changes: 53 additions & 1 deletion test/gatherEnvs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getRelevantEnvs } from '../src/gatherEnvs.js';

const testEnvs = ['SF_TEST', 'SFDX_TEST', 'SF_TEST2', 'OTHER_ENV'];
describe('gatherEnvs', () => {
beforeEach(() => {
afterEach(() => {
testEnvs.map((env) => delete process.env[env]);
});

Expand Down Expand Up @@ -42,4 +42,56 @@ describe('gatherEnvs', () => {
process.env.OTHER_ENV = 'test';
expect(getRelevantEnvs()).to.deep.equal({ specifiedEnvs: [], uniqueEnvs: [] });
});

describe('for proxies', () => {
const proxyEnvs = ['HTTPS_PROXY', 'HTTP_PROXY', 'https_proxy', 'http_proxy'];

afterEach(() => {
proxyEnvs.map((env) => delete process.env[env]);
});

it('returns HTTPS env', () => {
process.env.HTTPS_PROXY = 'HTTPS-test';
expect(getRelevantEnvs()).to.deep.equal({ specifiedEnvs: ['HTTPS_PROXY'], uniqueEnvs: ['HTTPS_PROXY'] });
});

it('returns HTTP env', () => {
process.env.HTTP_PROXY = 'HTTP-test';
expect(getRelevantEnvs()).to.deep.equal({ specifiedEnvs: ['HTTP_PROXY'], uniqueEnvs: ['HTTP_PROXY'] });
});

it('returns HTTPS and HTTP env', () => {
process.env.HTTPS_PROXY = 'HTTPS-test';
process.env.HTTP_PROXY = 'HTTP-test';
expect(getRelevantEnvs()).to.deep.equal({
specifiedEnvs: ['HTTPS_PROXY', 'HTTP_PROXY'],
uniqueEnvs: ['HTTPS_PROXY', 'HTTP_PROXY'],
});
});

it('returns https env', () => {
// eslint-disable-next-line camelcase
process.env.https_proxy = 'https-test';
expect(getRelevantEnvs()).to.deep.equal({ specifiedEnvs: ['https_proxy'], uniqueEnvs: ['https_proxy'] });
});

it('returns http env', () => {
// eslint-disable-next-line camelcase
process.env.http_proxy = 'http-test';
expect(getRelevantEnvs()).to.deep.equal({ specifiedEnvs: ['http_proxy'], uniqueEnvs: ['http_proxy'] });
});

it('returns HTTPS, HTTP, https, http env', () => {
process.env.HTTPS_PROXY = 'HTTPS-test';
process.env.HTTP_PROXY = 'HTTP-test';
// eslint-disable-next-line camelcase
process.env.https_proxy = 'https-test';
// eslint-disable-next-line camelcase
process.env.http_proxy = 'http-test';
expect(getRelevantEnvs()).to.deep.equal({
specifiedEnvs: ['HTTPS_PROXY', 'HTTP_PROXY', 'http_proxy', 'https_proxy'],
uniqueEnvs: ['HTTPS_PROXY', 'HTTP_PROXY', 'http_proxy', 'https_proxy'],
});
});
});
});

0 comments on commit 82324fb

Please sign in to comment.