aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/security
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-11-09 15:20:59 -0800
committerGravatar Craig Tiller <ctiller@google.com>2016-11-09 15:20:59 -0800
commit10cd3566621c17b4e63526b53b3052cc9a555c48 (patch)
tree9af431ce2843505736e6a685b598aaef10561245 /test/core/security
parent87a7e1fd114b571abc4644d6f1cddcaff3085df4 (diff)
Finish moving to new APIs
Diffstat (limited to 'test/core/security')
-rw-r--r--test/core/security/b64_test.c44
-rw-r--r--test/core/security/credentials_test.c129
-rw-r--r--test/core/security/json_token_test.c13
-rw-r--r--test/core/security/jwt_verifier_test.c32
-rw-r--r--test/core/security/secure_endpoint_test.c5
5 files changed, 148 insertions, 75 deletions
diff --git a/test/core/security/b64_test.c b/test/core/security/b64_test.c
index af883f51e9..28af48075e 100644
--- a/test/core/security/b64_test.c
+++ b/test/core/security/b64_test.c
@@ -38,6 +38,8 @@
#include <grpc/slice.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
+#include "src/core/lib/iomgr/exec_ctx.h"
+#include "src/core/lib/slice/slice_internal.h"
#include "test/core/util/test_config.h"
static int buffers_are_equal(const unsigned char *buf1,
@@ -57,12 +59,14 @@ static void test_simple_encode_decode_b64(int url_safe, int multiline) {
const char *hello = "hello";
char *hello_b64 =
grpc_base64_encode(hello, strlen(hello), url_safe, multiline);
- grpc_slice hello_slice = grpc_base64_decode(hello_b64, url_safe);
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_slice hello_slice = grpc_base64_decode(&exec_ctx, hello_b64, url_safe);
GPR_ASSERT(GRPC_SLICE_LENGTH(hello_slice) == strlen(hello));
GPR_ASSERT(strncmp((const char *)GRPC_SLICE_START_PTR(hello_slice), hello,
GRPC_SLICE_LENGTH(hello_slice)) == 0);
- grpc_slice_unref(hello_slice);
+ grpc_slice_unref_internal(&exec_ctx, hello_slice);
+ grpc_exec_ctx_finish(&exec_ctx);
gpr_free(hello_b64);
}
@@ -75,13 +79,15 @@ static void test_full_range_encode_decode_b64(int url_safe, int multiline) {
/* Try all the different paddings. */
for (i = 0; i < 3; i++) {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
b64 = grpc_base64_encode(orig, sizeof(orig) - i, url_safe, multiline);
- orig_decoded = grpc_base64_decode(b64, url_safe);
+ orig_decoded = grpc_base64_decode(&exec_ctx, b64, url_safe);
GPR_ASSERT(GRPC_SLICE_LENGTH(orig_decoded) == (sizeof(orig) - i));
GPR_ASSERT(buffers_are_equal(orig, GRPC_SLICE_START_PTR(orig_decoded),
sizeof(orig) - i));
- grpc_slice_unref(orig_decoded);
+ grpc_slice_unref_internal(&exec_ctx, orig_decoded);
gpr_free(b64);
+ grpc_exec_ctx_finish(&exec_ctx);
}
}
@@ -117,7 +123,7 @@ static void test_full_range_encode_decode_b64_urlsafe_multiline(void) {
test_full_range_encode_decode_b64(1, 1);
}
-static void test_url_safe_unsafe_mismtach_failure(void) {
+static void test_url_safe_unsafe_mismatch_failure(void) {
unsigned char orig[256];
size_t i;
char *b64;
@@ -125,17 +131,19 @@ static void test_url_safe_unsafe_mismtach_failure(void) {
int url_safe = 1;
for (i = 0; i < sizeof(orig); i++) orig[i] = (uint8_t)i;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
b64 = grpc_base64_encode(orig, sizeof(orig), url_safe, 0);
- orig_decoded = grpc_base64_decode(b64, !url_safe);
+ orig_decoded = grpc_base64_decode(&exec_ctx, b64, !url_safe);
GPR_ASSERT(GRPC_SLICE_IS_EMPTY(orig_decoded));
gpr_free(b64);
- grpc_slice_unref(orig_decoded);
+ grpc_slice_unref_internal(&exec_ctx, orig_decoded);
b64 = grpc_base64_encode(orig, sizeof(orig), !url_safe, 0);
- orig_decoded = grpc_base64_decode(b64, url_safe);
+ orig_decoded = grpc_base64_decode(&exec_ctx, b64, url_safe);
GPR_ASSERT(GRPC_SLICE_IS_EMPTY(orig_decoded));
gpr_free(b64);
- grpc_slice_unref(orig_decoded);
+ grpc_slice_unref_internal(&exec_ctx, orig_decoded);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void test_rfc4648_test_vectors(void) {
@@ -173,38 +181,40 @@ static void test_rfc4648_test_vectors(void) {
static void test_unpadded_decode(void) {
grpc_slice decoded;
- decoded = grpc_base64_decode("Zm9vYmFy", 0);
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ decoded = grpc_base64_decode(&exec_ctx, "Zm9vYmFy", 0);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded));
GPR_ASSERT(grpc_slice_str_cmp(decoded, "foobar") == 0);
grpc_slice_unref(decoded);
- decoded = grpc_base64_decode("Zm9vYmE", 0);
+ decoded = grpc_base64_decode(&exec_ctx, "Zm9vYmE", 0);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded));
GPR_ASSERT(grpc_slice_str_cmp(decoded, "fooba") == 0);
grpc_slice_unref(decoded);
- decoded = grpc_base64_decode("Zm9vYg", 0);
+ decoded = grpc_base64_decode(&exec_ctx, "Zm9vYg", 0);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded));
GPR_ASSERT(grpc_slice_str_cmp(decoded, "foob") == 0);
grpc_slice_unref(decoded);
- decoded = grpc_base64_decode("Zm9v", 0);
+ decoded = grpc_base64_decode(&exec_ctx, "Zm9v", 0);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded));
GPR_ASSERT(grpc_slice_str_cmp(decoded, "foo") == 0);
grpc_slice_unref(decoded);
- decoded = grpc_base64_decode("Zm8", 0);
+ decoded = grpc_base64_decode(&exec_ctx, "Zm8", 0);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded));
GPR_ASSERT(grpc_slice_str_cmp(decoded, "fo") == 0);
grpc_slice_unref(decoded);
- decoded = grpc_base64_decode("Zg", 0);
+ decoded = grpc_base64_decode(&exec_ctx, "Zg", 0);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(decoded));
GPR_ASSERT(grpc_slice_str_cmp(decoded, "f") == 0);
grpc_slice_unref(decoded);
- decoded = grpc_base64_decode("", 0);
+ decoded = grpc_base64_decode(&exec_ctx, "", 0);
GPR_ASSERT(GRPC_SLICE_IS_EMPTY(decoded));
+ grpc_exec_ctx_finish(&exec_ctx);
}
int main(int argc, char **argv) {
@@ -217,7 +227,7 @@ int main(int argc, char **argv) {
test_full_range_encode_decode_b64_multiline();
test_full_range_encode_decode_b64_urlsafe_no_multiline();
test_full_range_encode_decode_b64_urlsafe_multiline();
- test_url_safe_unsafe_mismtach_failure();
+ test_url_safe_unsafe_mismatch_failure();
test_rfc4648_test_vectors();
test_unpadded_decode();
return 0;
diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c
index d4c755088d..8fd4737c8f 100644
--- a/test/core/security/credentials_test.c
+++ b/test/core/security/credentials_test.c
@@ -166,24 +166,29 @@ static grpc_httpcli_response http_response(int status, const char *body) {
/* -- Tests. -- */
static void test_empty_md_store(void) {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_credentials_md_store *store = grpc_credentials_md_store_create(0);
GPR_ASSERT(store->num_entries == 0);
GPR_ASSERT(store->allocated == 0);
- grpc_credentials_md_store_unref(store);
+ grpc_credentials_md_store_unref(&exec_ctx, store);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void test_ref_unref_empty_md_store(void) {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_credentials_md_store *store = grpc_credentials_md_store_create(0);
grpc_credentials_md_store_ref(store);
grpc_credentials_md_store_ref(store);
GPR_ASSERT(store->num_entries == 0);
GPR_ASSERT(store->allocated == 0);
- grpc_credentials_md_store_unref(store);
- grpc_credentials_md_store_unref(store);
- grpc_credentials_md_store_unref(store);
+ grpc_credentials_md_store_unref(&exec_ctx, store);
+ grpc_credentials_md_store_unref(&exec_ctx, store);
+ grpc_credentials_md_store_unref(&exec_ctx, store);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void test_add_to_empty_md_store(void) {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_credentials_md_store *store = grpc_credentials_md_store_create(0);
const char *key_str = "hello";
const char *value_str = "there blah blah blah blah blah blah blah";
@@ -195,10 +200,12 @@ static void test_add_to_empty_md_store(void) {
GPR_ASSERT(grpc_slice_cmp(value, store->entries[0].value) == 0);
grpc_slice_unref(key);
grpc_slice_unref(value);
- grpc_credentials_md_store_unref(store);
+ grpc_credentials_md_store_unref(&exec_ctx, store);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void test_add_cstrings_to_empty_md_store(void) {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_credentials_md_store *store = grpc_credentials_md_store_create(0);
const char *key_str = "hello";
const char *value_str = "there blah blah blah blah blah blah blah";
@@ -206,18 +213,22 @@ static void test_add_cstrings_to_empty_md_store(void) {
GPR_ASSERT(store->num_entries == 1);
GPR_ASSERT(grpc_slice_str_cmp(store->entries[0].key, key_str) == 0);
GPR_ASSERT(grpc_slice_str_cmp(store->entries[0].value, value_str) == 0);
- grpc_credentials_md_store_unref(store);
+ grpc_credentials_md_store_unref(&exec_ctx, store);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void test_empty_preallocated_md_store(void) {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_credentials_md_store *store = grpc_credentials_md_store_create(4);
GPR_ASSERT(store->num_entries == 0);
GPR_ASSERT(store->allocated == 4);
GPR_ASSERT(store->entries != NULL);
- grpc_credentials_md_store_unref(store);
+ grpc_credentials_md_store_unref(&exec_ctx, store);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void test_add_abunch_to_md_store(void) {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_credentials_md_store *store = grpc_credentials_md_store_create(4);
size_t num_entries = 1000;
const char *key_str = "hello";
@@ -230,16 +241,19 @@ static void test_add_abunch_to_md_store(void) {
GPR_ASSERT(grpc_slice_str_cmp(store->entries[i].key, key_str) == 0);
GPR_ASSERT(grpc_slice_str_cmp(store->entries[i].value, value_str) == 0);
}
- grpc_credentials_md_store_unref(store);
+ grpc_credentials_md_store_unref(&exec_ctx, store);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void test_oauth2_token_fetcher_creds_parsing_ok(void) {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_credentials_md_store *token_md = NULL;
gpr_timespec token_lifetime;
grpc_httpcli_response response =
http_response(200, valid_oauth2_json_response);
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
- &response, &token_md, &token_lifetime) == GRPC_CREDENTIALS_OK);
+ &exec_ctx, &response, &token_md, &token_lifetime) ==
+ GRPC_CREDENTIALS_OK);
GPR_ASSERT(token_lifetime.tv_sec == 3599);
GPR_ASSERT(token_lifetime.tv_nsec == 0);
GPR_ASSERT(token_md->num_entries == 1);
@@ -248,32 +262,38 @@ static void test_oauth2_token_fetcher_creds_parsing_ok(void) {
GPR_ASSERT(grpc_slice_str_cmp(token_md->entries[0].value,
"Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_") ==
0);
- grpc_credentials_md_store_unref(token_md);
+ grpc_credentials_md_store_unref(&exec_ctx, 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_credentials_md_store *token_md = NULL;
gpr_timespec token_lifetime;
grpc_httpcli_response response =
http_response(401, valid_oauth2_json_response);
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
- &response, &token_md, &token_lifetime) ==
+ &exec_ctx, &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_credentials_md_store *token_md = NULL;
gpr_timespec token_lifetime;
grpc_httpcli_response response = http_response(200, "");
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
- &response, &token_md, &token_lifetime) ==
+ &exec_ctx, &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_credentials_md_store *token_md = NULL;
gpr_timespec token_lifetime;
grpc_httpcli_response response =
@@ -282,12 +302,14 @@ 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(
- &response, &token_md, &token_lifetime) ==
+ &exec_ctx, &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_credentials_md_store *token_md = NULL;
gpr_timespec token_lifetime;
grpc_httpcli_response response = http_response(200,
@@ -295,12 +317,14 @@ 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(
- &response, &token_md, &token_lifetime) ==
+ &exec_ctx, &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_credentials_md_store *token_md = NULL;
gpr_timespec token_lifetime;
grpc_httpcli_response response =
@@ -309,13 +333,15 @@ 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(
- &response, &token_md, &token_lifetime) ==
+ &exec_ctx, &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_credentials_md_store *token_md = NULL;
gpr_timespec token_lifetime;
grpc_httpcli_response response =
@@ -323,9 +349,10 @@ 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(
- &response, &token_md, &token_lifetime) ==
+ &exec_ctx, &response, &token_md, &token_lifetime) ==
GRPC_CREDENTIALS_ERROR);
grpc_http_response_destroy(&response);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void check_metadata(expected_md *expected, grpc_credentials_md *md_elems,
@@ -361,7 +388,7 @@ static void check_google_iam_metadata(grpc_exec_ctx *exec_ctx, void *user_data,
GPR_ASSERT(error_details == NULL);
GPR_ASSERT(num_md == 2);
check_metadata(emd, md_elems, num_md);
- grpc_call_credentials_unref(c);
+ grpc_call_credentials_unref(exec_ctx, c);
}
static void test_google_iam_creds(void) {
@@ -385,7 +412,7 @@ static void check_access_token_metadata(
GPR_ASSERT(error_details == NULL);
GPR_ASSERT(num_md == 1);
check_metadata(emd, md_elems, num_md);
- grpc_call_credentials_unref(c);
+ grpc_call_credentials_unref(exec_ctx, c);
}
static void test_access_token_creds(void) {
@@ -401,9 +428,10 @@ static void test_access_token_creds(void) {
}
static grpc_security_status check_channel_oauth2_create_security_connector(
- 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_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) {
GPR_ASSERT(strcmp(c->type, "mock") == 0);
GPR_ASSERT(call_creds != NULL);
GPR_ASSERT(strcmp(call_creds->type, GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0);
@@ -411,6 +439,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_channel_args *new_args;
grpc_channel_credentials_vtable vtable = {
NULL, check_channel_oauth2_create_security_connector, NULL};
@@ -424,9 +453,10 @@ 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(
- channel_oauth2_creds, NULL, NULL, NULL, &new_args) ==
- GRPC_SECURITY_OK);
+ &exec_ctx, channel_oauth2_creds, NULL, NULL, NULL,
+ &new_args) == GRPC_SECURITY_OK);
grpc_channel_credentials_release(channel_oauth2_creds);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void check_oauth2_google_iam_composite_metadata(
@@ -443,7 +473,7 @@ static void check_oauth2_google_iam_composite_metadata(
GPR_ASSERT(error_details == NULL);
GPR_ASSERT(num_md == 3);
check_metadata(emd, md_elems, num_md);
- grpc_call_credentials_unref(c);
+ grpc_call_credentials_unref(exec_ctx, c);
}
static void test_oauth2_google_iam_composite_creds(void) {
@@ -459,8 +489,8 @@ static void test_oauth2_google_iam_composite_creds(void) {
grpc_call_credentials *composite_creds =
grpc_composite_call_credentials_create(oauth2_creds, google_iam_creds,
NULL);
- grpc_call_credentials_unref(oauth2_creds);
- grpc_call_credentials_unref(google_iam_creds);
+ grpc_call_credentials_unref(&exec_ctx, oauth2_creds);
+ grpc_call_credentials_unref(&exec_ctx, google_iam_creds);
GPR_ASSERT(
strcmp(composite_creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0);
creds_array =
@@ -478,9 +508,10 @@ static void test_oauth2_google_iam_composite_creds(void) {
static grpc_security_status
check_channel_oauth2_google_iam_create_security_connector(
- 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_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) {
const grpc_call_credentials_array *creds_array;
GPR_ASSERT(strcmp(c->type, "mock") == 0);
GPR_ASSERT(call_creds != NULL);
@@ -495,6 +526,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_channel_args *new_args;
grpc_channel_credentials_vtable vtable = {
NULL, check_channel_oauth2_google_iam_create_security_connector, NULL};
@@ -517,10 +549,11 @@ 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(
- channel_oauth2_iam_creds, NULL, NULL, NULL, &new_args) ==
- GRPC_SECURITY_OK);
+ &exec_ctx, channel_oauth2_iam_creds, NULL, NULL, NULL,
+ &new_args) == GRPC_SECURITY_OK);
grpc_channel_credentials_release(channel_oauth2_iam_creds);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void on_oauth2_creds_get_metadata_success(
@@ -619,7 +652,7 @@ static void test_compute_engine_creds_success(void) {
on_oauth2_creds_get_metadata_success, (void *)test_user_data);
grpc_exec_ctx_finish(&exec_ctx);
- grpc_call_credentials_unref(compute_engine_creds);
+ grpc_call_credentials_unref(&exec_ctx, compute_engine_creds);
grpc_httpcli_set_override(NULL, NULL);
}
@@ -634,7 +667,7 @@ static void test_compute_engine_creds_failure(void) {
grpc_call_credentials_get_request_metadata(
&exec_ctx, compute_engine_creds, NULL, auth_md_ctx,
on_oauth2_creds_get_metadata_failure, (void *)test_user_data);
- grpc_call_credentials_unref(compute_engine_creds);
+ grpc_call_credentials_unref(&exec_ctx, compute_engine_creds);
grpc_httpcli_set_override(NULL, NULL);
grpc_exec_ctx_finish(&exec_ctx);
}
@@ -706,7 +739,7 @@ static void test_refresh_token_creds_success(void) {
on_oauth2_creds_get_metadata_success, (void *)test_user_data);
grpc_exec_ctx_flush(&exec_ctx);
- grpc_call_credentials_unref(refresh_token_creds);
+ grpc_call_credentials_unref(&exec_ctx, refresh_token_creds);
grpc_httpcli_set_override(NULL, NULL);
grpc_exec_ctx_finish(&exec_ctx);
}
@@ -723,7 +756,7 @@ static void test_refresh_token_creds_failure(void) {
grpc_call_credentials_get_request_metadata(
&exec_ctx, refresh_token_creds, NULL, auth_md_ctx,
on_oauth2_creds_get_metadata_failure, (void *)test_user_data);
- grpc_call_credentials_unref(refresh_token_creds);
+ grpc_call_credentials_unref(&exec_ctx, refresh_token_creds);
grpc_httpcli_set_override(NULL, NULL);
grpc_exec_ctx_finish(&exec_ctx);
}
@@ -832,7 +865,7 @@ static void test_jwt_creds_success(void) {
grpc_exec_ctx_flush(&exec_ctx);
gpr_free(json_key_string);
- grpc_call_credentials_unref(jwt_creds);
+ grpc_call_credentials_unref(&exec_ctx, jwt_creds);
grpc_jwt_encode_and_sign_set_override(NULL);
}
@@ -851,7 +884,7 @@ static void test_jwt_creds_signing_failure(void) {
on_jwt_creds_get_metadata_failure, (void *)test_user_data);
gpr_free(json_key_string);
- grpc_call_credentials_unref(jwt_creds);
+ grpc_call_credentials_unref(&exec_ctx, jwt_creds);
grpc_jwt_encode_and_sign_set_override(NULL);
grpc_exec_ctx_finish(&exec_ctx);
}
@@ -870,6 +903,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_service_account_jwt_access_credentials *jwt;
grpc_composite_channel_credentials *creds;
char *json_key = test_json_key_str();
@@ -885,11 +919,13 @@ static void test_google_default_creds_auth_key(void) {
strcmp(jwt->key.client_id,
"777-abaslkan11hlb6nmim3bpspl31ud.apps.googleusercontent.com") ==
0);
- grpc_channel_credentials_unref(&creds->base);
+ grpc_channel_credentials_unref(&exec_ctx, &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_google_refresh_token_credentials *refresh;
grpc_composite_channel_credentials *creds;
grpc_flush_cached_google_default_credentials();
@@ -901,8 +937,9 @@ 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(&creds->base);
+ grpc_channel_credentials_unref(&exec_ctx, &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(
@@ -1142,6 +1179,8 @@ 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_channel_credentials *channel_creds =
grpc_fake_transport_security_credentials_create();
@@ -1149,21 +1188,23 @@ 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(dup);
+ grpc_channel_credentials_unref(&exec_ctx, dup);
grpc_call_credentials *call_creds =
grpc_access_token_credentials_create("blah", NULL);
grpc_channel_credentials *composite_creds =
grpc_composite_channel_credentials_create(channel_creds, call_creds,
NULL);
- grpc_call_credentials_unref(call_creds);
+ grpc_call_credentials_unref(&exec_ctx, call_creds);
dup = grpc_channel_credentials_duplicate_without_call_credentials(
composite_creds);
GPR_ASSERT(dup == channel_creds);
- grpc_channel_credentials_unref(dup);
+ grpc_channel_credentials_unref(&exec_ctx, dup);
- grpc_channel_credentials_unref(channel_creds);
- grpc_channel_credentials_unref(composite_creds);
+ grpc_channel_credentials_unref(&exec_ctx, channel_creds);
+ grpc_channel_credentials_unref(&exec_ctx, composite_creds);
+
+ grpc_exec_ctx_finish(&exec_ctx);
}
int main(int argc, char **argv) {
diff --git a/test/core/security/json_token_test.c b/test/core/security/json_token_test.c
index 201655881f..5cebb09bb2 100644
--- a/test/core/security/json_token_test.c
+++ b/test/core/security/json_token_test.c
@@ -44,6 +44,7 @@
#include "src/core/lib/json/json.h"
#include "src/core/lib/security/credentials/oauth2/oauth2_credentials.h"
#include "src/core/lib/security/util/b64.h"
+#include "src/core/lib/slice/slice_internal.h"
#include "test/core/util/test_config.h"
/* This JSON key was generated with the GCE console and revoked immediately.
@@ -220,6 +221,7 @@ static void test_parse_json_key_failure_no_private_key(void) {
static grpc_json *parse_json_part_from_jwt(const char *str, size_t len,
char **scratchpad) {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
char *b64;
char *decoded;
grpc_json *json;
@@ -227,7 +229,7 @@ static grpc_json *parse_json_part_from_jwt(const char *str, size_t len,
b64 = gpr_malloc(len + 1);
strncpy(b64, str, len);
b64[len] = '\0';
- slice = grpc_base64_decode(b64, 1);
+ slice = grpc_base64_decode(&exec_ctx, b64, 1);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(slice));
decoded = gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1);
strncpy(decoded, (const char *)GRPC_SLICE_START_PTR(slice),
@@ -237,6 +239,7 @@ static grpc_json *parse_json_part_from_jwt(const char *str, size_t len,
gpr_free(b64);
*scratchpad = decoded;
grpc_slice_unref(slice);
+ grpc_exec_ctx_finish(&exec_ctx);
return json;
}
@@ -338,10 +341,12 @@ static void check_jwt_claim(grpc_json *claim, const char *expected_audience,
static void check_jwt_signature(const char *b64_signature, RSA *rsa_key,
const char *signed_data,
size_t signed_data_size) {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+
EVP_MD_CTX *md_ctx = EVP_MD_CTX_create();
EVP_PKEY *key = EVP_PKEY_new();
- grpc_slice sig = grpc_base64_decode(b64_signature, 1);
+ grpc_slice sig = grpc_base64_decode(&exec_ctx, b64_signature, 1);
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(sig));
GPR_ASSERT(GRPC_SLICE_LENGTH(sig) == 128);
@@ -355,9 +360,11 @@ static void check_jwt_signature(const char *b64_signature, RSA *rsa_key,
GPR_ASSERT(EVP_DigestVerifyFinal(md_ctx, GRPC_SLICE_START_PTR(sig),
GRPC_SLICE_LENGTH(sig)) == 1);
- grpc_slice_unref(sig);
+ grpc_slice_unref_internal(&exec_ctx, sig);
if (key != NULL) EVP_PKEY_free(key);
if (md_ctx != NULL) EVP_MD_CTX_destroy(md_ctx);
+
+ grpc_exec_ctx_finish(&exec_ctx);
}
static char *service_account_creds_jwt_encode_and_sign(
diff --git a/test/core/security/jwt_verifier_test.c b/test/core/security/jwt_verifier_test.c
index f8afba8d6d..14321d164e 100644
--- a/test/core/security/jwt_verifier_test.c
+++ b/test/core/security/jwt_verifier_test.c
@@ -185,7 +185,8 @@ static void test_claims_success(void) {
grpc_json *json = grpc_json_parse_string_with_len(
(char *)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s));
GPR_ASSERT(json != NULL);
- claims = grpc_jwt_claims_from_json(json, s);
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ claims = grpc_jwt_claims_from_json(&exec_ctx, json, s);
GPR_ASSERT(claims != NULL);
GPR_ASSERT(grpc_jwt_claims_json(claims) == json);
GPR_ASSERT(strcmp(grpc_jwt_claims_audience(claims), "https://foo.com") == 0);
@@ -194,7 +195,8 @@ static void test_claims_success(void) {
GPR_ASSERT(strcmp(grpc_jwt_claims_id(claims), "jwtuniqueid") == 0);
GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") ==
GRPC_JWT_VERIFIER_OK);
- grpc_jwt_claims_destroy(claims);
+ grpc_jwt_claims_destroy(&exec_ctx, claims);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void test_expired_claims_failure(void) {
@@ -206,7 +208,8 @@ static void test_expired_claims_failure(void) {
gpr_timespec exp_exp = {120, 0, GPR_CLOCK_REALTIME};
gpr_timespec exp_nbf = {60, 0, GPR_CLOCK_REALTIME};
GPR_ASSERT(json != NULL);
- claims = grpc_jwt_claims_from_json(json, s);
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ claims = grpc_jwt_claims_from_json(&exec_ctx, json, s);
GPR_ASSERT(claims != NULL);
GPR_ASSERT(grpc_jwt_claims_json(claims) == json);
GPR_ASSERT(strcmp(grpc_jwt_claims_audience(claims), "https://foo.com") == 0);
@@ -219,14 +222,17 @@ static void test_expired_claims_failure(void) {
GPR_ASSERT(grpc_jwt_claims_check(claims, "https://foo.com") ==
GRPC_JWT_VERIFIER_TIME_CONSTRAINT_FAILURE);
- grpc_jwt_claims_destroy(claims);
+ grpc_jwt_claims_destroy(&exec_ctx, claims);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void test_invalid_claims_failure(void) {
grpc_slice s = grpc_slice_from_copied_string(invalid_claims);
grpc_json *json = grpc_json_parse_string_with_len(
(char *)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s));
- GPR_ASSERT(grpc_jwt_claims_from_json(json, s) == NULL);
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ GPR_ASSERT(grpc_jwt_claims_from_json(&exec_ctx, json, s) == NULL);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void test_bad_audience_claims_failure(void) {
@@ -235,11 +241,13 @@ static void test_bad_audience_claims_failure(void) {
grpc_json *json = grpc_json_parse_string_with_len(
(char *)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s));
GPR_ASSERT(json != NULL);
- claims = grpc_jwt_claims_from_json(json, s);
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ claims = grpc_jwt_claims_from_json(&exec_ctx, json, s);
GPR_ASSERT(claims != NULL);
GPR_ASSERT(grpc_jwt_claims_check(claims, "https://bar.com") ==
GRPC_JWT_VERIFIER_BAD_AUDIENCE);
- grpc_jwt_claims_destroy(claims);
+ grpc_jwt_claims_destroy(&exec_ctx, claims);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static char *json_key_str(const char *last_part) {
@@ -305,7 +313,9 @@ static void on_verification_success(void *user_data,
GPR_ASSERT(claims != NULL);
GPR_ASSERT(user_data == (void *)expected_user_data);
GPR_ASSERT(strcmp(grpc_jwt_claims_audience(claims), expected_audience) == 0);
- grpc_jwt_claims_destroy(claims);
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_jwt_claims_destroy(&exec_ctx, claims);
+ grpc_exec_ctx_finish(&exec_ctx);
}
static void test_jwt_verifier_google_email_issuer_success(void) {
@@ -483,7 +493,11 @@ static void corrupt_jwt_sig(char *jwt) {
uint8_t *sig_bytes;
char *last_dot = strrchr(jwt, '.');
GPR_ASSERT(last_dot != NULL);
- sig = grpc_base64_decode(last_dot + 1, 1);
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ sig = grpc_base64_decode(&exec_ctx, last_dot + 1, 1);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
GPR_ASSERT(!GRPC_SLICE_IS_EMPTY(sig));
sig_bytes = GRPC_SLICE_START_PTR(sig);
(*sig_bytes)++; /* Corrupt first byte. */
diff --git a/test/core/security/secure_endpoint_test.c b/test/core/security/secure_endpoint_test.c
index e49662d428..3a0c2bb272 100644
--- a/test/core/security/secure_endpoint_test.c
+++ b/test/core/security/secure_endpoint_test.c
@@ -42,6 +42,7 @@
#include "src/core/lib/iomgr/endpoint_pair.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/security/transport/secure_endpoint.h"
+#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/tsi/fake_transport_security.h"
#include "test/core/util/test_config.h"
@@ -170,8 +171,8 @@ static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) {
grpc_endpoint_destroy(&exec_ctx, f.client_ep);
grpc_endpoint_destroy(&exec_ctx, f.server_ep);
grpc_exec_ctx_finish(&exec_ctx);
- grpc_slice_unref(s);
- grpc_slice_buffer_destroy_internal(exec_ctx, &incoming);
+ grpc_slice_unref_internal(&exec_ctx, s);
+ grpc_slice_buffer_destroy_internal(&exec_ctx, &incoming);
clean_up();
}