Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

fix bugs related no_proxy #7

Merged
merged 2 commits into from
Jan 23, 2020
Merged

Conversation

ericsciple
Copy link
Collaborator

  1. https://github.com should match no_proxy=github.com:443
  2. https://github.com:8080 should match no_proxy=github.com

…no_proxy=foo.com:443 and 2) https://foo.com:8080 should match no_proxy=foo.com
@@ -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', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simplify the unit tests related to bypass scenarios, I added another exported function checkBypass(string) to proxy.ts

Therefore I prefixed the test names to clarify which function was being exercised.

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', () => {
it('getProxyUrl does not return proxyUrl if https_proxy set and in no_proxy list', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many of the existing no_proxy tests moved down to the section that exercises the checkBypass function.

I kept a few basic tests here:

  1. https_proxy in no_proxy
  2. https_proxy not in no_proxy
  3. http_proxy in no_proxy
  4. http_proxy not in no_proxy

it('returns proxyUrl if https_proxy set and not in no_proxy list', () => {
process.env["https_proxy"] = "https://myproxysvr";

it('checkBypass returns true if host with port in no_proxy list without port', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is genuinely new and failed before.

expect(bypass).toBeTruthy();
})

it('checkBypass returns true if host in no_proxy list with default https port', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is genuinely new and failed before.

Since the no_proxy list is shared between https_proxy and http_proxy, this scenario should work.

* Returns the proxy URL, depending upon the supplied url and proxy environment variables.
* @param serverUrl The server URL where the request will be sent. For example, https://api.github.com
*/
export function getProxyUrl(serverUrl: string): string {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public function now exported. I'm planning to use this in checkout to add the server url to the git config

reqPort = 443
}

// Format the request hostname and hostname with port
Copy link
Collaborator Author

@ericsciple ericsciple Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trick here is generate two host values to check against the no_proxy list.

When reqUrl is like https://foo.com this will create two strings to check against the bypass list: FOO.COM and FOO.COM:443

This fixes the two bugs before:

  1. https://github.com should match no_proxy=github.com:443
  2. https://github.com:8080 should match no_proxy=github.com

upperReqHosts.push(`${upperReqHosts[0]}:${reqPort}`)
}

// Compare request host against noproxy
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also note i check uppercase rather than lowercase which i believe is supposed to be better b/c of Turkish i


// Determine the request port
let reqPort: number
if (reqUrl.port) {
Copy link
Collaborator Author

@ericsciple ericsciple Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Url.port is empty for urls like http://foo.com so i have a few if blocks to set based on the default port for the protocol

@ericsciple ericsciple changed the title fix bugs related no_proxy and ports fix bugs related no_proxy Jan 23, 2020
@bryanmacfarlane
Copy link
Member

LGTM

@bryanmacfarlane bryanmacfarlane merged commit f18f070 into master Jan 23, 2020
@bryanmacfarlane bryanmacfarlane deleted the users/ericsciple/m164bypass branch January 23, 2020 13:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants