aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/security/credentials_test.c
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-06-23 11:57:26 -0700
committerGravatar Craig Tiller <ctiller@google.com>2016-06-23 11:57:26 -0700
commitc074408bd3ff79c1eff55f4c6d0f8f6ddc852abb (patch)
treea265c1420763c6c67fd00858ac0142dc0840041d /test/core/security/credentials_test.c
parent5856dee7d6728bcdd0aaf8ac98abef4690252d4b (diff)
parentd605b63383678313aaf3a6a3be7d8f9fc7ca67e9 (diff)
Merge github.com:grpc/grpc into consistent_client_count
Diffstat (limited to 'test/core/security/credentials_test.c')
-rw-r--r--test/core/security/credentials_test.c76
1 files changed, 41 insertions, 35 deletions
diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c
index 31e06372b9..e703dbdeb6 100644
--- a/test/core/security/credentials_test.c
+++ b/test/core/security/credentials_test.c
@@ -157,7 +157,7 @@ static grpc_httpcli_response http_response(int status, const char *body) {
grpc_httpcli_response response;
memset(&response, 0, sizeof(grpc_httpcli_response));
response.status = status;
- response.body = (char *)body;
+ response.body = gpr_strdup((char *)body);
response.body_length = strlen(body);
return response;
}
@@ -247,6 +247,7 @@ static void test_oauth2_token_fetcher_creds_parsing_ok(void) {
"Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_") ==
0);
grpc_credentials_md_store_unref(token_md);
+ grpc_http_response_destroy(&response);
}
static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) {
@@ -257,6 +258,7 @@ static void test_oauth2_token_fetcher_creds_parsing_bad_http_status(void) {
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
&response, &token_md, &token_lifetime) ==
GRPC_CREDENTIALS_ERROR);
+ grpc_http_response_destroy(&response);
}
static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) {
@@ -266,6 +268,7 @@ static void test_oauth2_token_fetcher_creds_parsing_empty_http_body(void) {
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
&response, &token_md, &token_lifetime) ==
GRPC_CREDENTIALS_ERROR);
+ grpc_http_response_destroy(&response);
}
static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) {
@@ -279,6 +282,7 @@ static void test_oauth2_token_fetcher_creds_parsing_invalid_json(void) {
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
&response, &token_md, &token_lifetime) ==
GRPC_CREDENTIALS_ERROR);
+ grpc_http_response_destroy(&response);
}
static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) {
@@ -291,6 +295,7 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token(void) {
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
&response, &token_md, &token_lifetime) ==
GRPC_CREDENTIALS_ERROR);
+ grpc_http_response_destroy(&response);
}
static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) {
@@ -304,6 +309,7 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_type(void) {
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
&response, &token_md, &token_lifetime) ==
GRPC_CREDENTIALS_ERROR);
+ grpc_http_response_destroy(&response);
}
static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime(
@@ -317,6 +323,7 @@ static void test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime(
GPR_ASSERT(grpc_oauth2_token_fetcher_credentials_parse_server_response(
&response, &token_md, &token_lifetime) ==
GRPC_CREDENTIALS_ERROR);
+ grpc_http_response_destroy(&response);
}
static void check_metadata(expected_md *expected, grpc_credentials_md *md_elems,
@@ -549,37 +556,37 @@ 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,
- gpr_timespec deadline, grpc_httpcli_response_cb on_response,
- void *user_data) {
- grpc_httpcli_response response =
- http_response(200, valid_oauth2_json_response);
+ gpr_timespec deadline, grpc_closure *on_done,
+ grpc_httpcli_response *response) {
validate_compute_engine_http_request(request);
- on_response(exec_ctx, user_data, &response);
+ *response = http_response(200, valid_oauth2_json_response);
+ grpc_exec_ctx_sched(exec_ctx, on_done, GRPC_ERROR_NONE, NULL);
return 1;
}
static int compute_engine_httpcli_get_failure_override(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_httpcli_response_cb on_response,
- void *user_data) {
- grpc_httpcli_response response = http_response(403, "Not Authorized.");
+ gpr_timespec deadline, grpc_closure *on_done,
+ grpc_httpcli_response *response) {
validate_compute_engine_http_request(request);
- on_response(exec_ctx, user_data, &response);
+ *response = http_response(403, "Not Authorized.");
+ grpc_exec_ctx_sched(exec_ctx, on_done, GRPC_ERROR_NONE, NULL);
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, gpr_timespec deadline,
- grpc_httpcli_response_cb on_response, void *user_data) {
+ grpc_closure *on_done, grpc_httpcli_response *response) {
GPR_ASSERT("HTTP POST should not be called" == NULL);
return 1;
}
-static int httpcli_get_should_not_be_called(
- grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_httpcli_response_cb on_response,
- void *user_data) {
+static int httpcli_get_should_not_be_called(grpc_exec_ctx *exec_ctx,
+ const grpc_httpcli_request *request,
+ gpr_timespec deadline,
+ grpc_closure *on_done,
+ grpc_httpcli_response *response) {
GPR_ASSERT("HTTP GET should not be called" == NULL);
return 1;
}
@@ -653,21 +660,20 @@ 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, gpr_timespec deadline,
- grpc_httpcli_response_cb on_response, void *user_data) {
- grpc_httpcli_response response =
- http_response(200, valid_oauth2_json_response);
+ grpc_closure *on_done, grpc_httpcli_response *response) {
validate_refresh_token_http_request(request, body, body_size);
- on_response(exec_ctx, user_data, &response);
+ *response = http_response(200, valid_oauth2_json_response);
+ grpc_exec_ctx_sched(exec_ctx, on_done, GRPC_ERROR_NONE, NULL);
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, gpr_timespec deadline,
- grpc_httpcli_response_cb on_response, void *user_data) {
- grpc_httpcli_response response = http_response(403, "Not Authorized.");
+ grpc_closure *on_done, grpc_httpcli_response *response) {
validate_refresh_token_http_request(request, body, body_size);
- on_response(exec_ctx, user_data, &response);
+ *response = http_response(403, "Not Authorized.");
+ grpc_exec_ctx_sched(exec_ctx, on_done, GRPC_ERROR_NONE, NULL);
return 1;
}
@@ -899,17 +905,17 @@ static void test_google_default_creds_refresh_token(void) {
static int default_creds_gce_detection_httpcli_get_success_override(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_httpcli_response_cb on_response,
- void *user_data) {
- grpc_httpcli_response response = http_response(200, "");
- grpc_http_header header;
- header.key = "Metadata-Flavor";
- header.value = "Google";
- response.hdr_count = 1;
- response.hdrs = &header;
+ gpr_timespec deadline, grpc_closure *on_done,
+ grpc_httpcli_response *response) {
+ *response = http_response(200, "");
+ grpc_http_header *headers = gpr_malloc(sizeof(*headers) * 1);
+ headers[0].key = gpr_strdup("Metadata-Flavor");
+ headers[0].value = gpr_strdup("Google");
+ response->hdr_count = 1;
+ response->hdrs = headers;
GPR_ASSERT(strcmp(request->http.path, "/") == 0);
GPR_ASSERT(strcmp(request->host, "metadata.google.internal") == 0);
- on_response(exec_ctx, user_data, &response);
+ grpc_exec_ctx_sched(exec_ctx, on_done, GRPC_ERROR_NONE, NULL);
return 1;
}
@@ -961,13 +967,13 @@ static void test_google_default_creds_gce(void) {
static int default_creds_gce_detection_httpcli_get_failure_override(
grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
- gpr_timespec deadline, grpc_httpcli_response_cb on_response,
- void *user_data) {
+ gpr_timespec deadline, grpc_closure *on_done,
+ grpc_httpcli_response *response) {
/* No magic header. */
- grpc_httpcli_response response = http_response(200, "");
GPR_ASSERT(strcmp(request->http.path, "/") == 0);
GPR_ASSERT(strcmp(request->host, "metadata.google.internal") == 0);
- on_response(exec_ctx, user_data, &response);
+ *response = http_response(200, "");
+ grpc_exec_ctx_sched(exec_ctx, on_done, GRPC_ERROR_NONE, NULL);
return 1;
}