|
|
|
@ -1531,26 +1531,81 @@ static void test_google_default_creds_call_creds_specified(void) { |
|
|
|
|
nullptr, nullptr}; |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
grpc_flush_cached_google_default_credentials(); |
|
|
|
|
grpc_call_credentials* call_creds = grpc_google_compute_engine_credentials_create(nullptr); |
|
|
|
|
grpc_call_credentials* call_creds = |
|
|
|
|
grpc_google_compute_engine_credentials_create(nullptr); |
|
|
|
|
set_gce_tenancy_checker_for_testing(test_gce_tenancy_checker); |
|
|
|
|
g_test_gce_tenancy_checker_called = false; |
|
|
|
|
g_test_is_on_gce = true; |
|
|
|
|
grpc_httpcli_set_override( |
|
|
|
|
default_creds_metadata_server_detection_httpcli_get_success_override, |
|
|
|
|
httpcli_post_should_not_be_called); |
|
|
|
|
g_test_gce_tenancy_checker_called = false; |
|
|
|
|
g_test_is_on_gce = true; |
|
|
|
|
grpc_composite_channel_credentials* channel_creds = reinterpret_cast<grpc_composite_channel_credentials*>(grpc_google_default_credentials_create(call_creds)); |
|
|
|
|
grpc_composite_channel_credentials* channel_creds = |
|
|
|
|
reinterpret_cast<grpc_composite_channel_credentials*>( |
|
|
|
|
grpc_google_default_credentials_create(call_creds)); |
|
|
|
|
GPR_ASSERT(g_test_gce_tenancy_checker_called == true); |
|
|
|
|
GPR_ASSERT(channel_creds != nullptr); |
|
|
|
|
GPR_ASSERT(channel_creds->call_creds() != nullptr); |
|
|
|
|
grpc_httpcli_set_override(compute_engine_httpcli_get_success_override, |
|
|
|
|
httpcli_post_should_not_be_called); |
|
|
|
|
run_request_metadata_test(channel_creds->mutable_call_creds(), auth_md_ctx, state); |
|
|
|
|
run_request_metadata_test(channel_creds->mutable_call_creds(), auth_md_ctx, |
|
|
|
|
state); |
|
|
|
|
grpc_core::ExecCtx::Get()->Flush(); |
|
|
|
|
channel_creds->Unref(); |
|
|
|
|
grpc_httpcli_set_override(nullptr, nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: Test that we don't go down the nullptr path regardless of env vars.
|
|
|
|
|
struct fake_call_creds : public grpc_call_credentials { |
|
|
|
|
public: |
|
|
|
|
// TODO: Keep a single md_elem?
|
|
|
|
|
explicit fake_call_creds() : grpc_call_credentials("fake") {} |
|
|
|
|
|
|
|
|
|
bool get_request_metadata(grpc_polling_entity* pollent, |
|
|
|
|
grpc_auth_metadata_context context, |
|
|
|
|
grpc_credentials_mdelem_array* md_array, |
|
|
|
|
grpc_closure* on_request_metadata, |
|
|
|
|
grpc_error** error) { |
|
|
|
|
grpc_slice key = grpc_slice_from_static_string("foo"); |
|
|
|
|
grpc_slice value = grpc_slice_from_static_string("oof"); |
|
|
|
|
grpc_mdelem dummy_md = grpc_mdelem_from_slices(key, value); |
|
|
|
|
grpc_slice_unref(key); |
|
|
|
|
grpc_slice_unref(value); |
|
|
|
|
grpc_credentials_mdelem_array_add(md_array, dummy_md); |
|
|
|
|
GRPC_MDELEM_UNREF(dummy_md); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void cancel_get_request_metadata(grpc_credentials_mdelem_array* md_array, |
|
|
|
|
grpc_error* error) {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static void test_google_default_creds_not_default(void) { |
|
|
|
|
expected_md emd[] = {{"foo", "oof"}}; |
|
|
|
|
request_metadata_state* state = |
|
|
|
|
make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd)); |
|
|
|
|
grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method, |
|
|
|
|
nullptr, nullptr}; |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
grpc_flush_cached_google_default_credentials(); |
|
|
|
|
grpc_core::RefCountedPtr<grpc_call_credentials> call_creds = |
|
|
|
|
grpc_core::MakeRefCounted<fake_call_creds>(); |
|
|
|
|
set_gce_tenancy_checker_for_testing(test_gce_tenancy_checker); |
|
|
|
|
g_test_gce_tenancy_checker_called = false; |
|
|
|
|
g_test_is_on_gce = true; |
|
|
|
|
grpc_httpcli_set_override( |
|
|
|
|
default_creds_metadata_server_detection_httpcli_get_success_override, |
|
|
|
|
httpcli_post_should_not_be_called); |
|
|
|
|
grpc_composite_channel_credentials* channel_creds = |
|
|
|
|
reinterpret_cast<grpc_composite_channel_credentials*>( |
|
|
|
|
grpc_google_default_credentials_create(call_creds.release())); |
|
|
|
|
GPR_ASSERT(g_test_gce_tenancy_checker_called == true); |
|
|
|
|
GPR_ASSERT(channel_creds != nullptr); |
|
|
|
|
GPR_ASSERT(channel_creds->call_creds() != nullptr); |
|
|
|
|
run_request_metadata_test(channel_creds->mutable_call_creds(), auth_md_ctx, |
|
|
|
|
state); |
|
|
|
|
grpc_core::ExecCtx::Get()->Flush(); |
|
|
|
|
channel_creds->Unref(); |
|
|
|
|
grpc_httpcli_set_override(nullptr, nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
typedef enum { |
|
|
|
|
PLUGIN_INITIAL_STATE, |
|
|
|
@ -1862,6 +1917,7 @@ int main(int argc, char** argv) { |
|
|
|
|
test_google_default_creds_non_gce(); |
|
|
|
|
test_no_google_default_creds(); |
|
|
|
|
test_google_default_creds_call_creds_specified(); |
|
|
|
|
test_google_default_creds_not_default(); |
|
|
|
|
test_metadata_plugin_success(); |
|
|
|
|
test_metadata_plugin_failure(); |
|
|
|
|
test_get_well_known_google_credentials_file_path(); |
|
|
|
|