aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/security
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2017-11-28 13:23:36 -0800
committerGravatar Yash Tibrewal <yashkt@google.com>2017-11-28 13:23:36 -0800
commit81fc8c9c336fab7a71b448f748a32d680301277c (patch)
tree5cd64fd191db0f87d59ef53768c1b6760b4f1654 /test/core/security
parent3285f4c7329bf4305133be74f88dd4b10d5e2052 (diff)
Fix tests to call grpc_init and grpc_shutdown before using exec_ctx
Diffstat (limited to 'test/core/security')
-rw-r--r--test/core/security/json_token_test.cc2
-rw-r--r--test/core/security/secure_endpoint_test.cc24
-rw-r--r--test/core/security/ssl_server_fuzzer.cc115
3 files changed, 75 insertions, 66 deletions
diff --git a/test/core/security/json_token_test.cc b/test/core/security/json_token_test.cc
index b717de06d9..57e2f4c978 100644
--- a/test/core/security/json_token_test.cc
+++ b/test/core/security/json_token_test.cc
@@ -483,6 +483,7 @@ static void test_parse_refresh_token_failure_no_refresh_token(void) {
int main(int argc, char** argv) {
grpc_test_init(argc, argv);
+ grpc_init();
test_parse_json_key_success();
test_parse_json_key_failure_bad_json();
test_parse_json_key_failure_no_type();
@@ -497,5 +498,6 @@ int main(int argc, char** argv) {
test_parse_refresh_token_failure_no_client_id();
test_parse_refresh_token_failure_no_client_secret();
test_parse_refresh_token_failure_no_refresh_token();
+ grpc_shutdown();
return 0;
}
diff --git a/test/core/security/secure_endpoint_test.cc b/test/core/security/secure_endpoint_test.cc
index 694a8584ea..c8f4f32538 100644
--- a/test/core/security/secure_endpoint_test.cc
+++ b/test/core/security/secure_endpoint_test.cc
@@ -205,19 +205,21 @@ static void destroy_pollset(void* p, grpc_error* error) {
int main(int argc, char** argv) {
grpc_closure destroyed;
- grpc_core::ExecCtx _local_exec_ctx;
grpc_test_init(argc, argv);
-
grpc_init();
- g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size());
- grpc_pollset_init(g_pollset, &g_mu);
- grpc_endpoint_tests(configs[0], g_pollset, g_mu);
- grpc_endpoint_tests(configs[1], g_pollset, g_mu);
- test_leftover(configs[2], 1);
- test_leftover(configs[3], 1);
- GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset,
- grpc_schedule_on_exec_ctx);
- grpc_pollset_shutdown(g_pollset, &destroyed);
+
+ {
+ grpc_core::ExecCtx _local_exec_ctx;
+ g_pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size());
+ grpc_pollset_init(g_pollset, &g_mu);
+ grpc_endpoint_tests(configs[0], g_pollset, g_mu);
+ grpc_endpoint_tests(configs[1], g_pollset, g_mu);
+ test_leftover(configs[2], 1);
+ test_leftover(configs[3], 1);
+ GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset,
+ grpc_schedule_on_exec_ctx);
+ grpc_pollset_shutdown(g_pollset, &destroyed);
+ }
grpc_shutdown();
diff --git a/test/core/security/ssl_server_fuzzer.cc b/test/core/security/ssl_server_fuzzer.cc
index df62dc17b8..9cf73fa871 100644
--- a/test/core/security/ssl_server_fuzzer.cc
+++ b/test/core/security/ssl_server_fuzzer.cc
@@ -55,63 +55,68 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (squelch) gpr_set_log_function(dont_log);
if (leak_check) grpc_memory_counters_init();
grpc_init();
- grpc_core::ExecCtx _local_exec_ctx;
-
- grpc_resource_quota* resource_quota =
- grpc_resource_quota_create("ssl_server_fuzzer");
- grpc_endpoint* mock_endpoint =
- grpc_mock_endpoint_create(discard_write, resource_quota);
- grpc_resource_quota_unref_internal(resource_quota);
-
- grpc_mock_endpoint_put_read(
- mock_endpoint, grpc_slice_from_copied_buffer((const char*)data, size));
-
- // Load key pair and establish server SSL credentials.
- grpc_ssl_pem_key_cert_pair pem_key_cert_pair;
- grpc_slice ca_slice, cert_slice, key_slice;
- ca_slice = grpc_slice_from_static_string(test_root_cert);
- cert_slice = grpc_slice_from_static_string(test_server1_cert);
- key_slice = grpc_slice_from_static_string(test_server1_key);
- const char* ca_cert = (const char*)GRPC_SLICE_START_PTR(ca_slice);
- pem_key_cert_pair.private_key = (const char*)GRPC_SLICE_START_PTR(key_slice);
- pem_key_cert_pair.cert_chain = (const char*)GRPC_SLICE_START_PTR(cert_slice);
- grpc_server_credentials* creds = grpc_ssl_server_credentials_create(
- ca_cert, &pem_key_cert_pair, 1, 0, nullptr);
-
- // Create security connector
- grpc_server_security_connector* sc = nullptr;
- grpc_security_status status =
- grpc_server_credentials_create_security_connector(creds, &sc);
- GPR_ASSERT(status == GRPC_SECURITY_OK);
- grpc_millis deadline = GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now();
-
- struct handshake_state state;
- state.done_callback_called = false;
- grpc_handshake_manager* handshake_mgr = grpc_handshake_manager_create();
- grpc_server_security_connector_add_handshakers(sc, handshake_mgr);
- grpc_handshake_manager_do_handshake(
- handshake_mgr, mock_endpoint, nullptr /* channel_args */, deadline,
- nullptr /* acceptor */, on_handshake_done, &state);
- grpc_core::ExecCtx::Get()->Flush();
-
- // If the given string happens to be part of the correct client hello, the
- // server will wait for more data. Explicitly fail the server by shutting down
- // the endpoint.
- if (!state.done_callback_called) {
- grpc_endpoint_shutdown(
- mock_endpoint, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Explicit close"));
+ {
+ grpc_core::ExecCtx _local_exec_ctx;
+
+ grpc_resource_quota* resource_quota =
+ grpc_resource_quota_create("ssl_server_fuzzer");
+ grpc_endpoint* mock_endpoint =
+ grpc_mock_endpoint_create(discard_write, resource_quota);
+ grpc_resource_quota_unref_internal(resource_quota);
+
+ grpc_mock_endpoint_put_read(
+ mock_endpoint, grpc_slice_from_copied_buffer((const char*)data, size));
+
+ // Load key pair and establish server SSL credentials.
+ grpc_ssl_pem_key_cert_pair pem_key_cert_pair;
+ grpc_slice ca_slice, cert_slice, key_slice;
+ ca_slice = grpc_slice_from_static_string(test_root_cert);
+ cert_slice = grpc_slice_from_static_string(test_server1_cert);
+ key_slice = grpc_slice_from_static_string(test_server1_key);
+ const char* ca_cert = (const char*)GRPC_SLICE_START_PTR(ca_slice);
+ pem_key_cert_pair.private_key =
+ (const char*)GRPC_SLICE_START_PTR(key_slice);
+ pem_key_cert_pair.cert_chain =
+ (const char*)GRPC_SLICE_START_PTR(cert_slice);
+ grpc_server_credentials* creds = grpc_ssl_server_credentials_create(
+ ca_cert, &pem_key_cert_pair, 1, 0, nullptr);
+
+ // Create security connector
+ grpc_server_security_connector* sc = nullptr;
+ grpc_security_status status =
+ grpc_server_credentials_create_security_connector(creds, &sc);
+ GPR_ASSERT(status == GRPC_SECURITY_OK);
+ grpc_millis deadline = GPR_MS_PER_SEC + grpc_core::ExecCtx::Get()->Now();
+
+ struct handshake_state state;
+ state.done_callback_called = false;
+ grpc_handshake_manager* handshake_mgr = grpc_handshake_manager_create();
+ grpc_server_security_connector_add_handshakers(sc, handshake_mgr);
+ grpc_handshake_manager_do_handshake(
+ handshake_mgr, mock_endpoint, nullptr /* channel_args */, deadline,
+ nullptr /* acceptor */, on_handshake_done, &state);
grpc_core::ExecCtx::Get()->Flush();
- }
-
- GPR_ASSERT(state.done_callback_called);
- grpc_handshake_manager_destroy(handshake_mgr);
- GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "test");
- grpc_server_credentials_release(creds);
- grpc_slice_unref(cert_slice);
- grpc_slice_unref(key_slice);
- grpc_slice_unref(ca_slice);
- grpc_core::ExecCtx::Get()->Flush();
+ // If the given string happens to be part of the correct client hello, the
+ // server will wait for more data. Explicitly fail the server by shutting
+ // down the endpoint.
+ if (!state.done_callback_called) {
+ grpc_endpoint_shutdown(
+ mock_endpoint,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Explicit close"));
+ grpc_core::ExecCtx::Get()->Flush();
+ }
+
+ GPR_ASSERT(state.done_callback_called);
+
+ grpc_handshake_manager_destroy(handshake_mgr);
+ GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "test");
+ grpc_server_credentials_release(creds);
+ grpc_slice_unref(cert_slice);
+ grpc_slice_unref(key_slice);
+ grpc_slice_unref(ca_slice);
+ grpc_core::ExecCtx::Get()->Flush();
+ }
grpc_shutdown();
if (leak_check) {