public void WebProxyFromEnvironmentVariablesNoProxy() { try { Environment.SetEnvironmentVariable("http_proxy", "http://*****:*****@127.0.0.1:8888"); Environment.SetEnvironmentVariable("https_proxy", "http://*****:*****@127.0.0.1:9999"); Environment.SetEnvironmentVariable("no_proxy", "github.com, .google.com, example.com:444, 192.168.0.123:123, 192.168.1.123"); var proxy = new RunnerWebProxy(); Assert.False(proxy.IsBypassed(new Uri("https://actions.com"))); Assert.False(proxy.IsBypassed(new Uri("https://ggithub.com"))); Assert.False(proxy.IsBypassed(new Uri("https://github.comm"))); Assert.False(proxy.IsBypassed(new Uri("https://google.com"))); Assert.False(proxy.IsBypassed(new Uri("https://example.com"))); Assert.False(proxy.IsBypassed(new Uri("http://example.com:333"))); Assert.False(proxy.IsBypassed(new Uri("http://192.168.0.123:123"))); Assert.False(proxy.IsBypassed(new Uri("http://192.168.1.123/home"))); Assert.True(proxy.IsBypassed(new Uri("https://github.com"))); Assert.True(proxy.IsBypassed(new Uri("https://GITHUB.COM"))); Assert.True(proxy.IsBypassed(new Uri("https://github.com/owner/repo"))); Assert.True(proxy.IsBypassed(new Uri("https://actions.github.com"))); Assert.True(proxy.IsBypassed(new Uri("https://mails.google.com"))); Assert.True(proxy.IsBypassed(new Uri("https://MAILS.GOOGLE.com"))); Assert.True(proxy.IsBypassed(new Uri("https://mails.v2.google.com"))); Assert.True(proxy.IsBypassed(new Uri("http://mails.v2.v3.google.com/inbox"))); Assert.True(proxy.IsBypassed(new Uri("https://example.com:444"))); Assert.True(proxy.IsBypassed(new Uri("http://example.com:444"))); Assert.True(proxy.IsBypassed(new Uri("http://example.COM:444"))); } finally { CleanProxyEnv(); } }
public void WebProxyFromEnvironmentVariablesGetProxy() { try { Environment.SetEnvironmentVariable("http_proxy", "http://*****:*****@127.0.0.1:8888"); Environment.SetEnvironmentVariable("https_proxy", "http://*****:*****@127.0.0.1:9999"); Environment.SetEnvironmentVariable("no_proxy", "github.com, .google.com, example.com:444"); var proxy = new RunnerWebProxy(); Assert.Null(proxy.GetProxy(new Uri("http://github.com"))); Assert.Null(proxy.GetProxy(new Uri("https://github.com/owner/repo"))); Assert.Null(proxy.GetProxy(new Uri("https://mails.google.com"))); Assert.Null(proxy.GetProxy(new Uri("http://example.com:444"))); Assert.Equal("http://*****:*****@127.0.0.1:8888/", proxy.GetProxy(new Uri("http://something.com")).AbsoluteUri); Assert.Equal("http://*****:*****@127.0.0.1:8888/", proxy.GetProxy(new Uri("http://www.something2.com")).AbsoluteUri); Assert.Equal("http://*****:*****@127.0.0.1:9999/", proxy.GetProxy(new Uri("https://something.com")).AbsoluteUri); Assert.Equal("http://*****:*****@127.0.0.1:9999/", proxy.GetProxy(new Uri("https://www.something2.com")).AbsoluteUri); } finally { CleanProxyEnv(); } }
public void WebProxyFromEnvironmentVariablesProxyCredentialsEncoding() { try { Environment.SetEnvironmentVariable("http_proxy", "http://*****:*****@127.0.0.1:8888"); Environment.SetEnvironmentVariable("https_proxy", "http://*****:*****@127.0.0.1:9999"); Environment.SetEnvironmentVariable("no_proxy", "github.com, google.com,"); var proxy = new RunnerWebProxy(); Assert.Equal("http://*****:*****@127.0.0.1:8888/", proxy.HttpProxyAddress); Assert.Equal("user1", proxy.HttpProxyUsername); Assert.Equal("pass1@", proxy.HttpProxyPassword); var cred = proxy.Credentials.GetCredential(new Uri("http://*****:*****@127.0.0.1:8888/"), "Basic"); Assert.Equal("user1", cred.UserName); Assert.Equal("pass1@", cred.Password); Assert.Equal("http://*****:*****@127.0.0.1:9999/", proxy.HttpsProxyAddress); Assert.Equal("user2", proxy.HttpsProxyUsername); Assert.Equal("pass2@", proxy.HttpsProxyPassword); cred = proxy.Credentials.GetCredential(new Uri("http://*****:*****@127.0.0.1:9999/"), "Basic"); Assert.Equal("user2", cred.UserName); Assert.Equal("pass2@", cred.Password); Assert.Equal(2, proxy.NoProxyList.Count); Assert.Equal("github.com", proxy.NoProxyList[0].Host); Assert.Equal("google.com", proxy.NoProxyList[1].Host); } finally { CleanProxyEnv(); } }
public void WebProxyFromEnvironmentVariablesByPassEmptyProxy() { var proxy = new RunnerWebProxy(); Assert.True(proxy.IsBypassed(new Uri("https://github.com"))); Assert.True(proxy.IsBypassed(new Uri("https://github.com"))); }
public void WebProxyFromEnvironmentVariablesPreferLowerCase() { try { Environment.SetEnvironmentVariable("http_proxy", "http://127.0.0.1:7777"); Environment.SetEnvironmentVariable("HTTP_PROXY", "http://127.0.0.1:8888"); Environment.SetEnvironmentVariable("https_proxy", "http://*****:*****@127.0.0.1:8888"); Environment.SetEnvironmentVariable("HTTPS_PROXY", "http://*****:*****@127.0.0.1:9999"); Environment.SetEnvironmentVariable("no_proxy", "github.com, github.com "); Environment.SetEnvironmentVariable("NO_PROXY", "github.com, google.com,"); var proxy = new RunnerWebProxy(); Assert.Equal("http://127.0.0.1:7777/", proxy.HttpProxyAddress); Assert.Null(proxy.HttpProxyUsername); Assert.Null(proxy.HttpProxyPassword); Assert.Equal("http://*****:*****@127.0.0.1:8888/", proxy.HttpsProxyAddress); Assert.Equal("user", proxy.HttpsProxyUsername); Assert.Equal("pass", proxy.HttpsProxyPassword); Assert.Equal(1, proxy.NoProxyList.Count); Assert.Equal("github.com", proxy.NoProxyList[0].Host); } finally { CleanProxyEnv(); } }
public HttpClientHandler CreateClientHandler(RunnerWebProxy webProxy) { return(new HttpClientHandler() { Proxy = webProxy }); }
public void WebProxyFromEnvironmentVariablesWithPort80() { try { Environment.SetEnvironmentVariable("http_proxy", "http://127.0.0.1:80"); Environment.SetEnvironmentVariable("https_proxy", "http://*****:*****@127.0.0.1:80"); Environment.SetEnvironmentVariable("no_proxy", "github.com, google.com,"); var proxy = new RunnerWebProxy(); Assert.Equal("http://127.0.0.1:80", Environment.GetEnvironmentVariable("http_proxy")); Assert.Null(proxy.HttpProxyUsername); Assert.Null(proxy.HttpProxyPassword); Assert.Equal("http://*****:*****@127.0.0.1:80", Environment.GetEnvironmentVariable("https_proxy")); Assert.Equal("user", proxy.HttpsProxyUsername); Assert.Equal("pass", proxy.HttpsProxyPassword); Assert.Equal(2, proxy.NoProxyList.Count); Assert.Equal("github.com", proxy.NoProxyList[0].Host); Assert.Equal("google.com", proxy.NoProxyList[1].Host); } finally { CleanProxyEnv(); } }
private void UpdateWebProxyEnv(RunnerWebProxy webProxy) { // Set common forms of proxy variables if configured in Runner and not set directly by container.env if (!String.IsNullOrEmpty(webProxy.HttpProxyAddress)) { ContainerEnvironmentVariables.TryAdd("HTTP_PROXY", webProxy.HttpProxyAddress); ContainerEnvironmentVariables.TryAdd("http_proxy", webProxy.HttpProxyAddress); } if (!String.IsNullOrEmpty(webProxy.HttpsProxyAddress)) { ContainerEnvironmentVariables.TryAdd("HTTPS_PROXY", webProxy.HttpsProxyAddress); ContainerEnvironmentVariables.TryAdd("https_proxy", webProxy.HttpsProxyAddress); } if (!String.IsNullOrEmpty(webProxy.NoProxyString)) { ContainerEnvironmentVariables.TryAdd("NO_PROXY", webProxy.NoProxyString); ContainerEnvironmentVariables.TryAdd("no_proxy", webProxy.NoProxyString); } }
public void WebProxyFromEnvironmentVariablesInvalidString() { try { Environment.SetEnvironmentVariable("http_proxy", "127.0.0.1:7777"); Environment.SetEnvironmentVariable("https_proxy", "127.0.0.1"); var proxy = new RunnerWebProxy(); Assert.Null(proxy.HttpProxyAddress); Assert.Null(proxy.HttpProxyUsername); Assert.Null(proxy.HttpProxyPassword); Assert.Null(proxy.HttpsProxyAddress); Assert.Null(proxy.HttpsProxyUsername); Assert.Null(proxy.HttpsProxyPassword); Assert.Equal(0, proxy.NoProxyList.Count); } finally { CleanProxyEnv(); } }