-
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.
SNOW-1538117: Support privatelink environments (#769)
- Loading branch information
1 parent
df3dce7
commit c4b0fe2
Showing
9 changed files
with
128 additions
and
2 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
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,16 @@ | ||
#include "util.h" | ||
#include <string.h> | ||
|
||
sf_bool ends_with(char* str, char* suffix) | ||
{ | ||
size_t str_length = strlen(str); | ||
size_t suffix_length = strlen(suffix); | ||
if (suffix_length > str_length) | ||
{ | ||
return SF_BOOLEAN_FALSE; | ||
} | ||
|
||
char* str_suffix = str + (str_length - suffix_length); | ||
|
||
return sf_strncasecmp(str_suffix, suffix, suffix_length) == 0; | ||
} |
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,19 @@ | ||
#ifndef SNOWFLAKE_UTIL_H | ||
#define SNOWFLAKE_UTIL_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "../include/snowflake/basic_types.h" | ||
|
||
/** | ||
* Validate str ends with the suffix | ||
*/ | ||
sf_bool ends_with(char* str, char* suffix); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif //SNOWFLAKE_UTIL_H |
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,59 @@ | ||
/* | ||
* 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_private_link_core(void** unused) | ||
{ | ||
char* original_env = getenv("SF_OCSP_RESPONSE_CACHE_SERVER_URL"); | ||
SF_CONNECT* sf = (SF_CONNECT*)SF_CALLOC(1, sizeof(SF_CONNECT)); | ||
sf->account = "testaccount"; | ||
sf->user = "testuser"; | ||
sf->password = "testpassword"; | ||
sf->authenticator = SF_AUTHENTICATOR_DEFAULT; | ||
|
||
_snowflake_check_connection_parameters(sf); | ||
assert_int_equal(NULL, getenv("SF_OCSP_RESPONSE_CACHE_SERVER_URL")); | ||
sf_unsetenv("SF_OCSP_RESPONSE_CACHE_SERVER_URL"); | ||
|
||
sf->host = "account.privateLINK.snowflakecomputING.com"; | ||
_snowflake_check_connection_parameters(sf); | ||
assert_string_equal("http://ocsp.account.privateLINK.snowflakecomputING.com/ocsp_response_cache.json", getenv("SF_OCSP_RESPONSE_CACHE_SERVER_URL")); | ||
sf_unsetenv("SF_OCSP_RESPONSE_CACHE_SERVER_URL"); | ||
|
||
sf->host = "account.snowflakecomputing.com"; | ||
_snowflake_check_connection_parameters(sf); | ||
assert_int_equal(NULL, getenv("SF_OCSP_RESPONSE_CACHE_SERVER_URL")); | ||
sf_unsetenv("SF_OCSP_RESPONSE_CACHE_SERVER_URL"); | ||
|
||
sf->host = "account.privatelink.snowflakecomputing.cn"; | ||
_snowflake_check_connection_parameters(sf); | ||
assert_string_equal("http://ocsp.account.privatelink.snowflakecomputing.cn/ocsp_response_cache.json", getenv("SF_OCSP_RESPONSE_CACHE_SERVER_URL")); | ||
sf_unsetenv("SF_OCSP_RESPONSE_CACHE_SERVER_URL"); | ||
|
||
|
||
if (original_env) { | ||
sf_setenv("SF_OCSP_RESPONSE_CACHE_SERVER_URL", original_env); | ||
} | ||
else { | ||
sf_unsetenv("SF_OCSP_RESPONSE_CACHE_SERVER_URL"); | ||
} | ||
} | ||
|
||
int main(void) | ||
{ | ||
initialize_test(SF_BOOLEAN_FALSE); | ||
const struct CMUnitTest tests[] = { | ||
cmocka_unit_test(test_private_link_core), | ||
}; | ||
int ret = cmocka_run_group_tests(tests, NULL, NULL); | ||
snowflake_global_term(); | ||
return ret; | ||
} |