From ad92e98ecf7819acc5bc35e1566e6ad826aa2700 Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-lf Date: Fri, 6 Oct 2023 13:03:51 -0700 Subject: [PATCH 1/2] SNOW-723810: Add coverage for RestRequest --- Snowflake.Data.Tests/UnitTests/SFOktaTest.cs | 49 ++++++++++++++++++++ Snowflake.Data/Core/RestRequest.cs | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/Snowflake.Data.Tests/UnitTests/SFOktaTest.cs b/Snowflake.Data.Tests/UnitTests/SFOktaTest.cs index 81b958c81..35f7648ff 100644 --- a/Snowflake.Data.Tests/UnitTests/SFOktaTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFOktaTest.cs @@ -69,5 +69,54 @@ public void TestWrongPostbackUrl() Assert.AreEqual(SFError.IDP_SAML_POSTBACK_INVALID.GetAttribute().errorCode, e.ErrorCode); } } + + [Test] + public void TestLoginRequestToString() + { + string expectedOktaAccount = "mockOktaAccount"; + string expectedOktaUser = "mockOktaUser"; + string expectedOktaUrl = "mockOktaUrl"; + + LoginRequestClientEnv loginRequestClientEnv = new LoginRequestClientEnv(); + LoginRequest loginRequest = new LoginRequest() + { + data = new LoginRequestData() + { + loginName = expectedOktaUser, + accountName = expectedOktaAccount, + clientAppVersion = SFEnvironment.DriverVersion, + clientEnv = loginRequestClientEnv, + Authenticator = expectedOktaUrl, + } + }; + + Assert.AreEqual($"LoginRequest {{data: LoginRequestData {{ClientAppVersion: {SFEnvironment.DriverVersion},\n " + + $"AccountName: {expectedOktaAccount},\n " + + $"loginName: {expectedOktaUser},\n " + + $"ClientEnv: {{ " + + $"APPLICATION: , " + + $"OS_VERSION: , " + + $"NET_RUNTIME: , " + + $"NET_VERSION: , " + + $"INSECURE_MODE: }},\n " + + $"authenticator: {expectedOktaUrl} }} }}", + loginRequest.ToString()); + } + + [Test] + public void TestAuthenticatorRequestToString() + { + string expectedOktaAccount = "mockOktaAccount"; + AuthenticatorRequest authenticatorRequest = new AuthenticatorRequest() + { + Data = new AuthenticatorRequestData() + { + AccountName = expectedOktaAccount, + } + }; + + Assert.AreEqual($"AuthenticatorRequest {{data: AuthenticatorRequestData {{ACCOUNT_NAME: {expectedOktaAccount} }} }}", + authenticatorRequest.ToString()); + } } } diff --git a/Snowflake.Data/Core/RestRequest.cs b/Snowflake.Data/Core/RestRequest.cs index 49a53bc04..77a88323b 100644 --- a/Snowflake.Data/Core/RestRequest.cs +++ b/Snowflake.Data/Core/RestRequest.cs @@ -198,7 +198,7 @@ class AuthenticatorRequestData public override string ToString() { - return String.Format("AuthenticatorRequestData {{ACCOUNT_NANM: {0} }}", + return String.Format("AuthenticatorRequestData {{ACCOUNT_NAME: {0} }}", AccountName.ToString()); } } From 3de0c09f7be772091e0c19e9c6d4b22e24e47a28 Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-lf Date: Fri, 6 Oct 2023 15:44:37 -0700 Subject: [PATCH 2/2] SNOW-723810: Add coverage for RestRequest --- Snowflake.Data.Tests/UnitTests/SFOktaTest.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Snowflake.Data.Tests/UnitTests/SFOktaTest.cs b/Snowflake.Data.Tests/UnitTests/SFOktaTest.cs index 35f7648ff..5de0c6c06 100644 --- a/Snowflake.Data.Tests/UnitTests/SFOktaTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFOktaTest.cs @@ -73,11 +73,14 @@ public void TestWrongPostbackUrl() [Test] public void TestLoginRequestToString() { + // Arrange string expectedOktaAccount = "mockOktaAccount"; string expectedOktaUser = "mockOktaUser"; string expectedOktaUrl = "mockOktaUrl"; LoginRequestClientEnv loginRequestClientEnv = new LoginRequestClientEnv(); + + // Act LoginRequest loginRequest = new LoginRequest() { data = new LoginRequestData() @@ -90,6 +93,7 @@ public void TestLoginRequestToString() } }; + // Assert Assert.AreEqual($"LoginRequest {{data: LoginRequestData {{ClientAppVersion: {SFEnvironment.DriverVersion},\n " + $"AccountName: {expectedOktaAccount},\n " + $"loginName: {expectedOktaUser},\n " + @@ -106,7 +110,10 @@ public void TestLoginRequestToString() [Test] public void TestAuthenticatorRequestToString() { + // Arrange string expectedOktaAccount = "mockOktaAccount"; + + // Act AuthenticatorRequest authenticatorRequest = new AuthenticatorRequest() { Data = new AuthenticatorRequestData() @@ -115,6 +122,7 @@ public void TestAuthenticatorRequestToString() } }; + // Assert Assert.AreEqual($"AuthenticatorRequest {{data: AuthenticatorRequestData {{ACCOUNT_NAME: {expectedOktaAccount} }} }}", authenticatorRequest.ToString()); }