fix bugs related no_proxy and ports: 1) https://foo.com should match no_proxy=foo.com:443 and 2) https://foo.com:8080 should match no_proxy=foo.com

This commit is contained in:
eric sciple
2020-01-22 23:09:35 -05:00
parent 9e8142913f
commit d745dd984c
4 changed files with 138 additions and 61 deletions

View File

@@ -39,72 +39,112 @@ describe('proxy', () => {
})
})
it('does not return proxyUrl if variables not set', () => {
it('getProxyUrl does not return proxyUrl if variables not set', () => {
let proxyUrl = pm.getProxyUrl(url.parse('https://github.com'));
expect(proxyUrl).toBeUndefined();
})
it('returns proxyUrl if https_proxy set for https url', () => {
it('getProxyUrl returns proxyUrl if https_proxy set for https url', () => {
process.env["https_proxy"] = "https://myproxysvr";
let proxyUrl = pm.getProxyUrl(url.parse('https://github.com'));
expect(proxyUrl).toBeDefined();
})
it('does not return proxyUrl if http_proxy set for https url', () => {
it('getProxyUrl does not return proxyUrl if http_proxy set for https url', () => {
process.env["http_proxy"] = "https://myproxysvr";
let proxyUrl = pm.getProxyUrl(url.parse('https://github.com'));
expect(proxyUrl).toBeUndefined();
})
it('returns proxyUrl if http_proxy set for http url', () => {
it('getProxyUrl returns proxyUrl if http_proxy set for http url', () => {
process.env["http_proxy"] = "http://myproxysvr";
let proxyUrl = pm.getProxyUrl(url.parse('http://github.com'));
expect(proxyUrl).toBeDefined();
})
it('does not return proxyUrl if only host as no_proxy list', () => {
process.env["https_proxy"] = "https://myproxysvr";
process.env["no_proxy"] = "myserver"
let proxyUrl = pm.getProxyUrl(url.parse('https://myserver'));
expect(proxyUrl).toBeUndefined();
})
it('does not return proxyUrl if host in no_proxy list', () => {
it('getProxyUrl does not return proxyUrl if https_proxy set and in no_proxy list', () => {
process.env["https_proxy"] = "https://myproxysvr";
process.env["no_proxy"] = "otherserver,myserver,anotherserver:8080"
let proxyUrl = pm.getProxyUrl(url.parse('https://myserver'));
expect(proxyUrl).toBeUndefined();
})
it('does not return proxyUrl if host in no_proxy list with spaces', () => {
it('getProxyUrl returns proxyUrl if https_proxy set and not in no_proxy list', () => {
process.env["https_proxy"] = "https://myproxysvr";
process.env["no_proxy"] = "otherserver, myserver ,anotherserver:8080"
let proxyUrl = pm.getProxyUrl(url.parse('https://myserver'));
expect(proxyUrl).toBeUndefined();
})
it('does not return proxyUrl if host in no_proxy list with ports', () => {
process.env["https_proxy"] = "https://myproxysvr";
process.env["no_proxy"] = "otherserver, myserver:8080 ,anotherserver"
let proxyUrl = pm.getProxyUrl(url.parse('https://myserver:8080'));
expect(proxyUrl).toBeUndefined();
})
it('returns proxyUrl if https_proxy set and not in no_proxy list', () => {
process.env["https_proxy"] = "https://myproxysvr";
process.env["no_proxy"] = "otherserver, myserver ,anotherserver:8080"
let proxyUrl = pm.getProxyUrl(url.parse('https://github.com'));
expect(proxyUrl).toBeDefined();
})
it('returns proxyUrl if https_proxy set empty no_proxy set', () => {
process.env["https_proxy"] = "https://myproxysvr";
process.env["no_proxy"] = ""
process.env["no_proxy"] = "otherserver,myserver,anotherserver:8080"
let proxyUrl = pm.getProxyUrl(url.parse('https://github.com'));
expect(proxyUrl).toBeDefined();
})
it('does basic http get request through proxy', async () => {
it('getProxyUrl does not return proxyUrl if http_proxy set and in no_proxy list', () => {
process.env["http_proxy"] = "http://myproxysvr";
process.env["no_proxy"] = "otherserver,myserver,anotherserver:8080"
let proxyUrl = pm.getProxyUrl(url.parse('http://myserver'));
expect(proxyUrl).toBeUndefined();
})
it('getProxyUrl returns proxyUrl if http_proxy set and not in no_proxy list', () => {
process.env["http_proxy"] = "http://myproxysvr";
process.env["no_proxy"] = "otherserver,myserver,anotherserver:8080"
let proxyUrl = pm.getProxyUrl(url.parse('http://github.com'));
expect(proxyUrl).toBeDefined();
})
it('checkBypass returns true if host as no_proxy list', () => {
process.env["no_proxy"] = "myserver"
let bypass = pm.checkBypass(url.parse('https://myserver'));
expect(bypass).toBeTruthy();
})
it('checkBypass returns true if host in no_proxy list', () => {
process.env["no_proxy"] = "otherserver,myserver,anotherserver:8080"
let bypass = pm.checkBypass(url.parse('https://myserver'));
expect(bypass).toBeTruthy();
})
it('checkBypass returns true if host in no_proxy list with spaces', () => {
process.env["no_proxy"] = "otherserver, myserver ,anotherserver:8080"
let bypass = pm.checkBypass(url.parse('https://myserver'));
expect(bypass).toBeTruthy();
})
it('checkBypass returns true if host in no_proxy list with port', () => {
process.env["no_proxy"] = "otherserver, myserver:8080 ,anotherserver"
let bypass = pm.checkBypass(url.parse('https://myserver:8080'));
expect(bypass).toBeTruthy();
})
it('checkBypass returns true if host with port in no_proxy list without port', () => {
process.env["no_proxy"] = "otherserver, myserver ,anotherserver"
let bypass = pm.checkBypass(url.parse('https://myserver:8080'));
expect(bypass).toBeTruthy();
})
it('checkBypass returns true if host in no_proxy list with default https port', () => {
process.env["no_proxy"] = "otherserver, myserver:443 ,anotherserver"
let bypass = pm.checkBypass(url.parse('https://myserver'));
expect(bypass).toBeTruthy();
})
it('checkBypass returns true if host in no_proxy list with default http port', () => {
process.env["no_proxy"] = "otherserver, myserver:80 ,anotherserver"
let bypass = pm.checkBypass(url.parse('http://myserver'));
expect(bypass).toBeTruthy();
})
it('checkBypass returns false if host not in no_proxy list', () => {
process.env["no_proxy"] = "otherserver, myserver ,anotherserver:8080"
let bypass = pm.checkBypass(url.parse('https://github.com'));
expect(bypass).toBeFalsy();
})
it('checkBypass returns false if empty no_proxy', () => {
process.env["no_proxy"] = ""
let bypass = pm.checkBypass(url.parse('https://github.com'));
expect(bypass).toBeFalsy();
})
it('HttpClient does basic http get request through proxy', async () => {
process.env['http_proxy'] = _proxyUrl
const httpClient = new httpm.HttpClient();
let res: httpm.HttpClientResponse = await httpClient.get('http://httpbin.org/get');
@@ -115,7 +155,7 @@ describe('proxy', () => {
expect(_proxyConnects).toEqual(['httpbin.org:80'])
})
it('does basic http get request when bypass proxy', async () => {
it('HttoClient does basic http get request when bypass proxy', async () => {
process.env['http_proxy'] = _proxyUrl
process.env['no_proxy'] = 'httpbin.org'
const httpClient = new httpm.HttpClient();
@@ -127,7 +167,7 @@ describe('proxy', () => {
expect(_proxyConnects).toHaveLength(0)
})
it('does basic https get request through proxy', async () => {
it('HttpClient does basic https get request through proxy', async () => {
process.env['https_proxy'] = _proxyUrl
const httpClient = new httpm.HttpClient();
let res: httpm.HttpClientResponse = await httpClient.get('https://httpbin.org/get');
@@ -138,7 +178,7 @@ describe('proxy', () => {
expect(_proxyConnects).toEqual(['httpbin.org:443'])
})
it('does basic https get request when bypass proxy', async () => {
it('HttpClient does basic https get request when bypass proxy', async () => {
process.env['https_proxy'] = _proxyUrl
process.env['no_proxy'] = 'httpbin.org'
const httpClient = new httpm.HttpClient();