From 98ac660660a3422babeec7118823b9520feb27a8 Mon Sep 17 00:00:00 2001 From: Juan Martinez Ramirez Date: Fri, 15 Mar 2024 11:09:42 -0600 Subject: [PATCH 1/6] Fixed validation to special scenarios for warehouse property to allow scaped quotes on value. Refactoring of code for special cases. --- .../IntegrationTests/SFConnectionIT.cs | 4 +- .../UnitTests/SFSessionPropertyTest.cs | 43 +++++++++- .../Session/SFHttpClientPropertiesTest.cs | 2 +- .../SFHttpClientProxyPropertiesTest.cs | 2 +- Snowflake.Data/Core/Session/SFSession.cs | 2 +- .../Core/Session/SFSessionProperty.cs | 86 +++++++++++-------- 6 files changed, 95 insertions(+), 44 deletions(-) diff --git a/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs index 816e064b3..8d69fe606 100644 --- a/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs @@ -1652,7 +1652,7 @@ public void testMulitpleConnectionInParallel() } [Test] - [Ignore("Ignore this test, please test this manual with breakpoint at SFSessionProperty::parseConnectionString() to verify")] + [Ignore("Ignore this test, please test this manual with breakpoint at SFSessionProperty::ParseConnectionString() to verify")] public void TestEscapeChar() { using (IDbConnection conn = new SnowflakeDbConnection()) @@ -1679,7 +1679,7 @@ public void TestEscapeChar() } [Test] - [Ignore("Ignore this test, please test this manual with breakpoint at SFSessionProperty::parseConnectionString() to verify")] + [Ignore("Ignore this test, please test this manual with breakpoint at SFSessionProperty::ParseConnectionString() to verify")] public void TestEscapeChar1() { using (IDbConnection conn = new SnowflakeDbConnection()) diff --git a/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs b/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs index 694af9b5e..9483dfccd 100644 --- a/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs @@ -18,7 +18,7 @@ class SFSessionPropertyTest public void TestThatPropertiesAreParsed(TestCase testcase) { // act - var properties = SFSessionProperties.parseConnectionString( + var properties = SFSessionProperties.ParseConnectionString( testcase.ConnectionString, testcase.SecurePassword); @@ -40,7 +40,7 @@ public void TestValidateCorrectAccountNames(string accountName, string expectedA var connectionString = $"ACCOUNT={accountName};USER=test;PASSWORD=test;"; // act - var properties = SFSessionProperties.parseConnectionString(connectionString, null); + var properties = SFSessionProperties.ParseConnectionString(connectionString, null); // assert Assert.AreEqual(expectedAccountName, properties[SFSessionProperty.ACCOUNT]); @@ -60,7 +60,7 @@ public void TestThatItFailsForWrongConnectionParameter(string connectionString, { // act var exception = Assert.Throws( - () => SFSessionProperties.parseConnectionString(connectionString, null) + () => SFSessionProperties.ParseConnectionString(connectionString, null) ); // assert @@ -75,7 +75,7 @@ public void TestThatItFailsIfNoAccountSpecified(string connectionString) { // act var exception = Assert.Throws( - () => SFSessionProperties.parseConnectionString(connectionString, null) + () => SFSessionProperties.ParseConnectionString(connectionString, null) ); // assert @@ -134,6 +134,40 @@ public static IEnumerable ConnectionStringTestCases() { SFSessionProperty.ALLOWUNDERSCORESINHOST, defAllowUnderscoresInHost } } }; + + var warehouseWithSpaces = "\"warehouse test\""; + var dbWithQuotes = "\"testdb\""; + var testCaseWithWrappedValuesWithQuotesAndAllowSpaces = new TestCase() + { + ConnectionString = $"ACCOUNT={defAccount};USER={defUser};PASSWORD={defPassword};WAREHOUSE={warehouseWithSpaces};DB={dbWithQuotes}", + ExpectedProperties = new SFSessionProperties() + { + { SFSessionProperty.ACCOUNT, defAccount }, + { SFSessionProperty.USER, defUser }, + { SFSessionProperty.HOST, defHost }, + { SFSessionProperty.WAREHOUSE, warehouseWithSpaces }, + { SFSessionProperty.DB, dbWithQuotes }, + { SFSessionProperty.AUTHENTICATOR, defAuthenticator }, + { SFSessionProperty.SCHEME, defScheme }, + { SFSessionProperty.CONNECTION_TIMEOUT, defConnectionTimeout }, + { SFSessionProperty.PASSWORD, defPassword }, + { SFSessionProperty.PORT, defPort }, + { SFSessionProperty.VALIDATE_DEFAULT_PARAMETERS, "true" }, + { SFSessionProperty.USEPROXY, "false" }, + { SFSessionProperty.INSECUREMODE, "false" }, + { SFSessionProperty.DISABLERETRY, "false" }, + { SFSessionProperty.FORCERETRYON404, "false" }, + { SFSessionProperty.CLIENT_SESSION_KEEP_ALIVE, "false" }, + { SFSessionProperty.FORCEPARSEERROR, "false" }, + { SFSessionProperty.BROWSER_RESPONSE_TIMEOUT, defBrowserResponseTime }, + { SFSessionProperty.RETRY_TIMEOUT, defRetryTimeout }, + { SFSessionProperty.MAXHTTPRETRIES, defMaxHttpRetries }, + { SFSessionProperty.INCLUDERETRYREASON, defIncludeRetryReason }, + { SFSessionProperty.DISABLEQUERYCONTEXTCACHE, defDisableQueryContextCache }, + { SFSessionProperty.DISABLE_CONSOLE_LOGIN, defDisableConsoleLogin }, + { SFSessionProperty.ALLOWUNDERSCORESINHOST, defAllowUnderscoresInHost } + } + }; var testCaseWithBrowserResponseTimeout = new TestCase() { ConnectionString = $"ACCOUNT={defAccount};BROWSER_RESPONSE_TIMEOUT=180;authenticator=externalbrowser", @@ -438,6 +472,7 @@ public static IEnumerable ConnectionStringTestCases() return new TestCase[] { simpleTestCase, + testCaseWithWrappedValuesWithQuotesAndAllowSpaces, testCaseWithBrowserResponseTimeout, testCaseWithProxySettings, testCaseThatDefaultForUseProxyIsFalse, diff --git a/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs b/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs index 72421f588..617e3d429 100644 --- a/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs +++ b/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientPropertiesTest.cs @@ -115,7 +115,7 @@ public void TestExtractProperties(PropertiesTestCase testCase) // arrange var proxyExtractorMock = new Moq.Mock(); var extractor = new SFSessionHttpClientProperties.Extractor(proxyExtractorMock.Object); - var properties = SFSessionProperties.parseConnectionString(testCase.conectionString, null); + var properties = SFSessionProperties.ParseConnectionString(testCase.conectionString, null); var proxyProperties = new SFSessionHttpClientProxyProperties(); proxyExtractorMock .Setup(e => e.ExtractProperties(properties)) diff --git a/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientProxyPropertiesTest.cs b/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientProxyPropertiesTest.cs index a39d9bede..53941cc27 100644 --- a/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientProxyPropertiesTest.cs +++ b/Snowflake.Data.Tests/UnitTests/Session/SFHttpClientProxyPropertiesTest.cs @@ -17,7 +17,7 @@ public void ShouldExtractProxyProperties(ProxyPropertiesTestCase testCase) { // given var extractor = new SFSessionHttpClientProxyProperties.Extractor(); - var properties = SFSessionProperties.parseConnectionString(testCase.conectionString, null); + var properties = SFSessionProperties.ParseConnectionString(testCase.conectionString, null); // when var proxyProperties = extractor.ExtractProperties(properties); diff --git a/Snowflake.Data/Core/Session/SFSession.cs b/Snowflake.Data/Core/Session/SFSession.cs index e39370f19..8f56fdda4 100755 --- a/Snowflake.Data/Core/Session/SFSession.cs +++ b/Snowflake.Data/Core/Session/SFSession.cs @@ -152,7 +152,7 @@ internal SFSession( { _easyLoggingStarter = easyLoggingStarter; connStr = connectionString; - properties = SFSessionProperties.parseConnectionString(connectionString, password); + properties = SFSessionProperties.ParseConnectionString(connectionString, password); _disableQueryContextCache = bool.Parse(properties[SFSessionProperty.DISABLEQUERYCONTEXTCACHE]); _disableConsoleLogin = bool.Parse(properties[SFSessionProperty.DISABLE_CONSOLE_LOGIN]); ValidateApplicationName(properties); diff --git a/Snowflake.Data/Core/Session/SFSessionProperty.cs b/Snowflake.Data/Core/Session/SFSessionProperty.cs index 4311fe88f..bb874fcee 100644 --- a/Snowflake.Data/Core/Session/SFSessionProperty.cs +++ b/Snowflake.Data/Core/Session/SFSessionProperty.cs @@ -160,10 +160,10 @@ public override int GetHashCode() return base.GetHashCode(); } - internal static SFSessionProperties parseConnectionString(String connectionString, SecureString password) + internal static SFSessionProperties ParseConnectionString(string connectionString, SecureString password) { logger.Info("Start parsing connection string."); - DbConnectionStringBuilder builder = new DbConnectionStringBuilder(); + var builder = new DbConnectionStringBuilder(); try { builder.ConnectionString = connectionString; @@ -175,14 +175,14 @@ internal static SFSessionProperties parseConnectionString(String connectionStrin SFError.INVALID_CONNECTION_STRING, e.Message); } - SFSessionProperties properties = new SFSessionProperties(); + var properties = new SFSessionProperties(); - string[] keys = new string[builder.Keys.Count]; - string[] values = new string[builder.Values.Count]; + var keys = new string[builder.Keys.Count]; + var values = new string[builder.Values.Count]; builder.Keys.CopyTo(keys, 0); builder.Values.CopyTo(values,0); - for(int i=0; i 0) - { - string[] tokens = keyVal.Split(new string[] { "=" }, StringSplitOptions.None); - if(tokens[0].ToUpper() == "DB" || tokens[0].ToUpper() == "SCHEMA" || - tokens[0].ToLower() == "WAREHOUSE" || tokens[0].ToUpper() == "ROLE") - { - if (tokens.Length == 2) - { - SFSessionProperty p = (SFSessionProperty)Enum.Parse( - typeof(SFSessionProperty), tokens[0].ToUpper()); - properties[p]= tokens[1]; - } - } - if(tokens[0].ToUpper() == "USER" || tokens[0].ToUpper() == "PASSWORD") - { - SFSessionProperty p = (SFSessionProperty)Enum.Parse( - typeof(SFSessionProperty), tokens[0].ToUpper()); - if (!properties.ContainsKey(p)) - { - properties.Add(p, ""); - } - } - } - } + + ProcessPropertySpecialCases(connectionString, properties); bool useProxy = false; if (properties.ContainsKey(SFSessionProperty.USEPROXY)) @@ -292,6 +265,49 @@ internal static SFSessionProperties parseConnectionString(String connectionStrin return properties; } + private static void ProcessPropertySpecialCases(string connectionString, SFSessionProperties properties) + { + var propertyEntry = connectionString.Split(';'); + foreach(var keyVal in propertyEntry) + { + if(keyVal.Length > 0) + { + var tokens = keyVal.Split(new string[] { "=" }, StringSplitOptions.None); + var propertyName = tokens[0].ToUpper(); + switch (propertyName) + { + case "DB": + case "SCHEMA": + case "WAREHOUSE": + case "ROLE": + { + if (tokens.Length == 2) + { + var p = (SFSessionProperty)Enum.Parse( + typeof(SFSessionProperty), propertyName); + properties[p]= tokens[1]; + } + + break; + } + case "USER": + case "PASSWORD": + { + + var p = (SFSessionProperty)Enum.Parse( + typeof(SFSessionProperty), propertyName); + if (!properties.ContainsKey(p)) + { + properties.Add(p, ""); + } + + break; + } + } + } + } + } + private static void ValidateAccountDomain(SFSessionProperties properties) { var account = properties[SFSessionProperty.ACCOUNT]; From c0ac775c92dfb0d0b9d691a353e6e0e1ec7b5079 Mon Sep 17 00:00:00 2001 From: Juan Martinez Ramirez Date: Mon, 18 Mar 2024 10:37:03 -0600 Subject: [PATCH 2/6] Applying PR suggestions --- Snowflake.Data/Core/Session/SFSessionProperty.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Snowflake.Data/Core/Session/SFSessionProperty.cs b/Snowflake.Data/Core/Session/SFSessionProperty.cs index bb874fcee..ad1099ee0 100644 --- a/Snowflake.Data/Core/Session/SFSessionProperty.cs +++ b/Snowflake.Data/Core/Session/SFSessionProperty.cs @@ -283,9 +283,9 @@ private static void ProcessPropertySpecialCases(string connectionString, SFSessi { if (tokens.Length == 2) { - var p = (SFSessionProperty)Enum.Parse( + var sessionProperty = (SFSessionProperty)Enum.Parse( typeof(SFSessionProperty), propertyName); - properties[p]= tokens[1]; + properties[sessionProperty]= tokens[1]; } break; @@ -293,14 +293,9 @@ private static void ProcessPropertySpecialCases(string connectionString, SFSessi case "USER": case "PASSWORD": { - - var p = (SFSessionProperty)Enum.Parse( + var sessionProperty = (SFSessionProperty)Enum.Parse( typeof(SFSessionProperty), propertyName); - if (!properties.ContainsKey(p)) - { - properties.Add(p, ""); - } - + properties.TryAdd(sessionProperty, string.Empty); break; } } From 77c3a88f3cc14e7e2795be9a484c10b4dd584a42 Mon Sep 17 00:00:00 2001 From: Juan Martinez Ramirez Date: Mon, 18 Mar 2024 10:47:47 -0600 Subject: [PATCH 3/6] Added code coverage to refactored code. --- .../UnitTests/SFSessionPropertyTest.cs | 33 +++++++++++++++++++ .../Core/Session/SFSessionProperty.cs | 7 +++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs b/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs index 9483dfccd..9106138d7 100644 --- a/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs @@ -11,6 +11,8 @@ namespace Snowflake.Data.Tests.UnitTests { + using System; + class SFSessionPropertyTest { @@ -135,6 +137,36 @@ public static IEnumerable ConnectionStringTestCases() } }; + var testCaseWithEmptyUserAndPassword = new TestCase() + { + ConnectionString = $"ACCOUNT={defAccount};USER=;PASSWORD=", + ExpectedProperties = new SFSessionProperties() + { + { SFSessionProperty.ACCOUNT, defAccount }, + { SFSessionProperty.USER, string.Empty }, + { SFSessionProperty.HOST, defHost }, + { SFSessionProperty.AUTHENTICATOR, defAuthenticator }, + { SFSessionProperty.SCHEME, defScheme }, + { SFSessionProperty.CONNECTION_TIMEOUT, defConnectionTimeout }, + { SFSessionProperty.PASSWORD, string.Empty }, + { SFSessionProperty.PORT, defPort }, + { SFSessionProperty.VALIDATE_DEFAULT_PARAMETERS, "true" }, + { SFSessionProperty.USEPROXY, "false" }, + { SFSessionProperty.INSECUREMODE, "false" }, + { SFSessionProperty.DISABLERETRY, "false" }, + { SFSessionProperty.FORCERETRYON404, "false" }, + { SFSessionProperty.CLIENT_SESSION_KEEP_ALIVE, "false" }, + { SFSessionProperty.FORCEPARSEERROR, "false" }, + { SFSessionProperty.BROWSER_RESPONSE_TIMEOUT, defBrowserResponseTime }, + { SFSessionProperty.RETRY_TIMEOUT, defRetryTimeout }, + { SFSessionProperty.MAXHTTPRETRIES, defMaxHttpRetries }, + { SFSessionProperty.INCLUDERETRYREASON, defIncludeRetryReason }, + { SFSessionProperty.DISABLEQUERYCONTEXTCACHE, defDisableQueryContextCache }, + { SFSessionProperty.DISABLE_CONSOLE_LOGIN, defDisableConsoleLogin }, + { SFSessionProperty.ALLOWUNDERSCORESINHOST, defAllowUnderscoresInHost } + } + }; + var warehouseWithSpaces = "\"warehouse test\""; var dbWithQuotes = "\"testdb\""; var testCaseWithWrappedValuesWithQuotesAndAllowSpaces = new TestCase() @@ -472,6 +504,7 @@ public static IEnumerable ConnectionStringTestCases() return new TestCase[] { simpleTestCase, + testCaseWithEmptyUserAndPassword, testCaseWithWrappedValuesWithQuotesAndAllowSpaces, testCaseWithBrowserResponseTimeout, testCaseWithProxySettings, diff --git a/Snowflake.Data/Core/Session/SFSessionProperty.cs b/Snowflake.Data/Core/Session/SFSessionProperty.cs index ad1099ee0..a6c6d24fb 100644 --- a/Snowflake.Data/Core/Session/SFSessionProperty.cs +++ b/Snowflake.Data/Core/Session/SFSessionProperty.cs @@ -293,9 +293,14 @@ private static void ProcessPropertySpecialCases(string connectionString, SFSessi case "USER": case "PASSWORD": { + var sessionProperty = (SFSessionProperty)Enum.Parse( typeof(SFSessionProperty), propertyName); - properties.TryAdd(sessionProperty, string.Empty); + if (!properties.ContainsKey(sessionProperty)) + { + properties.Add(sessionProperty, ""); + } + break; } } From 49eb78c99c83be5973370de361246d194739bf08 Mon Sep 17 00:00:00 2001 From: Juan Martinez Ramirez Date: Mon, 18 Mar 2024 11:38:33 -0600 Subject: [PATCH 4/6] Removed non-required using --- Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs b/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs index 9106138d7..17274f05a 100644 --- a/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs @@ -11,7 +11,6 @@ namespace Snowflake.Data.Tests.UnitTests { - using System; class SFSessionPropertyTest { From 1f1feebb86a4142b793bfcd2b451c37c954f9b86 Mon Sep 17 00:00:00 2001 From: Juan Martinez Ramirez Date: Mon, 18 Mar 2024 14:27:25 -0600 Subject: [PATCH 5/6] Added verification for other object properties --- Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs b/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs index 17274f05a..701d61d41 100644 --- a/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs @@ -168,9 +168,11 @@ public static IEnumerable ConnectionStringTestCases() var warehouseWithSpaces = "\"warehouse test\""; var dbWithQuotes = "\"testdb\""; + var schemaWithQuotes = "\"quotedSchema\""; + var roleWithQuotes = "\"userrole\""; var testCaseWithWrappedValuesWithQuotesAndAllowSpaces = new TestCase() { - ConnectionString = $"ACCOUNT={defAccount};USER={defUser};PASSWORD={defPassword};WAREHOUSE={warehouseWithSpaces};DB={dbWithQuotes}", + ConnectionString = $"ACCOUNT={defAccount};USER={defUser};PASSWORD={defPassword};WAREHOUSE={warehouseWithSpaces};DB={dbWithQuotes};SCHEMA={schemaWithQuotes};ROLE={roleWithQuotes}", ExpectedProperties = new SFSessionProperties() { { SFSessionProperty.ACCOUNT, defAccount }, @@ -178,6 +180,8 @@ public static IEnumerable ConnectionStringTestCases() { SFSessionProperty.HOST, defHost }, { SFSessionProperty.WAREHOUSE, warehouseWithSpaces }, { SFSessionProperty.DB, dbWithQuotes }, + { SFSessionProperty.SCHEMA, schemaWithQuotes }, + { SFSessionProperty.ROLE, roleWithQuotes }, { SFSessionProperty.AUTHENTICATOR, defAuthenticator }, { SFSessionProperty.SCHEME, defScheme }, { SFSessionProperty.CONNECTION_TIMEOUT, defConnectionTimeout }, From d2903b7fbe1faf8d0485418782d2a36a5e9235ef Mon Sep 17 00:00:00 2001 From: Juan Martinez Ramirez Date: Tue, 19 Mar 2024 09:55:46 -0600 Subject: [PATCH 6/6] Move the added test to use a simplified test format. Rename the method to a more meaningful name. --- .../UnitTests/SFSessionPropertyTest.cs | 102 ++++++------------ .../Core/Session/SFSessionProperty.cs | 6 +- 2 files changed, 36 insertions(+), 72 deletions(-) diff --git a/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs b/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs index 701d61d41..4b2e3ec8f 100644 --- a/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs @@ -83,6 +83,39 @@ public void TestThatItFailsIfNoAccountSpecified(string connectionString) Assert.AreEqual(SFError.MISSING_CONNECTION_PROPERTY.GetAttribute().errorCode, exception.ErrorCode); } + + + [Test] + [TestCase("DB", SFSessionProperty.DB, "\"testdb\"")] + [TestCase("SCHEMA", SFSessionProperty.SCHEMA, "\"quotedSchema\"")] + [TestCase("ROLE", SFSessionProperty.ROLE, "\"userrole\"")] + [TestCase("WAREHOUSE", SFSessionProperty.WAREHOUSE, "\"warehouse test\"")] + public void TestValidateSupportEscapedQuotesValuesForObjectProperties(string propertyName, SFSessionProperty sessionProperty, string value) + { + // arrange + var connectionString = $"ACCOUNT=test;{propertyName}={value};USER=test;PASSWORD=test;"; + + // act + var properties = SFSessionProperties.ParseConnectionString(connectionString, null); + + // assert + Assert.AreEqual(value, properties[sessionProperty]); + } + + [Test] + public void TestProcessEmptyUserAndPasswordInConnectionString() + { + // arrange + var connectionString = $"ACCOUNT=test;USER=;PASSWORD=;"; + + // act + var properties = SFSessionProperties.ParseConnectionString(connectionString, null); + + // assert + Assert.AreEqual(string.Empty, properties[SFSessionProperty.USER]); + Assert.AreEqual(string.Empty, properties[SFSessionProperty.PASSWORD]); + } + public static IEnumerable ConnectionStringTestCases() { string defAccount = "testaccount"; @@ -135,74 +168,7 @@ public static IEnumerable ConnectionStringTestCases() { SFSessionProperty.ALLOWUNDERSCORESINHOST, defAllowUnderscoresInHost } } }; - - var testCaseWithEmptyUserAndPassword = new TestCase() - { - ConnectionString = $"ACCOUNT={defAccount};USER=;PASSWORD=", - ExpectedProperties = new SFSessionProperties() - { - { SFSessionProperty.ACCOUNT, defAccount }, - { SFSessionProperty.USER, string.Empty }, - { SFSessionProperty.HOST, defHost }, - { SFSessionProperty.AUTHENTICATOR, defAuthenticator }, - { SFSessionProperty.SCHEME, defScheme }, - { SFSessionProperty.CONNECTION_TIMEOUT, defConnectionTimeout }, - { SFSessionProperty.PASSWORD, string.Empty }, - { SFSessionProperty.PORT, defPort }, - { SFSessionProperty.VALIDATE_DEFAULT_PARAMETERS, "true" }, - { SFSessionProperty.USEPROXY, "false" }, - { SFSessionProperty.INSECUREMODE, "false" }, - { SFSessionProperty.DISABLERETRY, "false" }, - { SFSessionProperty.FORCERETRYON404, "false" }, - { SFSessionProperty.CLIENT_SESSION_KEEP_ALIVE, "false" }, - { SFSessionProperty.FORCEPARSEERROR, "false" }, - { SFSessionProperty.BROWSER_RESPONSE_TIMEOUT, defBrowserResponseTime }, - { SFSessionProperty.RETRY_TIMEOUT, defRetryTimeout }, - { SFSessionProperty.MAXHTTPRETRIES, defMaxHttpRetries }, - { SFSessionProperty.INCLUDERETRYREASON, defIncludeRetryReason }, - { SFSessionProperty.DISABLEQUERYCONTEXTCACHE, defDisableQueryContextCache }, - { SFSessionProperty.DISABLE_CONSOLE_LOGIN, defDisableConsoleLogin }, - { SFSessionProperty.ALLOWUNDERSCORESINHOST, defAllowUnderscoresInHost } - } - }; - var warehouseWithSpaces = "\"warehouse test\""; - var dbWithQuotes = "\"testdb\""; - var schemaWithQuotes = "\"quotedSchema\""; - var roleWithQuotes = "\"userrole\""; - var testCaseWithWrappedValuesWithQuotesAndAllowSpaces = new TestCase() - { - ConnectionString = $"ACCOUNT={defAccount};USER={defUser};PASSWORD={defPassword};WAREHOUSE={warehouseWithSpaces};DB={dbWithQuotes};SCHEMA={schemaWithQuotes};ROLE={roleWithQuotes}", - ExpectedProperties = new SFSessionProperties() - { - { SFSessionProperty.ACCOUNT, defAccount }, - { SFSessionProperty.USER, defUser }, - { SFSessionProperty.HOST, defHost }, - { SFSessionProperty.WAREHOUSE, warehouseWithSpaces }, - { SFSessionProperty.DB, dbWithQuotes }, - { SFSessionProperty.SCHEMA, schemaWithQuotes }, - { SFSessionProperty.ROLE, roleWithQuotes }, - { SFSessionProperty.AUTHENTICATOR, defAuthenticator }, - { SFSessionProperty.SCHEME, defScheme }, - { SFSessionProperty.CONNECTION_TIMEOUT, defConnectionTimeout }, - { SFSessionProperty.PASSWORD, defPassword }, - { SFSessionProperty.PORT, defPort }, - { SFSessionProperty.VALIDATE_DEFAULT_PARAMETERS, "true" }, - { SFSessionProperty.USEPROXY, "false" }, - { SFSessionProperty.INSECUREMODE, "false" }, - { SFSessionProperty.DISABLERETRY, "false" }, - { SFSessionProperty.FORCERETRYON404, "false" }, - { SFSessionProperty.CLIENT_SESSION_KEEP_ALIVE, "false" }, - { SFSessionProperty.FORCEPARSEERROR, "false" }, - { SFSessionProperty.BROWSER_RESPONSE_TIMEOUT, defBrowserResponseTime }, - { SFSessionProperty.RETRY_TIMEOUT, defRetryTimeout }, - { SFSessionProperty.MAXHTTPRETRIES, defMaxHttpRetries }, - { SFSessionProperty.INCLUDERETRYREASON, defIncludeRetryReason }, - { SFSessionProperty.DISABLEQUERYCONTEXTCACHE, defDisableQueryContextCache }, - { SFSessionProperty.DISABLE_CONSOLE_LOGIN, defDisableConsoleLogin }, - { SFSessionProperty.ALLOWUNDERSCORESINHOST, defAllowUnderscoresInHost } - } - }; var testCaseWithBrowserResponseTimeout = new TestCase() { ConnectionString = $"ACCOUNT={defAccount};BROWSER_RESPONSE_TIMEOUT=180;authenticator=externalbrowser", @@ -507,8 +473,6 @@ public static IEnumerable ConnectionStringTestCases() return new TestCase[] { simpleTestCase, - testCaseWithEmptyUserAndPassword, - testCaseWithWrappedValuesWithQuotesAndAllowSpaces, testCaseWithBrowserResponseTimeout, testCaseWithProxySettings, testCaseThatDefaultForUseProxyIsFalse, diff --git a/Snowflake.Data/Core/Session/SFSessionProperty.cs b/Snowflake.Data/Core/Session/SFSessionProperty.cs index a6c6d24fb..6ed45be81 100644 --- a/Snowflake.Data/Core/Session/SFSessionProperty.cs +++ b/Snowflake.Data/Core/Session/SFSessionProperty.cs @@ -196,9 +196,9 @@ internal static SFSessionProperties ParseConnectionString(string connectionStrin } } - ProcessPropertySpecialCases(connectionString, properties); + UpdatePropertiesForSpecialCases(properties, connectionString); - bool useProxy = false; + var useProxy = false; if (properties.ContainsKey(SFSessionProperty.USEPROXY)) { try @@ -265,7 +265,7 @@ internal static SFSessionProperties ParseConnectionString(string connectionStrin return properties; } - private static void ProcessPropertySpecialCases(string connectionString, SFSessionProperties properties) + private static void UpdatePropertiesForSpecialCases(SFSessionProperties properties, string connectionString) { var propertyEntry = connectionString.Split(';'); foreach(var keyVal in propertyEntry)