Skip to content

Commit

Permalink
Move added test to use simplified test format.
Browse files Browse the repository at this point in the history
Rename method to a more meaningful name.
  • Loading branch information
sfc-gh-jmartinezramirez committed Mar 19, 2024
1 parent 1f1feeb commit c6483bc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 72 deletions.
102 changes: 33 additions & 69 deletions Snowflake.Data.Tests/UnitTests/SFSessionPropertyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,39 @@ public void TestThatItFailsIfNoAccountSpecified(string connectionString)
Assert.AreEqual(SFError.MISSING_CONNECTION_PROPERTY.GetAttribute<SFErrorAttr>().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<TestCase> ConnectionStringTestCases()
{
string defAccount = "testaccount";
Expand Down Expand Up @@ -135,74 +168,7 @@ public static IEnumerable<TestCase> 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",
Expand Down Expand Up @@ -507,8 +473,6 @@ public static IEnumerable<TestCase> ConnectionStringTestCases()
return new TestCase[]
{
simpleTestCase,
testCaseWithEmptyUserAndPassword,
testCaseWithWrappedValuesWithQuotesAndAllowSpaces,
testCaseWithBrowserResponseTimeout,
testCaseWithProxySettings,
testCaseThatDefaultForUseProxyIsFalse,
Expand Down
6 changes: 3 additions & 3 deletions Snowflake.Data/Core/Session/SFSessionProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c6483bc

Please sign in to comment.