Skip to content

Commit

Permalink
Accept pooling for key files with password
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-knozderko committed May 15, 2024
1 parent db479e6 commit edb50c2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
12 changes: 12 additions & 0 deletions Snowflake.Data.Tests/UnitTests/ConnectionPoolManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ public void TestGetPoolingOnManagerLevelAlwaysTrue()
Assert.IsFalse(sessionPool2.GetPooling());
}

[Test]
[TestCase("authenticator=externalbrowser;account=test;user=test;")]
[TestCase("authenticator=snowflake_jwt;account=test;user=test;private_key_file=/some/file.key")]
public void TestDisabledPoolingWhenSecretesProvidedExternally(string connectionString)
{
// act
var pool = _connectionPoolManager.GetPool(connectionString, null);

// assert
Assert.IsFalse(pool.GetPooling());
}

[Test]
public void TestGetTimeoutOnManagerLevelWhenNotAllPoolsEqual()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ public void TestExtractPoolingEnabled(string propertyValue, bool poolingEnabled)
[TestCase("authenticator=snowflake_jwt;account=test;user=test;private_key=secretKey", true)]
[TestCase("authenticator=snowflake_jwt;account=test;user=test;private_key=secretKey;poolingEnabled=true;", true)]
[TestCase("authenticator=snowflake_jwt;account=test;user=test;private_key=secretKey;poolingEnabled=false;", false)]
[TestCase("authenticator=snowflake_jwt;account=test;user=test;private_key_file=/some/file.key;private_key_pwd=secretPwd", true)]
[TestCase("authenticator=snowflake_jwt;account=test;user=test;private_key_file=/some/file.key;private_key_pwd=", false)]
public void TestDisablePoolingDefaultWhenSecretsProvidedExternally(string connectionString, bool poolingEnabled)
{
// act
Expand Down
4 changes: 2 additions & 2 deletions Snowflake.Data/Core/Session/SFSessionHttpClientProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public void DisablePoolingDefaultIfSecretsProvidedExternally(SFSessionProperties
DisablePoolingIfNotExplicitlyEnabled(properties, "external browser");

} else if (KeyPairAuthenticator.AUTH_NAME.Equals(authenticator)
&& properties.TryGetValue(SFSessionProperty.PRIVATE_KEY_FILE, out var privateKeyFile)
&& !string.IsNullOrEmpty(privateKeyFile))
&& properties.IsNonEmptyValueProvided(SFSessionProperty.PRIVATE_KEY_FILE)
&& !properties.IsNonEmptyValueProvided(SFSessionProperty.PRIVATE_KEY_PWD))
{
DisablePoolingIfNotExplicitlyEnabled(properties, "key pair with private key in a file");
}
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 @@ -256,7 +256,7 @@ internal static SFSessionProperties ParseConnectionString(string connectionStrin
}

ValidateAuthenticator(properties);
properties.IsPoolingEnabledValueProvided = CheckPoolingEnabledValueProvided(properties);
properties.IsPoolingEnabledValueProvided = properties.IsNonEmptyValueProvided(SFSessionProperty.POOLINGENABLED);
CheckSessionProperties(properties);
ValidateFileTransferMaxBytesInMemoryProperty(properties);
ValidateAccountDomain(properties);
Expand Down Expand Up @@ -310,8 +310,8 @@ private static void ValidateAuthenticator(SFSessionProperties properties)
}
}

private static bool CheckPoolingEnabledValueProvided(SFSessionProperties properties) =>
properties.TryGetValue(SFSessionProperty.POOLINGENABLED, out var poolingEnabledStr) && !string.IsNullOrEmpty(poolingEnabledStr);
internal bool IsNonEmptyValueProvided(SFSessionProperty property) =>
TryGetValue(property, out var propertyValueStr) && !string.IsNullOrEmpty(propertyValueStr);

private static string BuildConnectionStringWithoutSecrets(ref string[] keys, ref string[] values)
{
Expand Down

0 comments on commit edb50c2

Please sign in to comment.