diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 50c2f74bbe..5098322eb7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -48,9 +48,7 @@ SET(TESTS_C # test_lob # test_stats # This test needs the Oauth token, so it should be run manually -# test_oauth -# MFA connection is only able to run testing manually. - test_mfa_connect +# test_manual_connect ) SET(TESTS_CXX diff --git a/tests/test_mfa_connect.c b/tests/test_manual_connect.c similarity index 63% rename from tests/test_mfa_connect.c rename to tests/test_manual_connect.c index fbc69e1f1d..82c55ce8cc 100644 --- a/tests/test_mfa_connect.c +++ b/tests/test_manual_connect.c @@ -1,19 +1,53 @@ -/* - * Copyright (c) 2018-2024 Snowflake Computing, Inc. All rights reserved. - */ +// +// Copyright (c) 2018-2024 Snowflake Computing, Inc. All rights reserved. +// #include "utils/test_setup.h" -void test_connect_with_duo_push(void **unused) -{ +/** + * Test connection with OAuth authentication. + */ +void test_oauth_connect(void **unused) { SF_CONNECT *sf = snowflake_init(); snowflake_set_attribute(sf, SF_CON_ACCOUNT, getenv("SNOWFLAKE_TEST_ACCOUNT")); snowflake_set_attribute(sf, SF_CON_USER, getenv("SNOWFLAKE_TEST_USER")); - snowflake_set_attribute(sf, SF_CON_PASSWORD, - getenv("SNOWFLAKE_TEST_PASSWORD")); + char *host, *port, *protocol; host = getenv("SNOWFLAKE_TEST_HOST"); + if (host) { + snowflake_set_attribute(sf, SF_CON_HOST, host); + } + port = getenv("SNOWFLAKE_TEST_PORT"); + if (port) { + snowflake_set_attribute(sf, SF_CON_PORT, port); + } + protocol = getenv("SNOWFLAKE_TEST_PROTOCOL"); + if (protocol) { + snowflake_set_attribute(sf, SF_CON_PROTOCOL, protocol); + } + char* token = ""; + snowflake_set_attribute(sf, SF_CON_AUTHENTICATOR, "oauth"); + snowflake_set_attribute(sf, SF_CON_OAUTH_TOKEN, token); + + SF_STATUS status = snowflake_connect(sf); + if (status != SF_STATUS_SUCCESS) { + dump_error(&(sf->error)); + } + assert_int_equal(status, SF_STATUS_SUCCESS); + snowflake_term(sf); +} + +void test_mfa_connect_with_duo_push(void** unused) +{ + SF_CONNECT* sf = snowflake_init(); + snowflake_set_attribute(sf, SF_CON_ACCOUNT, + getenv("SNOWFLAKE_TEST_ACCOUNT")); + snowflake_set_attribute(sf, SF_CON_USER, getenv("SNOWFLAKE_TEST_USER")); + snowflake_set_attribute(sf, SF_CON_PASSWORD, + getenv("SNOWFLAKE_TEST_PASSWORD")); + char* host, * port, * protocol; + host = getenv("SNOWFLAKE_TEST_HOST"); if (host) { snowflake_set_attribute(sf, SF_CON_HOST, host); @@ -38,15 +72,15 @@ void test_connect_with_duo_push(void **unused) snowflake_term(sf); } -void test_connect_with_duo_passcode(void **unused) +void test_mfa_connect_with_duo_passcode(void** unused) { - SF_CONNECT *sf = snowflake_init(); + SF_CONNECT* sf = snowflake_init(); snowflake_set_attribute(sf, SF_CON_ACCOUNT, - getenv("SNOWFLAKE_TEST_ACCOUNT")); + getenv("SNOWFLAKE_TEST_ACCOUNT")); snowflake_set_attribute(sf, SF_CON_USER, getenv("SNOWFLAKE_TEST_USER")); snowflake_set_attribute(sf, SF_CON_PASSWORD, - getenv("SNOWFLAKE_TEST_PASSWORD")); - char *host, *port, *protocol, *passcode; + getenv("SNOWFLAKE_TEST_PASSWORD")); + char* host, * port, * protocol, * passcode; host = getenv("SNOWFLAKE_TEST_HOST"); if (host) { @@ -80,7 +114,7 @@ void test_connect_with_duo_passcode(void **unused) snowflake_term(sf); } -void test_connect_with_duo_passcodeInPassword(void** unused) +void test_mfa_connect_with_duo_passcodeInPassword(void** unused) { SF_CONNECT* sf = snowflake_init(); snowflake_set_attribute(sf, SF_CON_ACCOUNT, @@ -117,14 +151,15 @@ void test_connect_with_duo_passcodeInPassword(void** unused) snowflake_term(sf); } -int main(void) -{ + +int main(void) { initialize_test(SF_BOOLEAN_FALSE); const struct CMUnitTest tests[] = { - cmocka_unit_test(test_connect_with_duo_push), - cmocka_unit_test(test_connect_with_duo_passcode), - //Need to run this testing separately. - //cmocka_unit_test(test_connect_with_duo_passcodeInPassword), + cmocka_unit_test(test_oauth_connect), + cmocka_unit_test(test_mfa_connect_with_duo_push), + cmocka_unit_test(test_mfa_connect_with_duo_passcode), + //Need to run this testing separately. + //cmocka_unit_test(test_mfa_connect_with_duo_passcodeInPassword), }; int ret = cmocka_run_group_tests(tests, NULL, NULL); snowflake_global_term(); diff --git a/tests/test_oauth.c b/tests/test_oauth.c deleted file mode 100644 index c1a77eb31e..0000000000 --- a/tests/test_oauth.c +++ /dev/null @@ -1,49 +0,0 @@ -// -// Copyright (c) 2018-2024 Snowflake Computing, Inc. All rights reserved. -// - -#include "utils/test_setup.h" - -/** - * Test connection with OAuth authentication. - */ -void test_connect_with_oauth(void **unused) { - SF_CONNECT *sf = snowflake_init(); - snowflake_set_attribute(sf, SF_CON_ACCOUNT, - getenv("SNOWFLAKE_TEST_ACCOUNT")); - snowflake_set_attribute(sf, SF_CON_USER, getenv("SNOWFLAKE_TEST_USER")); - - char *host, *port, *protocol; - host = getenv("SNOWFLAKE_TEST_HOST"); - if (host) { - snowflake_set_attribute(sf, SF_CON_HOST, host); - } - port = getenv("SNOWFLAKE_TEST_PORT"); - if (port) { - snowflake_set_attribute(sf, SF_CON_PORT, port); - } - protocol = getenv("SNOWFLAKE_TEST_PROTOCOL"); - if (protocol) { - snowflake_set_attribute(sf, SF_CON_PROTOCOL, protocol); - } - char* token = ""; - snowflake_set_attribute(sf, SF_CON_AUTHENTICATOR, "oauth"); - snowflake_set_attribute(sf, SF_CON_OAUTH_TOKEN, token); - - SF_STATUS status = snowflake_connect(sf); - if (status != SF_STATUS_SUCCESS) { - dump_error(&(sf->error)); - } - assert_int_equal(status, SF_STATUS_SUCCESS); - snowflake_term(sf); -} - -int main(void) { - initialize_test(SF_BOOLEAN_FALSE); - const struct CMUnitTest tests[] = { - cmocka_unit_test(test_connect_with_oauth), - }; - int ret = cmocka_run_group_tests(tests, NULL, NULL); - snowflake_global_term(); - return ret; -}