Skip to content

Commit e187b82

Browse files
committed
Merge branch 'master' into mgemra/SNOW-2026116-remove-mono-unix
2 parents bf84827 + f62d01d commit e187b82

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- v5.2.0
55
- Added multi-targeting support. The appropriate build is selected by NuGet based on target framework and OS.
66
- Fixed CRL validation to reject newly downloaded CRLs if their NextUpdate has already expired.
7+
- Users can now specify non-string values in Toml. For example, `port` can be specified as an integer in the Toml.
78
- v5.1.0
89
- Added `APPLICATION_PATH` to `CLIENT_ENVIRONMENT` sent during authentication to identify the application connecting to Snowflake.
910
- Renew idle sessions in the pool if keep alive is enabled.
@@ -19,4 +20,3 @@
1920
- Added the `changelog.yml` GitHub workflow to ensure changelog is updated on release PRs.
2021
- Removed internal classes from public API.
2122
- Added support for explicitly setting Azure managed identity client ID via `MANAGED_IDENTITY_CLIENT_ID` environmen
22-

Snowflake.Data.Tests/UnitTests/SnowflakeTomlConnectionBuilderTest.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,57 @@ public void TestConnectionMapPropertiesWithSpecialCharacters(string passwordValu
506506
// Assert
507507
Assert.AreEqual(expectedValue, properties[SFSessionProperty.PASSWORD]);
508508
}
509+
510+
[Test]
511+
public void TestConnectionWithCompleteSPCSConfiguration()
512+
{
513+
// Arrange
514+
var tokenFilePath = "/path/to/token";
515+
var testToken = "oauth_token_12345";
516+
var mockFileOperations = new Mock<FileOperations>();
517+
var mockEnvironmentOperations = new Mock<EnvironmentOperations>();
518+
mockEnvironmentOperations.Setup(e => e.GetFolderPath(Environment.SpecialFolder.UserProfile))
519+
.Returns($"{Path.DirectorySeparatorChar}home");
520+
mockFileOperations.Setup(f => f.Exists(It.IsAny<string>())).Returns(true);
521+
mockFileOperations.Setup(f => f.ReadAllText(tokenFilePath, It.IsAny<Action<UnixStream>>())).Returns(testToken);
522+
mockFileOperations.Setup(f => f.ReadAllText(It.Is<string>(p => p.Contains(".snowflake")), It.IsAny<Action<UnixStream>>()))
523+
.Returns(@$"
524+
[default]
525+
host = 'host.snowflake.com'
526+
protocol = 'http'
527+
port = 80
528+
account = 'account123'
529+
database = 'testdb'
530+
schema = 'testschema'
531+
warehouse = 'testwh'
532+
authenticator = 'oauth'
533+
token_file_path = '{tokenFilePath}'
534+
client_session_keep_alive = true
535+
ocsp_fail_open = true
536+
disable_ocsp_check = true
537+
");
538+
539+
var reader = new TomlConnectionBuilder(mockFileOperations.Object, mockEnvironmentOperations.Object);
540+
541+
// Act
542+
var connectionString = reader.GetConnectionStringFromToml();
543+
var properties = SFSessionProperties.ParseConnectionString(connectionString, new SessionPropertiesContext());
544+
545+
// Assert
546+
Assert.Multiple(() =>
547+
{
548+
Assert.AreEqual("host.snowflake.com", properties[SFSessionProperty.HOST]);
549+
Assert.AreEqual("http", properties[SFSessionProperty.SCHEME]);
550+
Assert.AreEqual("80", properties[SFSessionProperty.PORT]);
551+
Assert.AreEqual("account123", properties[SFSessionProperty.ACCOUNT]);
552+
Assert.AreEqual("testdb", properties[SFSessionProperty.DB]);
553+
Assert.AreEqual("testschema", properties[SFSessionProperty.SCHEMA]);
554+
Assert.AreEqual("testwh", properties[SFSessionProperty.WAREHOUSE]);
555+
Assert.AreEqual("oauth", properties[SFSessionProperty.AUTHENTICATOR]);
556+
Assert.AreEqual(testToken, properties[SFSessionProperty.TOKEN]);
557+
Assert.AreEqual("true", properties[SFSessionProperty.CLIENT_SESSION_KEEP_ALIVE]);
558+
});
559+
}
509560
}
510561

511562
}

Snowflake.Data/Core/TomlConnectionBuilder.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ internal class TomlConnectionBuilder
2929

3030
private readonly Dictionary<string, string> _tomlToNetPropertiesMapper = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase)
3131
{
32-
{ "DATABASE", "DB" }
32+
{ "DATABASE", "DB" },
33+
{ "PROTOCOL", "SCHEME" }
3334
};
3435

3536
private readonly FileOperations _fileOperations;
@@ -64,7 +65,7 @@ private string GetConnectionStringFromTomlTable(TomlTable connectionToml)
6465
var isOauth = connectionToml.TryGetValue("authenticator", out var authenticator) && OAuthAuthenticator.IsOAuthAuthenticator(authenticator.ToString());
6566
foreach (var property in connectionToml.Keys)
6667
{
67-
var propertyValue = (string)connectionToml[property];
68+
var propertyValue = ConvertTomlValueToString(connectionToml[property]);
6869
if (isOauth && property.Equals("token_file_path", StringComparison.InvariantCultureIgnoreCase))
6970
{
7071
tokenFilePathValue = propertyValue;
@@ -78,6 +79,15 @@ private string GetConnectionStringFromTomlTable(TomlTable connectionToml)
7879
return connectionStringBuilder.ToString();
7980
}
8081

82+
private string ConvertTomlValueToString(object value)
83+
{
84+
if (value is bool boolValue)
85+
{
86+
return boolValue.ToString().ToLower();
87+
}
88+
return value?.ToString() ?? string.Empty;
89+
}
90+
8191
private void AppendTokenFromFileIfNotGivenExplicitly(TomlTable connectionToml, bool isOauth,
8292
StringBuilder connectionStringBuilder, string tokenFilePathValue)
8393
{

0 commit comments

Comments
 (0)