|
|
@ -338,13 +338,15 @@ static void check_metadata(expected_md *expected, grpc_credentials_md *md_elems, |
|
|
|
static void check_google_iam_metadata(grpc_exec_ctx *exec_ctx, void *user_data, |
|
|
|
static void check_google_iam_metadata(grpc_exec_ctx *exec_ctx, void *user_data, |
|
|
|
grpc_credentials_md *md_elems, |
|
|
|
grpc_credentials_md *md_elems, |
|
|
|
size_t num_md, |
|
|
|
size_t num_md, |
|
|
|
grpc_credentials_status status) { |
|
|
|
grpc_credentials_status status, |
|
|
|
|
|
|
|
const char *error_details) { |
|
|
|
grpc_call_credentials *c = (grpc_call_credentials *)user_data; |
|
|
|
grpc_call_credentials *c = (grpc_call_credentials *)user_data; |
|
|
|
expected_md emd[] = {{GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, |
|
|
|
expected_md emd[] = {{GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, |
|
|
|
test_google_iam_authorization_token}, |
|
|
|
test_google_iam_authorization_token}, |
|
|
|
{GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, |
|
|
|
{GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, |
|
|
|
test_google_iam_authority_selector}}; |
|
|
|
test_google_iam_authority_selector}}; |
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_OK); |
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_OK); |
|
|
|
|
|
|
|
GPR_ASSERT(error_details == NULL); |
|
|
|
GPR_ASSERT(num_md == 2); |
|
|
|
GPR_ASSERT(num_md == 2); |
|
|
|
check_metadata(emd, md_elems, num_md); |
|
|
|
check_metadata(emd, md_elems, num_md); |
|
|
|
grpc_call_credentials_unref(c); |
|
|
|
grpc_call_credentials_unref(c); |
|
|
@ -362,14 +364,13 @@ static void test_google_iam_creds(void) { |
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void check_access_token_metadata(grpc_exec_ctx *exec_ctx, |
|
|
|
static void check_access_token_metadata( |
|
|
|
void *user_data, |
|
|
|
grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, |
|
|
|
grpc_credentials_md *md_elems, |
|
|
|
size_t num_md, grpc_credentials_status status, const char *error_details) { |
|
|
|
size_t num_md, |
|
|
|
|
|
|
|
grpc_credentials_status status) { |
|
|
|
|
|
|
|
grpc_call_credentials *c = (grpc_call_credentials *)user_data; |
|
|
|
grpc_call_credentials *c = (grpc_call_credentials *)user_data; |
|
|
|
expected_md emd[] = {{GRPC_AUTHORIZATION_METADATA_KEY, "Bearer blah"}}; |
|
|
|
expected_md emd[] = {{GRPC_AUTHORIZATION_METADATA_KEY, "Bearer blah"}}; |
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_OK); |
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_OK); |
|
|
|
|
|
|
|
GPR_ASSERT(error_details == NULL); |
|
|
|
GPR_ASSERT(num_md == 1); |
|
|
|
GPR_ASSERT(num_md == 1); |
|
|
|
check_metadata(emd, md_elems, num_md); |
|
|
|
check_metadata(emd, md_elems, num_md); |
|
|
|
grpc_call_credentials_unref(c); |
|
|
|
grpc_call_credentials_unref(c); |
|
|
@ -418,7 +419,7 @@ static void test_channel_oauth2_composite_creds(void) { |
|
|
|
|
|
|
|
|
|
|
|
static void check_oauth2_google_iam_composite_metadata( |
|
|
|
static void check_oauth2_google_iam_composite_metadata( |
|
|
|
grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, |
|
|
|
grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, |
|
|
|
size_t num_md, grpc_credentials_status status) { |
|
|
|
size_t num_md, grpc_credentials_status status, const char *error_details) { |
|
|
|
grpc_call_credentials *c = (grpc_call_credentials *)user_data; |
|
|
|
grpc_call_credentials *c = (grpc_call_credentials *)user_data; |
|
|
|
expected_md emd[] = { |
|
|
|
expected_md emd[] = { |
|
|
|
{GRPC_AUTHORIZATION_METADATA_KEY, test_oauth2_bearer_token}, |
|
|
|
{GRPC_AUTHORIZATION_METADATA_KEY, test_oauth2_bearer_token}, |
|
|
@ -427,6 +428,7 @@ static void check_oauth2_google_iam_composite_metadata( |
|
|
|
{GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, |
|
|
|
{GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, |
|
|
|
test_google_iam_authority_selector}}; |
|
|
|
test_google_iam_authority_selector}}; |
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_OK); |
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_OK); |
|
|
|
|
|
|
|
GPR_ASSERT(error_details == NULL); |
|
|
|
GPR_ASSERT(num_md == 3); |
|
|
|
GPR_ASSERT(num_md == 3); |
|
|
|
check_metadata(emd, md_elems, num_md); |
|
|
|
check_metadata(emd, md_elems, num_md); |
|
|
|
grpc_call_credentials_unref(c); |
|
|
|
grpc_call_credentials_unref(c); |
|
|
@ -511,8 +513,9 @@ static void test_channel_oauth2_google_iam_composite_creds(void) { |
|
|
|
|
|
|
|
|
|
|
|
static void on_oauth2_creds_get_metadata_success( |
|
|
|
static void on_oauth2_creds_get_metadata_success( |
|
|
|
grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, |
|
|
|
grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, |
|
|
|
size_t num_md, grpc_credentials_status status) { |
|
|
|
size_t num_md, grpc_credentials_status status, const char *error_details) { |
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_OK); |
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_OK); |
|
|
|
|
|
|
|
GPR_ASSERT(error_details == NULL); |
|
|
|
GPR_ASSERT(num_md == 1); |
|
|
|
GPR_ASSERT(num_md == 1); |
|
|
|
GPR_ASSERT(gpr_slice_str_cmp(md_elems[0].key, "authorization") == 0); |
|
|
|
GPR_ASSERT(gpr_slice_str_cmp(md_elems[0].key, "authorization") == 0); |
|
|
|
GPR_ASSERT(gpr_slice_str_cmp(md_elems[0].value, |
|
|
|
GPR_ASSERT(gpr_slice_str_cmp(md_elems[0].value, |
|
|
@ -524,7 +527,7 @@ static void on_oauth2_creds_get_metadata_success( |
|
|
|
|
|
|
|
|
|
|
|
static void on_oauth2_creds_get_metadata_failure( |
|
|
|
static void on_oauth2_creds_get_metadata_failure( |
|
|
|
grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, |
|
|
|
grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, |
|
|
|
size_t num_md, grpc_credentials_status status) { |
|
|
|
size_t num_md, grpc_credentials_status status, const char *error_details) { |
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_ERROR); |
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_ERROR); |
|
|
|
GPR_ASSERT(num_md == 0); |
|
|
|
GPR_ASSERT(num_md == 0); |
|
|
|
GPR_ASSERT(user_data != NULL); |
|
|
|
GPR_ASSERT(user_data != NULL); |
|
|
@ -760,14 +763,13 @@ static char *encode_and_sign_jwt_should_not_be_called( |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void on_jwt_creds_get_metadata_success(grpc_exec_ctx *exec_ctx, |
|
|
|
static void on_jwt_creds_get_metadata_success( |
|
|
|
void *user_data, |
|
|
|
grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, |
|
|
|
grpc_credentials_md *md_elems, |
|
|
|
size_t num_md, grpc_credentials_status status, const char *error_details) { |
|
|
|
size_t num_md, |
|
|
|
|
|
|
|
grpc_credentials_status status) { |
|
|
|
|
|
|
|
char *expected_md_value; |
|
|
|
char *expected_md_value; |
|
|
|
gpr_asprintf(&expected_md_value, "Bearer %s", test_signed_jwt); |
|
|
|
gpr_asprintf(&expected_md_value, "Bearer %s", test_signed_jwt); |
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_OK); |
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_OK); |
|
|
|
|
|
|
|
GPR_ASSERT(error_details == NULL); |
|
|
|
GPR_ASSERT(num_md == 1); |
|
|
|
GPR_ASSERT(num_md == 1); |
|
|
|
GPR_ASSERT(gpr_slice_str_cmp(md_elems[0].key, "authorization") == 0); |
|
|
|
GPR_ASSERT(gpr_slice_str_cmp(md_elems[0].key, "authorization") == 0); |
|
|
|
GPR_ASSERT(gpr_slice_str_cmp(md_elems[0].value, expected_md_value) == 0); |
|
|
|
GPR_ASSERT(gpr_slice_str_cmp(md_elems[0].value, expected_md_value) == 0); |
|
|
@ -776,11 +778,9 @@ static void on_jwt_creds_get_metadata_success(grpc_exec_ctx *exec_ctx, |
|
|
|
gpr_free(expected_md_value); |
|
|
|
gpr_free(expected_md_value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void on_jwt_creds_get_metadata_failure(grpc_exec_ctx *exec_ctx, |
|
|
|
static void on_jwt_creds_get_metadata_failure( |
|
|
|
void *user_data, |
|
|
|
grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, |
|
|
|
grpc_credentials_md *md_elems, |
|
|
|
size_t num_md, grpc_credentials_status status, const char *error_details) { |
|
|
|
size_t num_md, |
|
|
|
|
|
|
|
grpc_credentials_status status) { |
|
|
|
|
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_ERROR); |
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_ERROR); |
|
|
|
GPR_ASSERT(num_md == 0); |
|
|
|
GPR_ASSERT(num_md == 0); |
|
|
|
GPR_ASSERT(user_data != NULL); |
|
|
|
GPR_ASSERT(user_data != NULL); |
|
|
@ -1024,6 +1024,8 @@ static void plugin_get_metadata_success(void *state, |
|
|
|
cb(user_data, md, GPR_ARRAY_SIZE(md), GRPC_STATUS_OK, NULL); |
|
|
|
cb(user_data, md, GPR_ARRAY_SIZE(md), GRPC_STATUS_OK, NULL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char *plugin_error_details = "Could not get metadata for plugin."; |
|
|
|
|
|
|
|
|
|
|
|
static void plugin_get_metadata_failure(void *state, |
|
|
|
static void plugin_get_metadata_failure(void *state, |
|
|
|
grpc_auth_metadata_context context, |
|
|
|
grpc_auth_metadata_context context, |
|
|
|
grpc_credentials_plugin_metadata_cb cb, |
|
|
|
grpc_credentials_plugin_metadata_cb cb, |
|
|
@ -1034,13 +1036,12 @@ static void plugin_get_metadata_failure(void *state, |
|
|
|
GPR_ASSERT(context.channel_auth_context == NULL); |
|
|
|
GPR_ASSERT(context.channel_auth_context == NULL); |
|
|
|
GPR_ASSERT(context.reserved == NULL); |
|
|
|
GPR_ASSERT(context.reserved == NULL); |
|
|
|
*s = PLUGIN_GET_METADATA_CALLED_STATE; |
|
|
|
*s = PLUGIN_GET_METADATA_CALLED_STATE; |
|
|
|
cb(user_data, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, |
|
|
|
cb(user_data, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, plugin_error_details); |
|
|
|
"Could not get metadata for plugin."); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void on_plugin_metadata_received_success( |
|
|
|
static void on_plugin_metadata_received_success( |
|
|
|
grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, |
|
|
|
grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, |
|
|
|
size_t num_md, grpc_credentials_status status) { |
|
|
|
size_t num_md, grpc_credentials_status status, const char *error_details) { |
|
|
|
size_t i = 0; |
|
|
|
size_t i = 0; |
|
|
|
GPR_ASSERT(user_data == NULL); |
|
|
|
GPR_ASSERT(user_data == NULL); |
|
|
|
GPR_ASSERT(md_elems != NULL); |
|
|
|
GPR_ASSERT(md_elems != NULL); |
|
|
@ -1053,11 +1054,13 @@ static void on_plugin_metadata_received_success( |
|
|
|
|
|
|
|
|
|
|
|
static void on_plugin_metadata_received_failure( |
|
|
|
static void on_plugin_metadata_received_failure( |
|
|
|
grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, |
|
|
|
grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, |
|
|
|
size_t num_md, grpc_credentials_status status) { |
|
|
|
size_t num_md, grpc_credentials_status status, const char *error_details) { |
|
|
|
GPR_ASSERT(user_data == NULL); |
|
|
|
GPR_ASSERT(user_data == NULL); |
|
|
|
GPR_ASSERT(md_elems == NULL); |
|
|
|
GPR_ASSERT(md_elems == NULL); |
|
|
|
GPR_ASSERT(num_md == 0); |
|
|
|
GPR_ASSERT(num_md == 0); |
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_ERROR); |
|
|
|
GPR_ASSERT(status == GRPC_CREDENTIALS_ERROR); |
|
|
|
|
|
|
|
GPR_ASSERT(error_details != NULL); |
|
|
|
|
|
|
|
GPR_ASSERT(strcmp(error_details, plugin_error_details) == 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void plugin_destroy(void *state) { |
|
|
|
static void plugin_destroy(void *state) { |
|
|
|