diff --git a/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs b/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs index 701d61d41..27dd5f645 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.USER]); + } + 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)