Skip to content

Commit

Permalink
add some tests of getAgent()
Browse files Browse the repository at this point in the history
  • Loading branch information
bhamail committed Dec 18, 2020
1 parent 08c8152 commit 3316651
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/Services/RequestHelpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,61 @@ describe('RequestHelpers', () => {
expect(res).to.include.members(expected);
});

it('getAgent() should return undefined when no env variable is set', () => {
// eslint-disable-next-line @typescript-eslint/camelcase
process.env.http_proxy = 'no-proxy';

const res = RequestHelpers.getAgent();
expect(res).to.be.undefined;
});

it('getAgent() should return a proxy httpAgent when env variable is set', () => {
// eslint-disable-next-line @typescript-eslint/camelcase
process.env.http_proxy = 'http://test.local:8080';
const res = RequestHelpers.getAgent();
expect(res).not.to.be.undefined;
if (res) {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
expect(res.proxy.host).to.equal('test.local');
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
expect(res.proxy.port).to.equal(8080);
}
});

it('getAgent() should return an insecure httpAgent', () => {
const res = RequestHelpers.getAgent(true);
expect(res).not.to.be.undefined;
if (res) {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
expect(res.options.rejectUnauthorized).to.equal(false);
}
});

// TODO: This may indicate a problem. In the case of insecure, the proxy setting is ignored
// see: https://github.com/sonatype-nexus-community/auditjs/pull/213#discussion_r545617666
/*
it('getAgent() should return an insecure proxy httpAgent when env variable is set', () => {
// eslint-disable-next-line @typescript-eslint/camelcase
process.env.http_proxy = 'http://test.local:8080';
const res = RequestHelpers.getAgent(true);
expect(res).not.to.be.undefined;
if (res) {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
expect(res.options.rejectUnauthorized).to.equal(false);
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
expect(res.proxy.host).to.equal('test.local');
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
expect(res.proxy.port).to.equal(8080);
}
});
*/

it('should return an httpAgent when env variable is set', () => {
// eslint-disable-next-line @typescript-eslint/camelcase
process.env.http_proxy = 'http://test.local:8080';
Expand Down

0 comments on commit 3316651

Please sign in to comment.