-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into SNOW-1371086-multiple-statements
- Loading branch information
Showing
4 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright (c) 2018-2024 Snowflake Computing, Inc. All rights reserved. | ||
*/ | ||
|
||
#include "utils/test_setup.h" | ||
|
||
void test_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); | ||
} | ||
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); | ||
} | ||
|
||
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_connect_with_duo_passcode(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, *passcode; | ||
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); | ||
} | ||
passcode = getenv("SNOWFLAKE_TEST_PASSCODE"); | ||
if (passcode) | ||
{ | ||
snowflake_set_attribute(sf, SF_CON_PASSCODE, passcode); | ||
} | ||
else { | ||
dump_error(&(sf->error)); | ||
} | ||
|
||
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_connect_with_duo_passcodeInPassword(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")); | ||
sf_bool passcode_in_password = SF_BOOLEAN_TRUE; | ||
snowflake_set_attribute(sf, SF_CON_PASSCODE_IN_PASSWORD, &passcode_in_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); | ||
} | ||
|
||
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_duo_push), | ||
cmocka_unit_test(test_connect_with_duo_passcode), | ||
//Need to run this testing separately. | ||
//cmocka_unit_test(test_connect_with_duo_passcodeInPassword), | ||
}; | ||
int ret = cmocka_run_group_tests(tests, NULL, NULL); | ||
snowflake_global_term(); | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (c) 2018-2024 Snowflake Computing, Inc. All rights reserved. | ||
*/ | ||
|
||
#include <string.h> | ||
#include "utils/test_setup.h" | ||
#include "connection.h" | ||
#include "memory.h" | ||
|
||
/** | ||
* Test json body is properly updated. | ||
*/ | ||
void test_json_data_in_MFA_Auth(void **unused) | ||
{ | ||
SF_CONNECT* sf = (SF_CONNECT*)SF_CALLOC(1, sizeof(SF_CONNECT)); | ||
sf->account = "testaccount"; | ||
sf->host = "testaccount.snowflakecomputing.com"; | ||
sf->user = "testuser"; | ||
sf->password = "testpassword"; | ||
sf->authenticator = SF_AUTHENTICATOR_DEFAULT; | ||
sf->application_name = SF_API_NAME; | ||
sf->application_version = SF_API_VERSION; | ||
|
||
cJSON *body = create_auth_json_body( | ||
sf, | ||
sf->application, | ||
sf->application_name, | ||
sf->application_version, | ||
sf->timezone, | ||
sf->autocommit); | ||
cJSON* data = snowflake_cJSON_GetObjectItem(body, "data"); | ||
|
||
assert_string_equal(snowflake_cJSON_GetStringValue(snowflake_cJSON_GetObjectItem(data, "EXT_AUTHN_DUO_METHOD")), "push"); | ||
|
||
sf->passcode = "123456"; | ||
body = create_auth_json_body( | ||
sf, | ||
sf->application, | ||
sf->application_name, | ||
sf->application_version, | ||
sf->timezone, | ||
sf->autocommit); | ||
data = snowflake_cJSON_GetObjectItem(body, "data"); | ||
|
||
assert_string_equal(snowflake_cJSON_GetStringValue(snowflake_cJSON_GetObjectItem(data, "EXT_AUTHN_DUO_METHOD")), "passcode"); | ||
assert_string_equal(snowflake_cJSON_GetStringValue(snowflake_cJSON_GetObjectItem(data, "passcode")), "123456"); | ||
|
||
sf->passcode_in_password = SF_BOOLEAN_TRUE; | ||
|
||
body = create_auth_json_body( | ||
sf, | ||
sf->application, | ||
sf->application_name, | ||
sf->application_version, | ||
sf->timezone, | ||
sf->autocommit); | ||
data = snowflake_cJSON_GetObjectItem(body, "data"); | ||
|
||
assert_string_equal(snowflake_cJSON_GetStringValue(snowflake_cJSON_GetObjectItem(data, "EXT_AUTHN_DUO_METHOD")), "passcode"); | ||
assert_int_equal(snowflake_cJSON_GetStringValue(snowflake_cJSON_GetObjectItem(data, "passcode")), NULL); | ||
|
||
sf_bool passcodeInPassword; | ||
json_copy_bool(&passcodeInPassword, data, "passcodeInPassword"); | ||
assert_int_equal(passcodeInPassword, SF_BOOLEAN_TRUE); | ||
|
||
SF_FREE(sf); | ||
} | ||
|
||
int main(void) | ||
{ | ||
initialize_test(SF_BOOLEAN_FALSE); | ||
const struct CMUnitTest tests[] = { | ||
cmocka_unit_test(test_json_data_in_MFA_Auth), | ||
}; | ||
int ret = cmocka_run_group_tests(tests, NULL, NULL); | ||
snowflake_global_term(); | ||
return ret; | ||
} |