diff --git a/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs index 32aacdf31..ebdd8cc9b 100644 --- a/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs @@ -1549,16 +1549,21 @@ public void TestInvalidProxySettingFromConnectionString() [TestCase("^nonmatch*{0}$|*")] [TestCase("*a*", "a")] [TestCase("*la*", "la")] - public void TestNonProxyHostShouldBypassProxyServer(string regexHost, string proxyHost = null) + public void TestNonProxyHostShouldBypassProxyServer(string regexHost, string proxyHost = "proxyserverhost") { using (var conn = new SnowflakeDbConnection()) { + // Arrange var host = ResolveHostToUseFromTestConfig(ConnectionString); var nonProxyHosts = string.Format(regexHost, $"{host}"); - var proxyHostForConnection = proxyHost ?? "proxyserverhost"; conn.ConnectionString = - $"{ConnectionString}USEPROXY=true;PROXYHOST={proxyHostForConnection};NONPROXYHOSTS={nonProxyHosts};PROXYPORT=3128;"; + $"{ConnectionString}USEPROXY=true;PROXYHOST={proxyHost};NONPROXYHOSTS={nonProxyHosts};PROXYPORT=3128;"; + + // Act conn.Open(); + + // Assert + // If the connection is open, it indicates that the server proxy was bypassed. Assert.AreEqual(ConnectionState.Open, conn.State); } } @@ -1570,15 +1575,21 @@ public void TestNonProxyHostShouldBypassProxyServer(string regexHost, string pro [TestCase("*a.b")] [TestCase("a", "a")] [TestCase("la", "la")] - public void TestNonProxyHostShouldNotBypassProxyServer(string regexHost, string proxyHost = null) + public void TestNonProxyHostShouldNotBypassProxyServer(string regexHost, string proxyHost = "proxyserverhost") { using (var conn = new SnowflakeDbConnection()) { + // Arrange var nonProxyHosts = string.Format(regexHost, $"{testConfig.host}"); - var proxyHostForConnection = proxyHost ?? "proxyserverhost"; conn.ConnectionString = - $"{ConnectionString}connection_timeout=5;USEPROXY=true;PROXYHOST={proxyHostForConnection};NONPROXYHOSTS={nonProxyHosts};PROXYPORT=3128;"; + $"{ConnectionString}connection_timeout=5;USEPROXY=true;PROXYHOST={proxyHost};NONPROXYHOSTS={nonProxyHosts};PROXYPORT=3128;"; + + // Act/Assert + // If the nonproxyhosts property fails to bypass the server, the proxy will be use but it will return a exception + // because is not configure in the testing environment so the exception is used to verify that was not bypass. var exception = Assert.Throws(() => conn.Open()); + + // Assert s_logger.Debug("Failed opening connection ", exception); Assert.AreEqual(270001, exception.ErrorCode); AssertIsConnectionFailure(exception); @@ -1835,11 +1846,6 @@ public void TestKeepAlive() Assert.Fail(); } } - - private string ResolveHostToUseFromTestConfig(string connectionString) - { - return testConfig.host ?? $"{testConfig.account}.snowflakecomputing.com"; - } } [TestFixture] diff --git a/Snowflake.Data.Tests/SFBaseTest.cs b/Snowflake.Data.Tests/SFBaseTest.cs index 01ae94501..dad45acfc 100755 --- a/Snowflake.Data.Tests/SFBaseTest.cs +++ b/Snowflake.Data.Tests/SFBaseTest.cs @@ -146,6 +146,11 @@ public SFBaseTestAsync() testConfig.password); protected TestConfig testConfig { get; } + + protected string ResolveHostToUseFromTestConfig() + { + return testConfig.host ?? $"{testConfig.account}.snowflakecomputing.com"; + } } [SetUpFixture] diff --git a/Snowflake.Data/Core/HttpUtil.cs b/Snowflake.Data/Core/HttpUtil.cs index 6ed9395ae..531e76fd7 100755 --- a/Snowflake.Data/Core/HttpUtil.cs +++ b/Snowflake.Data/Core/HttpUtil.cs @@ -12,14 +12,11 @@ using System.Collections.Specialized; using System.Web; using System.Security.Authentication; -using System.Runtime.InteropServices; using System.Linq; using Snowflake.Data.Core.Authenticator; namespace Snowflake.Data.Core { - using System.Text.RegularExpressions; - public class HttpClientConfig { public HttpClientConfig(