aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/security/credentials_test.cc
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2017-12-06 09:47:54 -0800
committerGravatar GitHub <noreply@github.com>2017-12-06 09:47:54 -0800
commit8cf1470a51ea276ca84825e7495d4ee24743540d (patch)
tree72385cc865094115bc08cb813201d48cb09840bb /test/core/security/credentials_test.cc
parent1d4e99508409be052bd129ba507bae1fbe7eb7fa (diff)
Revert "Revert "All instances of exec_ctx being passed around in src/core removed""
Diffstat (limited to 'test/core/security/credentials_test.cc')
-rw-r--r--test/core/security/credentials_test.cc303
1 files changed, 132 insertions, 171 deletions
diff --git a/test/core/security/credentials_test.cc b/test/core/security/credentials_test.cc
index 64d383ad0a..ecc61928f5 100644
--- a/test/core/security/credentials_test.cc
+++ b/test/core/security/credentials_test.cc
@@ -148,41 +148,37 @@ static grpc_httpcli_response http_response(int status, const char* body) {
/* -- Tests. -- */
static void test_empty_md_array(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_credentials_mdelem_array md_array;
memset(&md_array, 0, sizeof(md_array));
GPR_ASSERT(md_array.md == nullptr);
GPR_ASSERT(md_array.size == 0);
- grpc_credentials_mdelem_array_destroy(&exec_ctx, &md_array);
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_credentials_mdelem_array_destroy(&md_array);
}
static void test_add_to_empty_md_array(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_credentials_mdelem_array md_array;
memset(&md_array, 0, sizeof(md_array));
const char* key = "hello";
const char* value = "there blah blah blah blah blah blah blah";
- grpc_mdelem md =
- grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key),
- grpc_slice_from_copied_string(value));
+ grpc_mdelem md = grpc_mdelem_from_slices(
+ grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value));
grpc_credentials_mdelem_array_add(&md_array, md);
GPR_ASSERT(md_array.size == 1);
GPR_ASSERT(grpc_mdelem_eq(md, md_array.md[0]));
- GRPC_MDELEM_UNREF(&exec_ctx, md);
- grpc_credentials_mdelem_array_destroy(&exec_ctx, &md_array);
- grpc_exec_ctx_finish(&exec_ctx);
+ GRPC_MDELEM_UNREF(md);
+ grpc_credentials_mdelem_array_destroy(&md_array);
}
static void test_add_abunch_to_md_array(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_credentials_mdelem_array md_array;
memset(&md_array, 0, sizeof(md_array));
const char* key = "hello";
const char* value = "there blah blah blah blah blah blah blah";
- grpc_mdelem md =
- grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key),
- grpc_slice_from_copied_string(value));
+ grpc_mdelem md = grpc_mdelem_from_slices(
+ grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value));
size_t num_entries = 1000;
for (size_t i = 0; i < num_entries; ++i) {
grpc_credentials_mdelem_array_add(&md_array, md);
@@ -190,57 +186,52 @@ static void test_add_abunch_to_md_array(void) {
for (size_t i = 0; i < num_entries; ++i) {
GPR_ASSERT(grpc_mdelem_eq(md_array.md[i], md));
}
- GRPC_MDELEM_UNREF(&exec_ctx, md);
- grpc_credentials_mdelem_array_destroy(&exec_ctx, &md_array);
- grpc_exec_ctx_finish(&exec_ctx);
+ GRPC_MDELEM_UNREF(md);
+ grpc_credentials_mdelem_array_destroy(&md_array);
}
static void test_oauth2_token_fetcher_creds_parsing_ok(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_mdelem token_md = GRPC_MDNULL;
grpc_millis token_lifetime;
grpc_httpcli_response response =
http_response(200, valid_oauth2_json_response);
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
- &exec_ctx, &response, &token_md, &token_lifetime) ==
- GRPC_CREDENTIALS_OK);
+ &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_OK);
GPR_ASSERT(token_lifetime == 3599 * GPR_MS_PER_SEC);
GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(token_md), "authorization") == 0);
GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(token_md),
"Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_") ==
0);
- GRPC_MDELEM_UNREF(&exec_ctx, token_md);
+ GRPC_MDELEM_UNREF(token_md);
grpc_http_response_destroy(&response);
- grpc_exec_ctx_finish(&exec_ctx);
}
static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_mdelem token_md = GRPC_MDNULL;
grpc_millis token_lifetime;
grpc_httpcli_response response =
http_response(401, valid_oauth2_json_response);
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
- &exec_ctx, &response, &token_md, &token_lifetime) ==
+ &response, &token_md, &token_lifetime) ==
GRPC_CREDENTIALS_ERROR);
grpc_http_response_destroy(&response);
- grpc_exec_ctx_finish(&exec_ctx);
}
static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_mdelem token_md = GRPC_MDNULL;
grpc_millis token_lifetime;
grpc_httpcli_response response = http_response(200, "");
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
- &exec_ctx, &response, &token_md, &token_lifetime) ==
+ &response, &token_md, &token_lifetime) ==
GRPC_CREDENTIALS_ERROR);
grpc_http_response_destroy(&response);
- grpc_exec_ctx_finish(&exec_ctx);
}
static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_mdelem token_md = GRPC_MDNULL;
grpc_millis token_lifetime;
grpc_httpcli_response response =
@@ -249,14 +240,13 @@ static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) {
" \"expires_in\":3599, "
" \"token_type\":\"Bearer\"");
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
- &exec_ctx, &response, &token_md, &token_lifetime) ==
+ &response, &token_md, &token_lifetime) ==
GRPC_CREDENTIALS_ERROR);
grpc_http_response_destroy(&response);
- grpc_exec_ctx_finish(&exec_ctx);
}
static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_mdelem token_md = GRPC_MDNULL;
grpc_millis token_lifetime;
grpc_httpcli_response response = http_response(200,
@@ -264,14 +254,13 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) {
" \"expires_in\":3599, "
" \"token_type\":\"Bearer\"}");
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
- &exec_ctx, &response, &token_md, &token_lifetime) ==
+ &response, &token_md, &token_lifetime) ==
GRPC_CREDENTIALS_ERROR);
grpc_http_response_destroy(&response);
- grpc_exec_ctx_finish(&exec_ctx);
}
static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_mdelem token_md = GRPC_MDNULL;
grpc_millis token_lifetime;
grpc_httpcli_response response =
@@ -280,15 +269,14 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) {
" \"expires_in\":3599, "
"}");
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
- &exec_ctx, &response, &token_md, &token_lifetime) ==
+ &response, &token_md, &token_lifetime) ==
GRPC_CREDENTIALS_ERROR);
grpc_http_response_destroy(&response);
- grpc_exec_ctx_finish(&exec_ctx);
}
static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime(
void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_mdelem token_md = GRPC_MDNULL;
grpc_millis token_lifetime;
grpc_httpcli_response response =
@@ -296,10 +284,9 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime(
"{\"access_token\":\"ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_\","
" \"token_type\":\"Bearer\"}");
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
- &exec_ctx, &response, &token_md, &token_lifetime) ==
+ &response, &token_md, &token_lifetime) ==
GRPC_CREDENTIALS_ERROR);
grpc_http_response_destroy(&response);
- grpc_exec_ctx_finish(&exec_ctx);
}
typedef struct {
@@ -336,8 +323,7 @@ static void check_metadata(const expected_md* expected,
}
}
-static void check_request_metadata(grpc_exec_ctx* exec_ctx, void* arg,
- grpc_error* error) {
+static void check_request_metadata(void* arg, grpc_error* error) {
request_metadata_state* state = (request_metadata_state*)arg;
gpr_log(GPR_INFO, "expected_error: %s",
grpc_error_string(state->expected_error));
@@ -358,9 +344,8 @@ static void check_request_metadata(grpc_exec_ctx* exec_ctx, void* arg,
state->expected_size, state->md_array.size);
GPR_ASSERT(state->md_array.size == state->expected_size);
check_metadata(state->expected, &state->md_array);
- grpc_credentials_mdelem_array_destroy(exec_ctx, &state->md_array);
- grpc_pollset_set_destroy(exec_ctx,
- grpc_polling_entity_pollset_set(&state->pollent));
+ grpc_credentials_mdelem_array_destroy(&state->md_array);
+ grpc_pollset_set_destroy(grpc_polling_entity_pollset_set(&state->pollent));
gpr_free(state);
}
@@ -379,22 +364,21 @@ static request_metadata_state* make_request_metadata_state(
return state;
}
-static void run_request_metadata_test(grpc_exec_ctx* exec_ctx,
- grpc_call_credentials* creds,
+static void run_request_metadata_test(grpc_call_credentials* creds,
grpc_auth_metadata_context auth_md_ctx,
request_metadata_state* state) {
grpc_error* error = GRPC_ERROR_NONE;
if (grpc_call_credentials_get_request_metadata(
- exec_ctx, creds, &state->pollent, auth_md_ctx, &state->md_array,
+ creds, &state->pollent, auth_md_ctx, &state->md_array,
&state->on_request_metadata, &error)) {
// Synchronous result. Invoke the callback directly.
- check_request_metadata(exec_ctx, state, error);
+ check_request_metadata(state, error);
GRPC_ERROR_UNREF(error);
}
}
static void test_google_iam_creds(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
expected_md emd[] = {{GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY,
test_google_iam_authorization_token},
{GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY,
@@ -406,13 +390,12 @@ static void test_google_iam_creds(void) {
nullptr);
grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method,
nullptr, nullptr};
- run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state);
- grpc_call_credentials_unref(&exec_ctx, creds);
- grpc_exec_ctx_finish(&exec_ctx);
+ run_request_metadata_test(creds, auth_md_ctx, state);
+ grpc_call_credentials_unref(creds);
}
static void test_access_token_creds(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
expected_md emd[] = {{GRPC_AUTHORIZATION_METADATA_KEY, "Bearer blah"}};
request_metadata_state* state =
make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd));
@@ -421,16 +404,14 @@ static void test_access_token_creds(void) {
grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method,
nullptr, nullptr};
GPR_ASSERT(strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0);
- run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state);
- grpc_call_credentials_unref(&exec_ctx, creds);
- grpc_exec_ctx_finish(&exec_ctx);
+ run_request_metadata_test(creds, auth_md_ctx, state);
+ grpc_call_credentials_unref(creds);
}
static grpc_security_status check_channel_oauth2_create_security_connector(
- grpc_exec_ctx* exec_ctx, grpc_channel_credentials* c,
- grpc_call_credentials* call_creds, const char* target,
- const grpc_channel_args* args, grpc_channel_security_connector** sc,
- grpc_channel_args** new_args) {
+ grpc_channel_credentials* c, grpc_call_credentials* call_creds,
+ const char* target, const grpc_channel_args* args,
+ grpc_channel_security_connector** sc, grpc_channel_args** new_args) {
GPR_ASSERT(strcmp(c->type, "mock") == 0);
GPR_ASSERT(call_creds != nullptr);
GPR_ASSERT(strcmp(call_creds->type, GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0);
@@ -438,7 +419,7 @@ static grpc_security_status check_channel_oauth2_create_security_connector(
}
static void test_channel_oauth2_composite_creds(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_channel_args* new_args;
grpc_channel_credentials_vtable vtable = {
nullptr, check_channel_oauth2_create_security_connector, nullptr};
@@ -452,14 +433,13 @@ static void test_channel_oauth2_composite_creds(void) {
grpc_channel_credentials_release(channel_creds);
grpc_call_credentials_release(oauth2_creds);
GPR_ASSERT(grpc_channel_credentials_create_security_connector(
- &exec_ctx, channel_oauth2_creds, nullptr, nullptr, nullptr,
- &new_args) == GRPC_SECURITY_OK);
+ channel_oauth2_creds, nullptr, nullptr, nullptr, &new_args) ==
+ GRPC_SECURITY_OK);
grpc_channel_credentials_release(channel_oauth2_creds);
- grpc_exec_ctx_finish(&exec_ctx);
}
static void test_oauth2_google_iam_composite_creds(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
expected_md emd[] = {
{GRPC_AUTHORIZATION_METADATA_KEY, test_oauth2_bearer_token},
{GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY,
@@ -471,15 +451,15 @@ static void test_oauth2_google_iam_composite_creds(void) {
grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method,
nullptr, nullptr};
grpc_call_credentials* oauth2_creds = grpc_md_only_test_credentials_create(
- &exec_ctx, "authorization", test_oauth2_bearer_token, 0);
+ "authorization", test_oauth2_bearer_token, 0);
grpc_call_credentials* google_iam_creds = grpc_google_iam_credentials_create(
test_google_iam_authorization_token, test_google_iam_authority_selector,
nullptr);
grpc_call_credentials* composite_creds =
grpc_composite_call_credentials_create(oauth2_creds, google_iam_creds,
nullptr);
- grpc_call_credentials_unref(&exec_ctx, oauth2_creds);
- grpc_call_credentials_unref(&exec_ctx, google_iam_creds);
+ grpc_call_credentials_unref(oauth2_creds);
+ grpc_call_credentials_unref(google_iam_creds);
GPR_ASSERT(
strcmp(composite_creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0);
const grpc_call_credentials_array* creds_array =
@@ -489,17 +469,15 @@ static void test_oauth2_google_iam_composite_creds(void) {
GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0);
GPR_ASSERT(strcmp(creds_array->creds_array[1]->type,
GRPC_CALL_CREDENTIALS_TYPE_IAM) == 0);
- run_request_metadata_test(&exec_ctx, composite_creds, auth_md_ctx, state);
- grpc_call_credentials_unref(&exec_ctx, composite_creds);
- grpc_exec_ctx_finish(&exec_ctx);
+ run_request_metadata_test(composite_creds, auth_md_ctx, state);
+ grpc_call_credentials_unref(composite_creds);
}
static grpc_security_status
check_channel_oauth2_google_iam_create_security_connector(
- grpc_exec_ctx* exec_ctx, grpc_channel_credentials* c,
- grpc_call_credentials* call_creds, const char* target,
- const grpc_channel_args* args, grpc_channel_security_connector** sc,
- grpc_channel_args** new_args) {
+ grpc_channel_credentials* c, grpc_call_credentials* call_creds,
+ const char* target, const grpc_channel_args* args,
+ grpc_channel_security_connector** sc, grpc_channel_args** new_args) {
const grpc_call_credentials_array* creds_array;
GPR_ASSERT(strcmp(c->type, "mock") == 0);
GPR_ASSERT(call_creds != nullptr);
@@ -514,7 +492,7 @@ check_channel_oauth2_google_iam_create_security_connector(
}
static void test_channel_oauth2_google_iam_composite_creds(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_channel_args* new_args;
grpc_channel_credentials_vtable vtable = {
nullptr, check_channel_oauth2_google_iam_create_security_connector,
@@ -538,11 +516,10 @@ static void test_channel_oauth2_google_iam_composite_creds(void) {
grpc_call_credentials_release(google_iam_creds);
GPR_ASSERT(grpc_channel_credentials_create_security_connector(
- &exec_ctx, channel_oauth2_iam_creds, nullptr, nullptr, nullptr,
+ channel_oauth2_iam_creds, nullptr, nullptr, nullptr,
&new_args) == GRPC_SECURITY_OK);
grpc_channel_credentials_release(channel_oauth2_iam_creds);
- grpc_exec_ctx_finish(&exec_ctx);
}
static void validate_compute_engine_http_request(
@@ -559,35 +536,32 @@ static void validate_compute_engine_http_request(
}
static int compute_engine_httpcli_get_success_override(
- grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request,
- grpc_millis deadline, grpc_closure* on_done,
- grpc_httpcli_response* response) {
+ const grpc_httpcli_request* request, grpc_millis deadline,
+ grpc_closure* on_done, grpc_httpcli_response* response) {
validate_compute_engine_http_request(request);
*response = http_response(200, valid_oauth2_json_response);
- GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE);
return 1;
}
static int compute_engine_httpcli_get_failure_override(
- grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request,
- grpc_millis deadline, grpc_closure* on_done,
- grpc_httpcli_response* response) {
+ const grpc_httpcli_request* request, grpc_millis deadline,
+ grpc_closure* on_done, grpc_httpcli_response* response) {
validate_compute_engine_http_request(request);
*response = http_response(403, "Not Authorized.");
- GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE);
return 1;
}
static int httpcli_post_should_not_be_called(
- grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request,
- const char* body_bytes, size_t body_size, grpc_millis deadline,
- grpc_closure* on_done, grpc_httpcli_response* response) {
+ const grpc_httpcli_request* request, const char* body_bytes,
+ size_t body_size, grpc_millis deadline, grpc_closure* on_done,
+ grpc_httpcli_response* response) {
GPR_ASSERT("HTTP POST should not be called" == nullptr);
return 1;
}
-static int httpcli_get_should_not_be_called(grpc_exec_ctx* exec_ctx,
- const grpc_httpcli_request* request,
+static int httpcli_get_should_not_be_called(const grpc_httpcli_request* request,
grpc_millis deadline,
grpc_closure* on_done,
grpc_httpcli_response* response) {
@@ -596,7 +570,7 @@ static int httpcli_get_should_not_be_called(grpc_exec_ctx* exec_ctx,
}
static void test_compute_engine_creds_success(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
expected_md emd[] = {
{"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}};
grpc_call_credentials* creds =
@@ -609,24 +583,23 @@ static void test_compute_engine_creds_success(void) {
make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd));
grpc_httpcli_set_override(compute_engine_httpcli_get_success_override,
httpcli_post_should_not_be_called);
- run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state);
- grpc_exec_ctx_flush(&exec_ctx);
+ run_request_metadata_test(creds, auth_md_ctx, state);
+ grpc_core::ExecCtx::Get()->Flush();
/* Second request: the cached token should be served directly. */
state =
make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd));
grpc_httpcli_set_override(httpcli_get_should_not_be_called,
httpcli_post_should_not_be_called);
- run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state);
- grpc_exec_ctx_flush(&exec_ctx);
+ run_request_metadata_test(creds, auth_md_ctx, state);
+ grpc_core::ExecCtx::Get()->Flush();
- grpc_call_credentials_unref(&exec_ctx, creds);
+ grpc_call_credentials_unref(creds);
grpc_httpcli_set_override(nullptr, nullptr);
- grpc_exec_ctx_finish(&exec_ctx);
}
static void test_compute_engine_creds_failure(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
request_metadata_state* state = make_request_metadata_state(
GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Error occured when fetching oauth2 token."),
@@ -637,10 +610,9 @@ static void test_compute_engine_creds_failure(void) {
grpc_google_compute_engine_credentials_create(nullptr);
grpc_httpcli_set_override(compute_engine_httpcli_get_failure_override,
httpcli_post_should_not_be_called);
- run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state);
- grpc_call_credentials_unref(&exec_ctx, creds);
+ run_request_metadata_test(creds, auth_md_ctx, state);
+ grpc_call_credentials_unref(creds);
grpc_httpcli_set_override(nullptr, nullptr);
- grpc_exec_ctx_finish(&exec_ctx);
}
static void validate_refresh_token_http_request(
@@ -667,27 +639,27 @@ static void validate_refresh_token_http_request(
}
static int refresh_token_httpcli_post_success(
- grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request,
- const char* body, size_t body_size, grpc_millis deadline,
- grpc_closure* on_done, grpc_httpcli_response* response) {
+ const grpc_httpcli_request* request, const char* body, size_t body_size,
+ grpc_millis deadline, grpc_closure* on_done,
+ grpc_httpcli_response* response) {
validate_refresh_token_http_request(request, body, body_size);
*response = http_response(200, valid_oauth2_json_response);
- GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE);
return 1;
}
static int refresh_token_httpcli_post_failure(
- grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request,
- const char* body, size_t body_size, grpc_millis deadline,
- grpc_closure* on_done, grpc_httpcli_response* response) {
+ const grpc_httpcli_request* request, const char* body, size_t body_size,
+ grpc_millis deadline, grpc_closure* on_done,
+ grpc_httpcli_response* response) {
validate_refresh_token_http_request(request, body, body_size);
*response = http_response(403, "Not Authorized.");
- GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE);
return 1;
}
static void test_refresh_token_creds_success(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
expected_md emd[] = {
{"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}};
grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method,
@@ -700,24 +672,23 @@ static void test_refresh_token_creds_success(void) {
make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd));
grpc_httpcli_set_override(httpcli_get_should_not_be_called,
refresh_token_httpcli_post_success);
- run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state);
- grpc_exec_ctx_flush(&exec_ctx);
+ run_request_metadata_test(creds, auth_md_ctx, state);
+ grpc_core::ExecCtx::Get()->Flush();
/* Second request: the cached token should be served directly. */
state =
make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd));
grpc_httpcli_set_override(httpcli_get_should_not_be_called,
httpcli_post_should_not_be_called);
- run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state);
- grpc_exec_ctx_flush(&exec_ctx);
+ run_request_metadata_test(creds, auth_md_ctx, state);
+ grpc_core::ExecCtx::Get()->Flush();
- grpc_call_credentials_unref(&exec_ctx, creds);
+ grpc_call_credentials_unref(creds);
grpc_httpcli_set_override(nullptr, nullptr);
- grpc_exec_ctx_finish(&exec_ctx);
}
static void test_refresh_token_creds_failure(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
request_metadata_state* state = make_request_metadata_state(
GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Error occured when fetching oauth2 token."),
@@ -728,10 +699,9 @@ static void test_refresh_token_creds_failure(void) {
test_refresh_token_str, nullptr);
grpc_httpcli_set_override(httpcli_get_should_not_be_called,
refresh_token_httpcli_post_failure);
- run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state);
- grpc_call_credentials_unref(&exec_ctx, creds);
+ run_request_metadata_test(creds, auth_md_ctx, state);
+ grpc_call_credentials_unref(creds);
grpc_httpcli_set_override(nullptr, nullptr);
- grpc_exec_ctx_finish(&exec_ctx);
}
static void validate_jwt_encode_and_sign_params(
@@ -821,7 +791,7 @@ static void test_jwt_creds_lifetime(void) {
static void test_jwt_creds_success(void) {
char* json_key_string = test_json_key_str();
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method,
nullptr, nullptr};
char* expected_md_value;
@@ -835,16 +805,16 @@ static void test_jwt_creds_success(void) {
request_metadata_state* state =
make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd));
grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success);
- run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state);
- grpc_exec_ctx_flush(&exec_ctx);
+ run_request_metadata_test(creds, auth_md_ctx, state);
+ grpc_core::ExecCtx::Get()->Flush();
/* Second request: the cached token should be served directly. */
state =
make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd));
grpc_jwt_encode_and_sign_set_override(
encode_and_sign_jwt_should_not_be_called);
- run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state);
- grpc_exec_ctx_flush(&exec_ctx);
+ run_request_metadata_test(creds, auth_md_ctx, state);
+ grpc_core::ExecCtx::Get()->Flush();
/* Third request: Different service url so jwt_encode_and_sign should be
called again (no caching). */
@@ -852,19 +822,18 @@ static void test_jwt_creds_success(void) {
make_request_metadata_state(GRPC_ERROR_NONE, emd, GPR_ARRAY_SIZE(emd));
auth_md_ctx.service_url = other_test_service_url;
grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success);
- run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state);
- grpc_exec_ctx_flush(&exec_ctx);
+ run_request_metadata_test(creds, auth_md_ctx, state);
+ grpc_core::ExecCtx::Get()->Flush();
- grpc_call_credentials_unref(&exec_ctx, creds);
+ grpc_call_credentials_unref(creds);
gpr_free(json_key_string);
gpr_free(expected_md_value);
grpc_jwt_encode_and_sign_set_override(nullptr);
- grpc_exec_ctx_finish(&exec_ctx);
}
static void test_jwt_creds_signing_failure(void) {
char* json_key_string = test_json_key_str();
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method,
nullptr, nullptr};
request_metadata_state* state = make_request_metadata_state(
@@ -875,12 +844,11 @@ static void test_jwt_creds_signing_failure(void) {
json_key_string, grpc_max_auth_token_lifetime(), nullptr);
grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_failure);
- run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, state);
+ run_request_metadata_test(creds, auth_md_ctx, state);
gpr_free(json_key_string);
- grpc_call_credentials_unref(&exec_ctx, creds);
+ grpc_call_credentials_unref(creds);
grpc_jwt_encode_and_sign_set_override(nullptr);
- grpc_exec_ctx_finish(&exec_ctx);
}
static void set_google_default_creds_env_var_with_file_contents(
@@ -897,7 +865,7 @@ static void set_google_default_creds_env_var_with_file_contents(
}
static void test_google_default_creds_auth_key(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_service_account_jwt_access_credentials* jwt;
grpc_composite_channel_credentials* creds;
char* json_key = test_json_key_str();
@@ -913,13 +881,12 @@ static void test_google_default_creds_auth_key(void) {
strcmp(jwt->key.client_id,
"777-abaslkan11hlb6nmim3bpspl31ud.apps.googleusercontent.com") ==
0);
- grpc_channel_credentials_unref(&exec_ctx, &creds->base);
+ grpc_channel_credentials_unref(&creds->base);
gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */
- grpc_exec_ctx_finish(&exec_ctx);
}
static void test_google_default_creds_refresh_token(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_google_refresh_token_credentials* refresh;
grpc_composite_channel_credentials* creds;
grpc_flush_cached_google_default_credentials();
@@ -931,15 +898,13 @@ static void test_google_default_creds_refresh_token(void) {
refresh = (grpc_google_refresh_token_credentials*)creds->call_creds;
GPR_ASSERT(strcmp(refresh->refresh_token.client_id,
"32555999999.apps.googleusercontent.com") == 0);
- grpc_channel_credentials_unref(&exec_ctx, &creds->base);
+ grpc_channel_credentials_unref(&creds->base);
gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */
- grpc_exec_ctx_finish(&exec_ctx);
}
static int default_creds_gce_detection_httpcli_get_success_override(
- grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request,
- grpc_millis deadline, grpc_closure* on_done,
- grpc_httpcli_response* response) {
+ const grpc_httpcli_request* request, grpc_millis deadline,
+ grpc_closure* on_done, grpc_httpcli_response* response) {
*response = http_response(200, "");
grpc_http_header* headers =
static_cast<grpc_http_header*>(gpr_malloc(sizeof(*headers) * 1));
@@ -949,14 +914,14 @@ static int default_creds_gce_detection_httpcli_get_success_override(
response->hdrs = headers;
GPR_ASSERT(strcmp(request->http.path, "/") == 0);
GPR_ASSERT(strcmp(request->host, "metadata.google.internal") == 0);
- GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE);
return 1;
}
static char* null_well_known_creds_path_getter(void) { return nullptr; }
static void test_google_default_creds_gce(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
expected_md emd[] = {
{"authorization", "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_"}};
request_metadata_state* state =
@@ -981,8 +946,8 @@ static void test_google_default_creds_gce(void) {
GPR_ASSERT(creds->call_creds != nullptr);
grpc_httpcli_set_override(compute_engine_httpcli_get_success_override,
httpcli_post_should_not_be_called);
- run_request_metadata_test(&exec_ctx, creds->call_creds, auth_md_ctx, state);
- grpc_exec_ctx_flush(&exec_ctx);
+ run_request_metadata_test(creds->call_creds, auth_md_ctx, state);
+ grpc_core::ExecCtx::Get()->Flush();
/* Check that we get a cached creds if we call
grpc_google_default_credentials_create again.
@@ -994,22 +959,20 @@ static void test_google_default_creds_gce(void) {
GPR_ASSERT(cached_creds == &creds->base);
/* Cleanup. */
- grpc_channel_credentials_unref(&exec_ctx, cached_creds);
- grpc_channel_credentials_unref(&exec_ctx, &creds->base);
+ grpc_channel_credentials_unref(cached_creds);
+ grpc_channel_credentials_unref(&creds->base);
grpc_httpcli_set_override(nullptr, nullptr);
grpc_override_well_known_credentials_path_getter(nullptr);
- grpc_exec_ctx_finish(&exec_ctx);
}
static int default_creds_gce_detection_httpcli_get_failure_override(
- grpc_exec_ctx* exec_ctx, const grpc_httpcli_request* request,
- grpc_millis deadline, grpc_closure* on_done,
- grpc_httpcli_response* response) {
+ const grpc_httpcli_request* request, grpc_millis deadline,
+ grpc_closure* on_done, grpc_httpcli_response* response) {
/* No magic header. */
GPR_ASSERT(strcmp(request->http.path, "/") == 0);
GPR_ASSERT(strcmp(request->host, "metadata.google.internal") == 0);
*response = http_response(200, "");
- GRPC_CLOSURE_SCHED(exec_ctx, on_done, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE);
return 1;
}
@@ -1093,7 +1056,7 @@ static void plugin_destroy(void* state) {
static void test_metadata_plugin_success(void) {
plugin_state state = PLUGIN_INITIAL_STATE;
grpc_metadata_credentials_plugin plugin;
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method,
nullptr, nullptr};
request_metadata_state* md_state = make_request_metadata_state(
@@ -1106,17 +1069,17 @@ static void test_metadata_plugin_success(void) {
grpc_call_credentials* creds =
grpc_metadata_credentials_create_from_plugin(plugin, nullptr);
GPR_ASSERT(state == PLUGIN_INITIAL_STATE);
- run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, md_state);
+ run_request_metadata_test(creds, auth_md_ctx, md_state);
GPR_ASSERT(state == PLUGIN_GET_METADATA_CALLED_STATE);
- grpc_call_credentials_unref(&exec_ctx, creds);
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_call_credentials_unref(creds);
+
GPR_ASSERT(state == PLUGIN_DESTROY_CALLED_STATE);
}
static void test_metadata_plugin_failure(void) {
plugin_state state = PLUGIN_INITIAL_STATE;
grpc_metadata_credentials_plugin plugin;
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_auth_metadata_context auth_md_ctx = {test_service_url, test_method,
nullptr, nullptr};
char* expected_error;
@@ -1134,10 +1097,10 @@ static void test_metadata_plugin_failure(void) {
grpc_call_credentials* creds =
grpc_metadata_credentials_create_from_plugin(plugin, nullptr);
GPR_ASSERT(state == PLUGIN_INITIAL_STATE);
- run_request_metadata_test(&exec_ctx, creds, auth_md_ctx, md_state);
+ run_request_metadata_test(creds, auth_md_ctx, md_state);
GPR_ASSERT(state == PLUGIN_GET_METADATA_CALLED_STATE);
- grpc_call_credentials_unref(&exec_ctx, creds);
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_call_credentials_unref(creds);
+
GPR_ASSERT(state == PLUGIN_DESTROY_CALLED_STATE);
}
@@ -1158,7 +1121,7 @@ static void test_get_well_known_google_credentials_file_path(void) {
}
static void test_channel_creds_duplicate_without_call_creds(void) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_core::ExecCtx exec_ctx;
grpc_channel_credentials* channel_creds =
grpc_fake_transport_security_credentials_create();
@@ -1167,23 +1130,21 @@ static void test_channel_creds_duplicate_without_call_creds(void) {
grpc_channel_credentials_duplicate_without_call_credentials(
channel_creds);
GPR_ASSERT(dup == channel_creds);
- grpc_channel_credentials_unref(&exec_ctx, dup);
+ grpc_channel_credentials_unref(dup);
grpc_call_credentials* call_creds =
grpc_access_token_credentials_create("blah", nullptr);
grpc_channel_credentials* composite_creds =
grpc_composite_channel_credentials_create(channel_creds, call_creds,
nullptr);
- grpc_call_credentials_unref(&exec_ctx, call_creds);
+ grpc_call_credentials_unref(call_creds);
dup = grpc_channel_credentials_duplicate_without_call_credentials(
composite_creds);
GPR_ASSERT(dup == channel_creds);
- grpc_channel_credentials_unref(&exec_ctx, dup);
-
- grpc_channel_credentials_unref(&exec_ctx, channel_creds);
- grpc_channel_credentials_unref(&exec_ctx, composite_creds);
+ grpc_channel_credentials_unref(dup);
- grpc_exec_ctx_finish(&exec_ctx);
+ grpc_channel_credentials_unref(channel_creds);
+ grpc_channel_credentials_unref(composite_creds);
}
typedef struct {