diff --git a/Snowflake.Data.Tests/AuthenticationTests/KeyPairConnection.cs b/Snowflake.Data.Tests/AuthenticationTests/KeyPairConnection.cs index ff9150d74..18e3697a0 100644 --- a/Snowflake.Data.Tests/AuthenticationTests/KeyPairConnection.cs +++ b/Snowflake.Data.Tests/AuthenticationTests/KeyPairConnection.cs @@ -12,55 +12,54 @@ public class KeyPairConnectionTest { private string _connectionString = ""; - // - // [Test] - // public void TestAuthenticateUsingKeyPairFileContentSuccessful() - // - // { - // AuthTestHelper authTestHelper = new AuthTestHelper(); - // var privateKey = AuthConnectionString.GetPrivateKeyContentForKeypairAuth("SNOWFLAKE_AUTH_TEST_PRIVATE_KEY_PATH"); - // var parameters = AuthConnectionString.GetKeyPairFromFileContentParameters(privateKey); - // _connectionString = AuthConnectionString.SetPrivateKeyFromFileContentConnectionString(parameters); - // authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); - // authTestHelper.VerifyExceptionIsNotThrown(); - // } -// -// [Test, IgnoreOnCI] -// public void TestAuthenticateUsingKeyPairFileContentInvalidKey() -// { -// AuthTestHelper authTestHelper = new AuthTestHelper(); -// -// var privateKey = AuthConnectionString.GetPrivateKeyContentForKeypairAuth("SNOWFLAKE_AUTH_TEST_INVALID_PRIVATE_KEY_PATH"); -// var parameters = AuthConnectionString.GetKeyPairFromFileContentParameters(privateKey); -// _connectionString = AuthConnectionString.SetPrivateKeyFromFileContentConnectionString(parameters); -// -// authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); -// authTestHelper.VerifyExceptionIsThrown("Error: JWT token is invalid"); -// } -// -// [Test, IgnoreOnCI] -// public void TestAuthenticateUsingKeyPairFilePathSuccessful() -// { -// AuthTestHelper authTestHelper = new AuthTestHelper(); -// var privateKeyPath = AuthConnectionString.GetPrivateKeyPathForKeypairAuth("SNOWFLAKE_AUTH_TEST_PRIVATE_KEY_PATH"); -// var parameters = AuthConnectionString.GetKeyPairFromFilePathConnectionString(privateKeyPath); -// _connectionString = AuthConnectionString.SetPrivateKeyFromFilePathConnectionString(parameters); -// -// authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); -// authTestHelper.VerifyExceptionIsNotThrown(); -// } -// -// [Test, IgnoreOnCI] -// public void TestAuthenticateUsingKeyPairFilePathInvalidKey() -// { -// AuthTestHelper authTestHelper = new AuthTestHelper(); -// -// var privateKeyPath = AuthConnectionString.GetPrivateKeyPathForKeypairAuth("SNOWFLAKE_AUTH_TEST_INVALID_PRIVATE_KEY_PATH"); -// var parameters = AuthConnectionString.GetKeyPairFromFilePathConnectionString(privateKeyPath); -// _connectionString = AuthConnectionString.SetPrivateKeyFromFilePathConnectionString(parameters); -// -// authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); -// authTestHelper.VerifyExceptionIsThrown("Error: JWT token is invalid"); -// } + [Test] + public void TestAuthenticateUsingKeyPairFileContentSuccessful() + + { + AuthTestHelper authTestHelper = new AuthTestHelper(); + var privateKey = AuthConnectionString.GetPrivateKeyContentForKeypairAuth("SNOWFLAKE_AUTH_TEST_PRIVATE_KEY_PATH"); + var parameters = AuthConnectionString.GetKeyPairFromFileContentParameters(privateKey); + _connectionString = AuthConnectionString.SetPrivateKeyFromFileContentConnectionString(parameters); + authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); + authTestHelper.VerifyExceptionIsNotThrown(); + } + + [Test] + public void TestAuthenticateUsingKeyPairFileContentInvalidKey() + { + AuthTestHelper authTestHelper = new AuthTestHelper(); + + var privateKey = AuthConnectionString.GetPrivateKeyContentForKeypairAuth("SNOWFLAKE_AUTH_TEST_INVALID_PRIVATE_KEY_PATH"); + var parameters = AuthConnectionString.GetKeyPairFromFileContentParameters(privateKey); + _connectionString = AuthConnectionString.SetPrivateKeyFromFileContentConnectionString(parameters); + + authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); + authTestHelper.VerifyExceptionIsThrown("Error: JWT token is invalid"); + } + + [Test] + public void TestAuthenticateUsingKeyPairFilePathSuccessful() + { + AuthTestHelper authTestHelper = new AuthTestHelper(); + var privateKeyPath = AuthConnectionString.GetPrivateKeyPathForKeypairAuth("SNOWFLAKE_AUTH_TEST_PRIVATE_KEY_PATH"); + var parameters = AuthConnectionString.GetKeyPairFromFilePathConnectionString(privateKeyPath); + _connectionString = AuthConnectionString.SetPrivateKeyFromFilePathConnectionString(parameters); + + authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); + authTestHelper.VerifyExceptionIsNotThrown(); + } + + [Test] + public void TestAuthenticateUsingKeyPairFilePathInvalidKey() + { + AuthTestHelper authTestHelper = new AuthTestHelper(); + + var privateKeyPath = AuthConnectionString.GetPrivateKeyPathForKeypairAuth("SNOWFLAKE_AUTH_TEST_INVALID_PRIVATE_KEY_PATH"); + var parameters = AuthConnectionString.GetKeyPairFromFilePathConnectionString(privateKeyPath); + _connectionString = AuthConnectionString.SetPrivateKeyFromFilePathConnectionString(parameters); + + authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); + authTestHelper.VerifyExceptionIsThrown("Error: JWT token is invalid"); + } } } diff --git a/Snowflake.Data.Tests/AuthenticationTests/OauthConnection.cs b/Snowflake.Data.Tests/AuthenticationTests/OauthConnection.cs index 37f60dabe..6d6fe26a8 100644 --- a/Snowflake.Data.Tests/AuthenticationTests/OauthConnection.cs +++ b/Snowflake.Data.Tests/AuthenticationTests/OauthConnection.cs @@ -43,20 +43,20 @@ public void TestAuthenticateUsingOauthInvalidToken() authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); authTestHelper.VerifyExceptionIsThrown("Invalid OAuth access token"); } -// -// // [Test, Ignore("Skipped, waits for SNOW-1893041")] -// // public void TestAuthenticateUsingOauthMismatchedUser() -// // { -// // AuthTestHelper authTestHelper = new AuthTestHelper(); -// // -// // string token = AuthConnectionString.GetOauthToken(); -// // var parameters = AuthConnectionString.GetOauthConnectionString(token); -// // parameters[SFSessionProperty.USER] = "fakeAccount"; -// // _connectionString = AuthConnectionString.SetOauthConnectionString(parameters) + ";poolingEnabled=false;minPoolSize=0;"; -// // -// // authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); -// // authTestHelper.VerifyExceptionIsThrown("The user you were trying to authenticate as differs from the user tied to the access token"); -// // -// // } + + [Test, Ignore("Skipped, waits for SNOW-1893041")] + public void TestAuthenticateUsingOauthMismatchedUser() + { + AuthTestHelper authTestHelper = new AuthTestHelper(); + + string token = AuthConnectionString.GetOauthToken(); + var parameters = AuthConnectionString.GetOauthConnectionString(token); + parameters[SFSessionProperty.USER] = "fakeAccount"; + _connectionString = AuthConnectionString.SetOauthConnectionString(parameters) + ";poolingEnabled=false;minPoolSize=0;"; + + authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); + authTestHelper.VerifyExceptionIsThrown("The user you were trying to authenticate as differs from the user tied to the access token"); + + } } } diff --git a/Snowflake.Data.Tests/AuthenticationTests/OktaConnection.cs b/Snowflake.Data.Tests/AuthenticationTests/OktaConnection.cs index e7f1ebc1d..47d0556f7 100644 --- a/Snowflake.Data.Tests/AuthenticationTests/OktaConnection.cs +++ b/Snowflake.Data.Tests/AuthenticationTests/OktaConnection.cs @@ -1,94 +1,94 @@ -// /* -// * Copyright (c) 2012-2025 Snowflake Computing Inc. All rights reserved. -// */ -// -// using NUnit.Framework; -// using Snowflake.Data.Core; -// -// namespace Snowflake.Data.Tests.AuthenticationTests -// { -// -// [NonParallelizable] -// public class OktaConnectionTest : SFBaseTest -// { -// private string _connectionString = ""; -// -// [SetUp] -// public void SetUp() -// { -// AuthTestHelper authTestHelper = new AuthTestHelper(); -// -// var parameters = AuthConnectionString.GetOktaConnectionString(); -// _connectionString = AuthConnectionString.SetOktaConnectionString(parameters); -// authTestHelper.CleanBrowserProcess(); -// -// } -// -// [Test, IgnoreOnCI] -// public void TestAuthenticateUsingOktaSuccessful() -// { -// AuthTestHelper authTestHelper = new AuthTestHelper(); -// -// authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); -// authTestHelper.VerifyExceptionIsNotThrown(); -// -// } -// -// [Test, IgnoreOnCI] -// public void TestAuthenticateUsingOktaWrongUsernameParam() -// { -// AuthTestHelper authTestHelper = new AuthTestHelper(); -// -// var parameters = AuthConnectionString.GetOktaConnectionString(); -// parameters[SFSessionProperty.USER] = "differentUser"; -// _connectionString = AuthConnectionString.SetOktaConnectionString(parameters); -// -// authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); -// authTestHelper.VerifyExceptionIsThrown("401 (Unauthorized)"); -// } -// -// [Test, IgnoreOnCI] -// public void TestAuthenticateUsingOktaWrongCredentials() -// { -// AuthTestHelper authTestHelper = new AuthTestHelper(); -// -// var parameters = AuthConnectionString.GetOktaConnectionString(); -// parameters[SFSessionProperty.USER] = "differentUser"; -// parameters[SFSessionProperty.PASSWORD] = "fakepassword"; -// -// _connectionString = AuthConnectionString.SetOktaConnectionString(parameters); -// -// authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); -// authTestHelper.VerifyExceptionIsThrown("401 (Unauthorized)"); -// } -// -// [Test, IgnoreOnCI] -// public void TestAuthenticateUsingOktaWrongUrl() -// { -// AuthTestHelper authTestHelper = new AuthTestHelper(); -// -// var parameters = AuthConnectionString.GetOktaConnectionString(); -// parameters[SFSessionProperty.AUTHENTICATOR] = "https://invalid.okta.com/"; -// -// _connectionString = AuthConnectionString.SetOktaConnectionString(parameters); -// -// authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); -// authTestHelper.VerifyExceptionIsThrown("The specified authenticator is not accepted by your Snowflake account configuration"); -// } -// -// -// [Test, IgnoreOnCI] -// public void TestAuthenticateUsingUrlWithoutOkta() -// { -// AuthTestHelper authTestHelper = new AuthTestHelper(); -// -// var parameters = AuthConnectionString.GetOktaConnectionString(); -// parameters[SFSessionProperty.AUTHENTICATOR] = "https://invalid.abc.com/"; -// -// _connectionString = AuthConnectionString.SetOktaConnectionString(parameters); -// -// authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); -// authTestHelper.VerifyExceptionIsThrown("Unknown authenticator"); -// } -// } -// } +/* + * Copyright (c) 2012-2025 Snowflake Computing Inc. All rights reserved. + */ + +using NUnit.Framework; +using Snowflake.Data.Core; + +namespace Snowflake.Data.AuthenticationTests +{ + + [NonParallelizable] + public class OktaConnectionTest + { + private string _connectionString = ""; + + [SetUp] + public void SetUp() + { + AuthTestHelper authTestHelper = new AuthTestHelper(); + + var parameters = AuthConnectionString.GetOktaConnectionString(); + _connectionString = AuthConnectionString.SetOktaConnectionString(parameters); + authTestHelper.CleanBrowserProcess(); + + } + + [Test] + public void TestAuthenticateUsingOktaSuccessful() + { + AuthTestHelper authTestHelper = new AuthTestHelper(); + + authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); + authTestHelper.VerifyExceptionIsNotThrown(); + + } + + [Test] + public void TestAuthenticateUsingOktaWrongUsernameParam() + { + AuthTestHelper authTestHelper = new AuthTestHelper(); + + var parameters = AuthConnectionString.GetOktaConnectionString(); + parameters[SFSessionProperty.USER] = "differentUser"; + _connectionString = AuthConnectionString.SetOktaConnectionString(parameters); + + authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); + authTestHelper.VerifyExceptionIsThrown("401 (Unauthorized)"); + } + + [Test] + public void TestAuthenticateUsingOktaWrongCredentials() + { + AuthTestHelper authTestHelper = new AuthTestHelper(); + + var parameters = AuthConnectionString.GetOktaConnectionString(); + parameters[SFSessionProperty.USER] = "differentUser"; + parameters[SFSessionProperty.PASSWORD] = "fakepassword"; + + _connectionString = AuthConnectionString.SetOktaConnectionString(parameters); + + authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); + authTestHelper.VerifyExceptionIsThrown("401 (Unauthorized)"); + } + + [Test] + public void TestAuthenticateUsingOktaWrongUrl() + { + AuthTestHelper authTestHelper = new AuthTestHelper(); + + var parameters = AuthConnectionString.GetOktaConnectionString(); + parameters[SFSessionProperty.AUTHENTICATOR] = "https://invalid.okta.com/"; + + _connectionString = AuthConnectionString.SetOktaConnectionString(parameters); + + authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); + authTestHelper.VerifyExceptionIsThrown("The specified authenticator is not accepted by your Snowflake account configuration"); + } + + + [Test] + public void TestAuthenticateUsingUrlWithoutOkta() + { + AuthTestHelper authTestHelper = new AuthTestHelper(); + + var parameters = AuthConnectionString.GetOktaConnectionString(); + parameters[SFSessionProperty.AUTHENTICATOR] = "https://invalid.abc.com/"; + + _connectionString = AuthConnectionString.SetOktaConnectionString(parameters); + + authTestHelper.ConnectAndExecuteSimpleQuery(_connectionString); + authTestHelper.VerifyExceptionIsThrown("Unknown authenticator"); + } + } +}