public void HttpProxy_CredentialParsing_Basic() { RemoteExecutor.Invoke(() => { IWebProxy p; Environment.SetEnvironmentVariable("all_proxy", "http://*****:*****@1.1.1.1:3000"); Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); Assert.NotNull(p.Credentials); // Use user only without password. Environment.SetEnvironmentVariable("all_proxy", "http://[email protected]:3000"); Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); Assert.NotNull(p.Credentials); // Use different user for http and https Environment.SetEnvironmentVariable("https_proxy", "http://*****:*****@1.1.1.1:3000"); Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); Uri u = p.GetProxy(fooHttp); Assert.NotNull(p.Credentials.GetCredential(u, "Basic")); u = p.GetProxy(fooHttps); Assert.NotNull(p.Credentials.GetCredential(u, "Basic")); // This should not match Proxy Uri Assert.Null(p.Credentials.GetCredential(fooHttp, "Basic")); Assert.Null(p.Credentials.GetCredential(null, null)); }).Dispose(); }
public void HttpProxy_CredentialParsing_Basic() { Environment.SetEnvironmentVariable("all_proxy", "http://*****:*****@1.1.1.1:3000"); Assert.True(HttpEnvironmentProxy.TryCreate(out IWebProxy p)); Assert.NotNull(p); Assert.NotNull(p.Credentials); // Use user only without password. Environment.SetEnvironmentVariable("all_proxy", "http://[email protected]:3000"); Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); Assert.NotNull(p.Credentials); // Use different user for http and https Environment.SetEnvironmentVariable("https_proxy", "http://*****:*****@1.1.1.1:3000"); Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); Uri u = p.GetProxy(s_fooHttp); Assert.NotNull(p.Credentials.GetCredential(u, "Basic")); u = p.GetProxy(s_fooHttps); Assert.NotNull(p.Credentials.GetCredential(u, "Basic")); // This should not match Proxy Uri Assert.Null(p.Credentials.GetCredential(s_fooHttp, "Basic")); Assert.Null(p.Credentials.GetCredential(null, null)); }
public void HttpProxy_EnvironmentProxy_Loaded() { IWebProxy p; Uri u; // It should not return object if there are no variables set. Assert.False(HttpEnvironmentProxy.TryCreate(out p)); Environment.SetEnvironmentVariable("all_proxy", "http://1.1.1.1:3000"); Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); Assert.Null(p.Credentials); u = p.GetProxy(fooHttp); Assert.True(u != null && u.Host == "1.1.1.1"); u = p.GetProxy(fooHttps); Assert.True(u != null && u.Host == "1.1.1.1"); Environment.SetEnvironmentVariable("http_proxy", "http://1.1.1.2:3001"); Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); // Protocol specific variables should take precedence over all_ // and https should still use all_proxy. u = p.GetProxy(fooHttp); Assert.True(u != null && u.Host == "1.1.1.2" && u.Port == 3001); u = p.GetProxy(fooHttps); Assert.True(u != null && u.Host == "1.1.1.1" && u.Port == 3000); // Set https to invalid strings and use only IP & port for http. Environment.SetEnvironmentVariable("http_proxy", "1.1.1.3:3003"); Environment.SetEnvironmentVariable("https_proxy", "ab!cd"); Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); u = p.GetProxy(fooHttp); Assert.True(u != null && u.Host == "1.1.1.3" && u.Port == 3003); u = p.GetProxy(fooHttps); Assert.True(u != null && u.Host == "1.1.1.1" && u.Port == 3000); // Try valid URI with unsupported protocol. It will be ignored // to mimic curl behavior. Environment.SetEnvironmentVariable("https_proxy", "socks5://1.1.1.4:3004"); Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); u = p.GetProxy(fooHttps); Assert.True(u != null && u.Host == "1.1.1.1" && u.Port == 3000); // Set https to valid URI but different from http. Environment.SetEnvironmentVariable("https_proxy", "http://1.1.1.5:3005"); Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); u = p.GetProxy(fooHttp); Assert.True(u != null && u.Host == "1.1.1.3" && u.Port == 3003); u = p.GetProxy(fooHttps); Assert.True(u != null && u.Host == "1.1.1.5" && u.Port == 3005); }
public void HttpProxy_Exceptions_Match() { IWebProxy p; Environment.SetEnvironmentVariable("no_proxy", ".test.com,, foo.com"); Environment.SetEnvironmentVariable("all_proxy", "http://*****:*****@1.1.1.1:3000"); Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); Assert.True(p.IsBypassed(fooHttp)); Assert.True(p.IsBypassed(fooHttps)); Assert.True(p.IsBypassed(new Uri("http://test.com"))); Assert.False(p.IsBypassed(new Uri("http://1test.com"))); Assert.True(p.IsBypassed(new Uri("http://www.test.com"))); }
public void HttpProxy_Exceptions_Match() { RemoteExecutor.Invoke(() => { IWebProxy p; Environment.SetEnvironmentVariable("no_proxy", ".test.com,, foo.com"); Environment.SetEnvironmentVariable("all_proxy", "http://*****:*****@1.1.1.1:3000"); Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); Assert.True(p.IsBypassed(fooHttp)); Assert.True(p.IsBypassed(fooHttps)); Assert.True(p.IsBypassed(new Uri("http://test.com"))); Assert.False(p.IsBypassed(new Uri("http://1test.com"))); Assert.True(p.IsBypassed(new Uri("http://www.test.com"))); }).Dispose(); }
public void HttpProxy_CredentialParsing_DefaultCredentials() { RemoteExecutor.Invoke(() => { IWebProxy p; Environment.SetEnvironmentVariable("all_proxy", "http://:@1.1.1.1:3000"); Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); Assert.Equal(CredentialCache.DefaultCredentials, p.Credentials.GetCredential(p.GetProxy(fooHttp), "")); Assert.Equal(CredentialCache.DefaultCredentials, p.Credentials.GetCredential(p.GetProxy(fooHttps), "")); Environment.SetEnvironmentVariable("http_proxy", "http://:@[::1]:80"); Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); Assert.Equal(CredentialCache.DefaultCredentials, p.Credentials.GetCredential(p.GetProxy(fooHttp), "")); }).Dispose(); }
public void HttpProxy_Uri_Parsing(string input, string host, string port, string user, string password) { Environment.SetEnvironmentVariable("all_proxy", input); IWebProxy p; Uri u; Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); u = p.GetProxy(fooHttp); Assert.AreEqual(host, u.Host); Assert.AreEqual(Convert.ToInt32(port), u.Port); if (user != null) { NetworkCredential nc = p.Credentials.GetCredential(u, "Basic"); Assert.NotNull(nc); Assert.AreEqual(user, nc.UserName); Assert.AreEqual(password, nc.Password); } }
public void HttpProxy_Uri_Parsing(string _input, string _host, string _port, string _user, string _password) { RemoteExecutor.Invoke((input, host, port, user, password) => { // Remote exec does not allow to pass null at this moment. if (user == "null") { user = null; } if (password == "null") { password = null; } Environment.SetEnvironmentVariable("all_proxy", input); IWebProxy p; Uri u; Assert.True(HttpEnvironmentProxy.TryCreate(out p)); Assert.NotNull(p); u = p.GetProxy(fooHttp); Assert.Equal(host, u.Host); Assert.Equal(Convert.ToInt32(port), u.Port); if (user != null) { NetworkCredential nc = p.Credentials.GetCredential(u, "Basic"); Assert.NotNull(nc); Assert.Equal(user, nc.UserName); Assert.Equal(password, nc.Password); } return(RemoteExecutor.SuccessExitCode); }, _input, _host, _port, _user ?? "null", _password ?? "null").Dispose(); }