From a715a99cf90abf92c964d9d7086784ab3592147e Mon Sep 17 00:00:00 2001 From: Brad Culberson Date: Thu, 14 Dec 2023 10:41:10 -0700 Subject: [PATCH] fix dns names with underscore --- .../UnitTests/SFSessionPropertyTest.cs | 31 ++++++++++++++++++- .../Core/Session/SFSessionProperty.cs | 3 +- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs b/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs index cd72bffce..b1f40078f 100644 --- a/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs @@ -305,6 +305,34 @@ public static IEnumerable ConnectionStringTestCases() { SFSessionProperty.DISABLEQUERYCONTEXTCACHE, defDisableQueryContextCache } } }; + var underscoredAccount = $"prefix_{defAccount}"; + var testCaseUnderscoredAccountName = new TestCase() + { + ConnectionString = $"ACCOUNT={underscoredAccount};USER={defUser};PASSWORD={defPassword};", + ExpectedProperties = new SFSessionProperties() + { + { SFSessionProperty.ACCOUNT, underscoredAccount}, + { SFSessionProperty.USER, defUser }, + { SFSessionProperty.HOST, $"prefix-{underscoredAccount}.snowflakecomputing.com" }, + { 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 } + } + }; return new TestCase[] { simpleTestCase, @@ -314,7 +342,8 @@ public static IEnumerable ConnectionStringTestCases() testCaseWithFileTransferMaxBytesInMemory, testCaseWithIncludeRetryReason, testCaseWithDisableQueryContextCache, - testCaseComplicatedAccountName + testCaseComplicatedAccountName, + testCaseUnderscoredAccountName }; } diff --git a/Snowflake.Data/Core/Session/SFSessionProperty.cs b/Snowflake.Data/Core/Session/SFSessionProperty.cs index b07015a88..35b295881 100755 --- a/Snowflake.Data/Core/Session/SFSessionProperty.cs +++ b/Snowflake.Data/Core/Session/SFSessionProperty.cs @@ -260,7 +260,8 @@ internal static SFSessionProperties parseConnectionString(String connectionStrin if (!properties.ContainsKey(SFSessionProperty.HOST) || (0 == properties[SFSessionProperty.HOST].Length)) { - string hostName = String.Format("{0}.snowflakecomputing.com", properties[SFSessionProperty.ACCOUNT]); + string compliantAccountName = properties[SFSessionProperty.ACCOUNT].Replace('_','-'); + string hostName = String.Format("{0}.snowflakecomputing.com", compliantAccountName); // Remove in case it's here but empty properties.Remove(SFSessionProperty.HOST); properties.Add(SFSessionProperty.HOST, hostName);