From e954f95ba403dff45caeaa0bbdf5d91a5118c14d Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-lf <115584722+sfc-gh-ext-simba-lf@users.noreply.github.com> Date: Wed, 18 Oct 2023 09:03:59 -0700 Subject: [PATCH] SNOW-723810: Add coverage for RestRequest (#784) ### Description Regarding issue 113 The PR adds tests for RestRequest to increase code coverage ### Checklist - [x] Code compiles correctly - [x] Code is formatted according to [Coding Conventions](../CodingConventions.md) - [x] Created tests which fail without the change (if possible) - [x] All tests passing (`dotnet test`) - [x] Extended the README / documentation, if necessary - [x] Provide JIRA issue id (if possible) or GitHub issue id in PR name --- Snowflake.Data.Tests/UnitTests/SFOktaTest.cs | 57 ++++++++++++++++++++ Snowflake.Data/Core/RestRequest.cs | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/Snowflake.Data.Tests/UnitTests/SFOktaTest.cs b/Snowflake.Data.Tests/UnitTests/SFOktaTest.cs index 81b958c81..5de0c6c06 100644 --- a/Snowflake.Data.Tests/UnitTests/SFOktaTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFOktaTest.cs @@ -69,5 +69,62 @@ public void TestWrongPostbackUrl() Assert.AreEqual(SFError.IDP_SAML_POSTBACK_INVALID.GetAttribute().errorCode, e.ErrorCode); } } + + [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() + { + loginName = expectedOktaUser, + accountName = expectedOktaAccount, + clientAppVersion = SFEnvironment.DriverVersion, + clientEnv = loginRequestClientEnv, + Authenticator = expectedOktaUrl, + } + }; + + // Assert + 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() + { + // Arrange + string expectedOktaAccount = "mockOktaAccount"; + + // Act + AuthenticatorRequest authenticatorRequest = new AuthenticatorRequest() + { + Data = new AuthenticatorRequestData() + { + AccountName = expectedOktaAccount, + } + }; + + // Assert + 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()); } }