|
|
|
@ -30,39 +30,22 @@ |
|
|
|
|
|
|
|
|
|
const size_t kTargetServiceAccountNum = 2; |
|
|
|
|
|
|
|
|
|
static void test_add_target_service_account_failure() { |
|
|
|
|
/* Initialization. */ |
|
|
|
|
grpc_alts_credentials_options* options = |
|
|
|
|
grpc_alts_credentials_client_options_create(); |
|
|
|
|
auto client_options = |
|
|
|
|
reinterpret_cast<grpc_alts_credentials_client_options*>(options); |
|
|
|
|
|
|
|
|
|
/* Test. */ |
|
|
|
|
GPR_ASSERT(!grpc_alts_credentials_client_options_add_target_service_account( |
|
|
|
|
client_options, nullptr)); |
|
|
|
|
GPR_ASSERT(!grpc_alts_credentials_client_options_add_target_service_account( |
|
|
|
|
nullptr, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1)); |
|
|
|
|
|
|
|
|
|
/* Cleanup. */ |
|
|
|
|
grpc_alts_credentials_options_destroy(options); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void test_copy_client_options_failure() { |
|
|
|
|
/* Initialization. */ |
|
|
|
|
grpc_alts_credentials_options* options = |
|
|
|
|
grpc_alts_credentials_client_options_create(); |
|
|
|
|
|
|
|
|
|
/* Test. */ |
|
|
|
|
GPR_ASSERT(grpc_alts_credentials_options_copy(nullptr) == nullptr); |
|
|
|
|
|
|
|
|
|
/* Cleanup. */ |
|
|
|
|
grpc_alts_credentials_options_destroy(options); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static size_t get_target_service_account_num( |
|
|
|
|
grpc_alts_credentials_client_options* options) { |
|
|
|
|
grpc_alts_credentials_options* options) { |
|
|
|
|
auto client_options = |
|
|
|
|
reinterpret_cast<grpc_alts_credentials_client_options*>(options); |
|
|
|
|
size_t num = 0; |
|
|
|
|
target_service_account* node = options->target_account_list_head; |
|
|
|
|
target_service_account* node = client_options->target_account_list_head; |
|
|
|
|
while (node != nullptr) { |
|
|
|
|
num++; |
|
|
|
|
node = node->next; |
|
|
|
@ -74,36 +57,31 @@ static void test_client_options_api_success() { |
|
|
|
|
/* Initialization. */ |
|
|
|
|
grpc_alts_credentials_options* options = |
|
|
|
|
grpc_alts_credentials_client_options_create(); |
|
|
|
|
auto client_options = |
|
|
|
|
reinterpret_cast<grpc_alts_credentials_client_options*>(options); |
|
|
|
|
|
|
|
|
|
/* Set client options fields. */ |
|
|
|
|
grpc_alts_credentials_client_options_add_target_service_account( |
|
|
|
|
client_options, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1); |
|
|
|
|
options, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1); |
|
|
|
|
grpc_alts_credentials_client_options_add_target_service_account( |
|
|
|
|
client_options, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2); |
|
|
|
|
|
|
|
|
|
options, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2); |
|
|
|
|
/* Validate client option fields. */ |
|
|
|
|
GPR_ASSERT(get_target_service_account_num(client_options) == |
|
|
|
|
GPR_ASSERT(get_target_service_account_num(options) == |
|
|
|
|
kTargetServiceAccountNum); |
|
|
|
|
auto client_options = |
|
|
|
|
reinterpret_cast<grpc_alts_credentials_client_options*>(options); |
|
|
|
|
GPR_ASSERT(strcmp(client_options->target_account_list_head->data, |
|
|
|
|
ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2) == 0); |
|
|
|
|
GPR_ASSERT(strcmp(client_options->target_account_list_head->next->data, |
|
|
|
|
ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1) == 0); |
|
|
|
|
|
|
|
|
|
/* Perform a copy operation and validate its correctness. */ |
|
|
|
|
grpc_alts_credentials_options* new_options = |
|
|
|
|
grpc_alts_credentials_options_copy(options); |
|
|
|
|
GPR_ASSERT(get_target_service_account_num(new_options) == |
|
|
|
|
kTargetServiceAccountNum); |
|
|
|
|
auto new_client_options = |
|
|
|
|
reinterpret_cast<grpc_alts_credentials_client_options*>(new_options); |
|
|
|
|
|
|
|
|
|
GPR_ASSERT(get_target_service_account_num(new_client_options) == |
|
|
|
|
kTargetServiceAccountNum); |
|
|
|
|
GPR_ASSERT(strcmp(new_client_options->target_account_list_head->data, |
|
|
|
|
ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2) == 0); |
|
|
|
|
GPR_ASSERT(strcmp(new_client_options->target_account_list_head->next->data, |
|
|
|
|
ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1) == 0); |
|
|
|
|
|
|
|
|
|
/* Cleanup.*/ |
|
|
|
|
grpc_alts_credentials_options_destroy(options); |
|
|
|
|
grpc_alts_credentials_options_destroy(new_options); |
|
|
|
@ -111,7 +89,6 @@ static void test_client_options_api_success() { |
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) { |
|
|
|
|
/* Test. */ |
|
|
|
|
test_add_target_service_account_failure(); |
|
|
|
|
test_copy_client_options_failure(); |
|
|
|
|
test_client_options_api_success(); |
|
|
|
|
return 0; |
|
|
|
|