|
8 | 8 | */ |
9 | 9 | void test_json_data_in_MFA_Auth(void **unused) |
10 | 10 | { |
| 11 | + SF_UNUSED(unused); |
11 | 12 | SF_CONNECT* sf = (SF_CONNECT*)SF_CALLOC(1, sizeof(SF_CONNECT)); |
12 | 13 | sf->account = "testaccount"; |
13 | 14 | sf->host = "testaccount.snowflakecomputing.com"; |
@@ -62,11 +63,66 @@ void test_json_data_in_MFA_Auth(void **unused) |
62 | 63 | SF_FREE(sf); |
63 | 64 | } |
64 | 65 |
|
| 66 | +/** |
| 67 | + * Test that application_path override is used in CLIENT_ENVIRONMENT. |
| 68 | + */ |
| 69 | +void test_application_path_override(void **unused) |
| 70 | +{ |
| 71 | + SF_UNUSED(unused); |
| 72 | + SF_CONNECT* sf = (SF_CONNECT*)SF_CALLOC(1, sizeof(SF_CONNECT)); |
| 73 | + sf->account = "testaccount"; |
| 74 | + sf->host = "testaccount.snowflakecomputing.com"; |
| 75 | + sf->user = "testuser"; |
| 76 | + sf->password = "testpassword"; |
| 77 | + sf->authenticator = SF_AUTHENTICATOR_DEFAULT; |
| 78 | + sf->application_name = SF_API_NAME; |
| 79 | + sf->application_version = SF_API_VERSION; |
| 80 | + |
| 81 | + // Test 1: Without override, APPLICATION_PATH should be auto-detected |
| 82 | + // (In mock mode it will be "/app/path") |
| 83 | + cJSON *body = create_auth_json_body( |
| 84 | + sf, |
| 85 | + sf->application, |
| 86 | + sf->application_name, |
| 87 | + sf->application_version, |
| 88 | + sf->timezone, |
| 89 | + sf->autocommit); |
| 90 | + cJSON* data = snowflake_cJSON_GetObjectItem(body, "data"); |
| 91 | + cJSON* client_env = snowflake_cJSON_GetObjectItem(data, "CLIENT_ENVIRONMENT"); |
| 92 | + cJSON* app_path = snowflake_cJSON_GetObjectItem(client_env, "APPLICATION_PATH"); |
| 93 | + |
| 94 | + assert_non_null(app_path); |
| 95 | + // In non-mock mode this would be the executable path, in mock mode it's "/app/path" |
| 96 | + assert_non_null(snowflake_cJSON_GetStringValue(app_path)); |
| 97 | + snowflake_cJSON_Delete(body); |
| 98 | + |
| 99 | + // Test 2: With override, APPLICATION_PATH should use the custom value |
| 100 | + sf->application_path = "/custom/path/to/my_script.php"; |
| 101 | + |
| 102 | + body = create_auth_json_body( |
| 103 | + sf, |
| 104 | + sf->application, |
| 105 | + sf->application_name, |
| 106 | + sf->application_version, |
| 107 | + sf->timezone, |
| 108 | + sf->autocommit); |
| 109 | + data = snowflake_cJSON_GetObjectItem(body, "data"); |
| 110 | + client_env = snowflake_cJSON_GetObjectItem(data, "CLIENT_ENVIRONMENT"); |
| 111 | + app_path = snowflake_cJSON_GetObjectItem(client_env, "APPLICATION_PATH"); |
| 112 | + |
| 113 | + assert_non_null(app_path); |
| 114 | + assert_string_equal(snowflake_cJSON_GetStringValue(app_path), "/custom/path/to/my_script.php"); |
| 115 | + snowflake_cJSON_Delete(body); |
| 116 | + |
| 117 | + SF_FREE(sf); |
| 118 | +} |
| 119 | + |
65 | 120 | int main(void) |
66 | 121 | { |
67 | 122 | initialize_test(SF_BOOLEAN_FALSE); |
68 | 123 | const struct CMUnitTest tests[] = { |
69 | 124 | cmocka_unit_test(test_json_data_in_MFA_Auth), |
| 125 | + cmocka_unit_test(test_application_path_override), |
70 | 126 | }; |
71 | 127 | int ret = cmocka_run_group_tests(tests, NULL, NULL); |
72 | 128 | snowflake_global_term(); |
|
0 commit comments