From 7db62c96d4b4d587de75e14036fe8fc50da4381f Mon Sep 17 00:00:00 2001 From: Krzysztof Nozderko Date: Wed, 13 Dec 2023 12:47:58 +0100 Subject: [PATCH 1/2] Fix usage of insecure mode in connection parameters --- .../UnitTests/Session/SFHttpClientPropertiesTest.cs | 2 +- Snowflake.Data/Core/Session/SFSessionHttpClientProperties.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs b/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs index ea6deb5ca..2eba8fd49 100644 --- a/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs +++ b/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs @@ -79,7 +79,7 @@ public void ShouldBuildHttpClientConfig() var config = properties.BuildHttpClientConfig(); // then - Assert.AreEqual(properties.insecureMode, config.CrlCheckEnabled); + Assert.AreEqual(!properties.insecureMode, config.CrlCheckEnabled); Assert.AreEqual(properties.proxyProperties.proxyHost, config.ProxyHost); Assert.AreEqual(properties.proxyProperties.proxyPort, config.ProxyPort); Assert.AreEqual(properties.proxyProperties.proxyUser, config.ProxyUser); diff --git a/Snowflake.Data/Core/Session/SFSessionHttpClientProperties.cs b/Snowflake.Data/Core/Session/SFSessionHttpClientProperties.cs index b7466a362..f129de25a 100644 --- a/Snowflake.Data/Core/Session/SFSessionHttpClientProperties.cs +++ b/Snowflake.Data/Core/Session/SFSessionHttpClientProperties.cs @@ -75,7 +75,7 @@ internal TimeSpan TimeoutDuration() internal HttpClientConfig BuildHttpClientConfig() { return new HttpClientConfig( - insecureMode, + !insecureMode, proxyProperties.proxyHost, proxyProperties.proxyPort, proxyProperties.proxyUser, From 659e8b7f4d8d55b4d8ae358aa7bca45f709327c6 Mon Sep 17 00:00:00 2001 From: Krzysztof Nozderko Date: Fri, 15 Dec 2023 12:27:41 +0100 Subject: [PATCH 2/2] More tests --- .../Session/SFHttpClientPropertiesTest.cs | 69 ++++++++++++------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs b/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs index 2eba8fd49..72421f588 100644 --- a/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs +++ b/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs @@ -15,11 +15,11 @@ namespace Snowflake.Data.Tests.UnitTests.Session public class SFHttpClientPropertiesTest { [Test] - public void ShouldConvertToMapOnly2Properties( + public void TestConvertToMapOnly2Properties( [Values(true, false)] bool validateDefaultParameters, [Values(true, false)] bool clientSessionKeepAlive) { - // given + // arrange var proxyProperties = new SFSessionHttpClientProxyProperties() { proxyHost = "localhost", @@ -41,19 +41,52 @@ public void ShouldConvertToMapOnly2Properties( proxyProperties = proxyProperties }; - // when + // act var parameterMap = properties.ToParameterMap(); - // then + // assert Assert.AreEqual(2, parameterMap.Count); Assert.AreEqual(validateDefaultParameters, parameterMap[SFSessionParameter.CLIENT_VALIDATE_DEFAULT_PARAMETERS]); Assert.AreEqual(clientSessionKeepAlive, parameterMap[SFSessionParameter.CLIENT_SESSION_KEEP_ALIVE]); } [Test] - public void ShouldBuildHttpClientConfig() + public void TestBuildHttpClientConfig() + { + // arrange + var properties = RandomSFSessionHttpClientProperties(); + + // act + var config = properties.BuildHttpClientConfig(); + + // assert + Assert.AreEqual(!properties.insecureMode, config.CrlCheckEnabled); + Assert.AreEqual(properties.proxyProperties.proxyHost, config.ProxyHost); + Assert.AreEqual(properties.proxyProperties.proxyPort, config.ProxyPort); + Assert.AreEqual(properties.proxyProperties.proxyUser, config.ProxyUser); + Assert.AreEqual(properties.proxyProperties.proxyPassword, config.ProxyPassword); + Assert.AreEqual(properties.proxyProperties.nonProxyHosts, config.NoProxyList); + Assert.AreEqual(properties.disableRetry, config.DisableRetry); + Assert.AreEqual(properties.forceRetryOn404, config.ForceRetryOn404); + Assert.AreEqual(properties.maxHttpRetries, config.MaxHttpRetries); + } + + [Test] + public void TestCrlCheckEnabledToBeOppositeInsecureMode([Values] bool insecureMode) + { + // arrange + var properties = RandomSFSessionHttpClientProperties(); + properties.insecureMode = insecureMode; + + // act + var config = properties.BuildHttpClientConfig(); + + // assert + Assert.AreEqual(!insecureMode, config.CrlCheckEnabled); + } + + private SFSessionHttpClientProperties RandomSFSessionHttpClientProperties() { - // given var proxyProperties = new SFSessionHttpClientProxyProperties() { proxyHost = TestDataGenarator.NextAlphaNumeric(), @@ -62,7 +95,7 @@ public void ShouldBuildHttpClientConfig() proxyPassword = TestDataGenarator.NextAlphaNumeric(), proxyUser = TestDataGenarator.NextAlphaNumeric() }; - var properties = new SFSessionHttpClientProperties() + return new SFSessionHttpClientProperties() { validateDefaultParameters = TestDataGenarator.NextBool(), clientSessionKeepAlive = TestDataGenarator.NextBool(), @@ -74,26 +107,12 @@ public void ShouldBuildHttpClientConfig() maxHttpRetries = TestDataGenarator.NextInt(0, 15), proxyProperties = proxyProperties }; - - // when - var config = properties.BuildHttpClientConfig(); - - // then - Assert.AreEqual(!properties.insecureMode, config.CrlCheckEnabled); - Assert.AreEqual(properties.proxyProperties.proxyHost, config.ProxyHost); - Assert.AreEqual(properties.proxyProperties.proxyPort, config.ProxyPort); - Assert.AreEqual(properties.proxyProperties.proxyUser, config.ProxyUser); - Assert.AreEqual(properties.proxyProperties.proxyPassword, config.ProxyPassword); - Assert.AreEqual(properties.proxyProperties.nonProxyHosts, config.NoProxyList); - Assert.AreEqual(properties.disableRetry, config.DisableRetry); - Assert.AreEqual(properties.forceRetryOn404, config.ForceRetryOn404); - Assert.AreEqual(properties.maxHttpRetries, config.MaxHttpRetries); } [Test, TestCaseSource(nameof(PropertiesProvider))] - public void ShouldExtractProperties(PropertiesTestCase testCase) + public void TestExtractProperties(PropertiesTestCase testCase) { - // given + // arrange var proxyExtractorMock = new Moq.Mock(); var extractor = new SFSessionHttpClientProperties.Extractor(proxyExtractorMock.Object); var properties = SFSessionProperties.parseConnectionString(testCase.conectionString, null); @@ -102,11 +121,11 @@ public void ShouldExtractProperties(PropertiesTestCase testCase) .Setup(e => e.ExtractProperties(properties)) .Returns(proxyProperties); - // when + // act var extractedProperties = extractor.ExtractProperties(properties); extractedProperties.CheckPropertiesAreValid(); - // then + // assert Assert.AreEqual(testCase.expectedProperties.validateDefaultParameters, extractedProperties.validateDefaultParameters); Assert.AreEqual(testCase.expectedProperties.clientSessionKeepAlive, extractedProperties.clientSessionKeepAlive); Assert.AreEqual(testCase.expectedProperties.timeoutInSec, extractedProperties.timeoutInSec);