diff options
author | yang-g <yangg@google.com> | 2015-11-18 11:41:30 -0800 |
---|---|---|
committer | yang-g <yangg@google.com> | 2015-11-18 11:41:30 -0800 |
commit | 71b962634eceacae336b1c706829e4ad9621b397 (patch) | |
tree | 35378c669bf04c24097a403af65a5adb8c82e812 /test | |
parent | 42630b010f398ca072a0ba89648855c3052c6594 (diff) | |
parent | 75b53d6a5d891fa33a9173318b1446faeaf154e4 (diff) |
merge with head
Diffstat (limited to 'test')
44 files changed, 1058 insertions, 971 deletions
diff --git a/test/core/channel/channel_stack_test.c b/test/core/channel/channel_stack_test.c index 076a122e20..5e1ba11857 100644 --- a/test/core/channel/channel_stack_test.c +++ b/test/core/channel/channel_stack_test.c @@ -42,22 +42,19 @@ #include "test/core/util/test_config.h" static void channel_init_func(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, grpc_channel *master, - const grpc_channel_args *args, - grpc_mdctx *metadata_context, int is_first, - int is_last) { - GPR_ASSERT(args->num_args == 1); - GPR_ASSERT(args->args[0].type == GRPC_ARG_INTEGER); - GPR_ASSERT(0 == strcmp(args->args[0].key, "test_key")); - GPR_ASSERT(args->args[0].value.integer == 42); - GPR_ASSERT(is_first); - GPR_ASSERT(is_last); + grpc_channel_element *elem, + grpc_channel_element_args *args) { + GPR_ASSERT(args->channel_args->num_args == 1); + GPR_ASSERT(args->channel_args->args[0].type == GRPC_ARG_INTEGER); + GPR_ASSERT(0 == strcmp(args->channel_args->args[0].key, "test_key")); + GPR_ASSERT(args->channel_args->args[0].value.integer == 42); + GPR_ASSERT(args->is_first); + GPR_ASSERT(args->is_last); *(int *)(elem->channel_data) = 0; } static void call_init_func(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - const void *server_transport_data, - grpc_transport_stream_op *initial_op) { + grpc_call_element_args *args) { ++*(int *)(elem->channel_data); *(int *)(elem->call_data) = 0; } @@ -86,9 +83,9 @@ static char *get_peer(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) { static void test_create_channel_stack(void) { const grpc_channel_filter filter = { - call_func, channel_func, sizeof(int), call_init_func, call_destroy_func, - sizeof(int), channel_init_func, channel_destroy_func, get_peer, - "some_test_filter"}; + call_func, channel_func, sizeof(int), call_init_func, + grpc_call_stack_ignore_set_pollset, call_destroy_func, sizeof(int), + channel_init_func, channel_destroy_func, get_peer, "some_test_filter"}; const grpc_channel_filter *filters = &filter; grpc_channel_stack *channel_stack; grpc_call_stack *call_stack; @@ -119,7 +116,8 @@ static void test_create_channel_stack(void) { GPR_ASSERT(*channel_data == 0); call_stack = gpr_malloc(channel_stack->call_stack_size); - grpc_call_stack_init(&exec_ctx, channel_stack, NULL, NULL, call_stack); + grpc_call_stack_init(&exec_ctx, channel_stack, 0, NULL, NULL, NULL, NULL, + call_stack); GPR_ASSERT(call_stack->count == 1); call_elem = grpc_call_stack_element(call_stack, 0); GPR_ASSERT(call_elem->filter == channel_elem->filter); diff --git a/test/core/client_config/lb_policies_test.c b/test/core/client_config/lb_policies_test.c index 3eb6f11bf7..0218b8f07f 100644 --- a/test/core/client_config/lb_policies_test.c +++ b/test/core/client_config/lb_policies_test.c @@ -119,14 +119,15 @@ static void test_spec_destroy(test_spec *spec) { static void *tag(gpr_intptr t) { return (void *)t; } -static gpr_timespec n_seconds_time(int n) { - return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n); +static gpr_timespec n_millis_time(int n) { + return gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_millis(n, GPR_TIMESPAN)); } static void drain_cq(grpc_completion_queue *cq) { grpc_event ev; do { - ev = grpc_completion_queue_next(cq, n_seconds_time(5), NULL); + ev = grpc_completion_queue_next(cq, n_millis_time(5000), NULL); } while (ev.type != GRPC_QUEUE_SHUTDOWN); } @@ -134,29 +135,47 @@ static void kill_server(const servers_fixture *f, size_t i) { gpr_log(GPR_INFO, "KILLING SERVER %d", i); GPR_ASSERT(f->servers[i] != NULL); grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000)); - GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(10000), - GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), - NULL).type == GRPC_OP_COMPLETE); + GPR_ASSERT( + grpc_completion_queue_pluck(f->cq, tag(10000), n_millis_time(5000), NULL) + .type == GRPC_OP_COMPLETE); grpc_server_destroy(f->servers[i]); f->servers[i] = NULL; } -static void revive_server(const servers_fixture *f, size_t i) { +typedef struct request_data { + grpc_metadata_array initial_metadata_recv; + grpc_metadata_array trailing_metadata_recv; + char *details; + size_t details_capacity; + grpc_status_code status; + grpc_call_details *call_details; +} request_data; + +static void revive_server(const servers_fixture *f, request_data *rdata, + size_t i) { int got_port; gpr_log(GPR_INFO, "RAISE AGAIN SERVER %d", i); GPR_ASSERT(f->servers[i] == NULL); + + gpr_log(GPR_DEBUG, "revive: %s", f->servers_hostports[i]); + f->servers[i] = grpc_server_create(NULL, NULL); grpc_server_register_completion_queue(f->servers[i], f->cq, NULL); GPR_ASSERT((got_port = grpc_server_add_insecure_http2_port( f->servers[i], f->servers_hostports[i])) > 0); grpc_server_start(f->servers[i]); + + GPR_ASSERT(GRPC_CALL_OK == + grpc_server_request_call(f->servers[i], &f->server_calls[i], + &rdata->call_details[i], + &f->request_metadata_recv[i], f->cq, + f->cq, tag(1000 + (int)i))); } static servers_fixture *setup_servers(const char *server_host, + request_data *rdata, const size_t num_servers) { servers_fixture *f = gpr_malloc(sizeof(servers_fixture)); - int *ports; - int got_port; size_t i; f->num_servers = num_servers; @@ -164,23 +183,16 @@ static servers_fixture *setup_servers(const char *server_host, f->request_metadata_recv = gpr_malloc(sizeof(grpc_metadata_array) * num_servers); /* Create servers. */ - ports = gpr_malloc(sizeof(int *) * num_servers); f->servers = gpr_malloc(sizeof(grpc_server *) * num_servers); f->servers_hostports = gpr_malloc(sizeof(char *) * num_servers); f->cq = grpc_completion_queue_create(NULL); for (i = 0; i < num_servers; i++) { - ports[i] = grpc_pick_unused_port_or_die(); - - gpr_join_host_port(&f->servers_hostports[i], server_host, ports[i]); - - f->servers[i] = grpc_server_create(NULL, NULL); - grpc_server_register_completion_queue(f->servers[i], f->cq, NULL); - GPR_ASSERT((got_port = grpc_server_add_insecure_http2_port( - f->servers[i], f->servers_hostports[i])) > 0); - GPR_ASSERT(ports[i] == got_port); - grpc_server_start(f->servers[i]); + grpc_metadata_array_init(&f->request_metadata_recv[i]); + gpr_join_host_port(&f->servers_hostports[i], server_host, + grpc_pick_unused_port_or_die()); + f->servers[i] = 0; + revive_server(f, rdata, i); } - gpr_free(ports); return f; } @@ -191,8 +203,8 @@ static void teardown_servers(servers_fixture *f) { if (f->servers[i] == NULL) continue; grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000)); GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(10000), - GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), - NULL).type == GRPC_OP_COMPLETE); + n_millis_time(5000), NULL) + .type == GRPC_OP_COMPLETE); grpc_server_destroy(f->servers[i]); } grpc_completion_queue_shutdown(f->cq); @@ -203,6 +215,7 @@ static void teardown_servers(servers_fixture *f) { for (i = 0; i < f->num_servers; i++) { gpr_free(f->servers_hostports[i]); + grpc_metadata_array_destroy(&f->request_metadata_recv[i]); } gpr_free(f->servers_hostports); @@ -211,22 +224,12 @@ static void teardown_servers(servers_fixture *f) { gpr_free(f); } -typedef struct request_data { - grpc_metadata_array initial_metadata_recv; - grpc_metadata_array trailing_metadata_recv; - char *details; - size_t details_capacity; - grpc_status_code status; - grpc_call_details *call_details; -} request_data; - /** Returns connection sequence (server indices), which must be freed */ int *perform_request(servers_fixture *f, grpc_channel *client, request_data *rdata, const test_spec *spec) { grpc_call *c; int s_idx; int *s_valid; - gpr_timespec deadline; grpc_op ops[6]; grpc_op *op; int was_cancelled; @@ -234,13 +237,12 @@ int *perform_request(servers_fixture *f, grpc_channel *client, grpc_event ev; int read_tag; int *connection_sequence; + int completed_client; s_valid = gpr_malloc(sizeof(int) * f->num_servers); - rdata->call_details = gpr_malloc(sizeof(grpc_call_details) * f->num_servers); connection_sequence = gpr_malloc(sizeof(int) * spec->num_iters); /* Send a trivial request. */ - deadline = n_seconds_time(60); for (iter_num = 0; iter_num < spec->num_iters; iter_num++) { cq_verifier *cqv = cq_verifier_create(f->cq); @@ -253,7 +255,7 @@ int *perform_request(servers_fixture *f, grpc_channel *client, kill_server(f, i); } else if (spec->revive_at[iter_num][i] != 0) { /* killing takes precedence */ - revive_server(f, i); + revive_server(f, rdata, i); } } @@ -267,8 +269,10 @@ int *perform_request(servers_fixture *f, grpc_channel *client, memset(s_valid, 0, f->num_servers * sizeof(int)); c = grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, - "/foo", "foo.test.google.fr", deadline, NULL); + "/foo", "foo.test.google.fr", gpr_inf_future(GPR_CLOCK_REALTIME), + NULL); GPR_ASSERT(c); + completed_client = 0; op = ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; @@ -286,32 +290,23 @@ int *perform_request(servers_fixture *f, grpc_channel *client, op->reserved = NULL; op++; op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; - op->data.recv_status_on_client.trailing_metadata = &rdata->trailing_metadata_recv; + op->data.recv_status_on_client.trailing_metadata = + &rdata->trailing_metadata_recv; op->data.recv_status_on_client.status = &rdata->status; op->data.recv_status_on_client.status_details = &rdata->details; - op->data.recv_status_on_client.status_details_capacity = &rdata->details_capacity; + op->data.recv_status_on_client.status_details_capacity = + &rdata->details_capacity; op->flags = 0; op->reserved = NULL; op++; GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL)); - /* "listen" on all servers */ - for (i = 0; i < f->num_servers; i++) { - grpc_metadata_array_init(&f->request_metadata_recv[i]); - if (f->servers[i] != NULL) { - GPR_ASSERT(GRPC_CALL_OK == - grpc_server_request_call(f->servers[i], &f->server_calls[i], - &rdata->call_details[i], - &f->request_metadata_recv[i], f->cq, - f->cq, tag(1000 + (int)i))); - } - } - s_idx = -1; while ((ev = grpc_completion_queue_next( - f->cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1), NULL)).type != - GRPC_QUEUE_TIMEOUT) { + f->cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1), NULL)) + .type != GRPC_QUEUE_TIMEOUT) { + GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); read_tag = ((int)(gpr_intptr)ev.tag); gpr_log(GPR_DEBUG, "EVENT: success:%d, type:%d, tag:%d iter:%d", ev.success, ev.type, read_tag, iter_num); @@ -321,9 +316,16 @@ int *perform_request(servers_fixture *f, grpc_channel *client, s_idx = read_tag - 1000; s_valid[s_idx] = 1; connection_sequence[iter_num] = s_idx; + break; + } else if (read_tag == 1) { + gpr_log(GPR_DEBUG, "client timed out"); + GPR_ASSERT(ev.success); + completed_client = 1; } } + gpr_log(GPR_DEBUG, "s_idx=%d", s_idx); + if (s_idx >= 0) { op = ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; @@ -348,23 +350,35 @@ int *perform_request(servers_fixture *f, grpc_channel *client, tag(102), NULL)); cq_expect_completion(cqv, tag(102), 1); - cq_expect_completion(cqv, tag(1), 1); + if (!completed_client) { + cq_expect_completion(cqv, tag(1), 1); + } cq_verify(cqv); + gpr_log(GPR_DEBUG, "status=%d; %s", rdata->status, rdata->details); GPR_ASSERT(rdata->status == GRPC_STATUS_UNIMPLEMENTED); GPR_ASSERT(0 == strcmp(rdata->details, "xyz")); GPR_ASSERT(0 == strcmp(rdata->call_details[s_idx].method, "/foo")); - GPR_ASSERT(0 == strcmp(rdata->call_details[s_idx].host, "foo.test.google.fr")); + GPR_ASSERT(0 == + strcmp(rdata->call_details[s_idx].host, "foo.test.google.fr")); GPR_ASSERT(was_cancelled == 1); - } else { - } - for (i = 0; i < f->num_servers; i++) { - if (s_valid[i] != 0) { - grpc_call_destroy(f->server_calls[i]); + grpc_call_destroy(f->server_calls[s_idx]); + + /* ask for the next request on this server */ + GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( + f->servers[s_idx], &f->server_calls[s_idx], + &rdata->call_details[s_idx], + &f->request_metadata_recv[s_idx], f->cq, + f->cq, tag(1000 + (int)s_idx))); + } else { + grpc_call_cancel(c, NULL); + if (!completed_client) { + cq_expect_completion(cqv, tag(1), 1); + cq_verify(cqv); } - grpc_metadata_array_destroy(&f->request_metadata_recv[i]); } + grpc_metadata_array_destroy(&rdata->initial_metadata_recv); grpc_metadata_array_destroy(&rdata->trailing_metadata_recv); @@ -378,7 +392,6 @@ int *perform_request(servers_fixture *f, grpc_channel *client, gpr_free(rdata->details); } - gpr_free(rdata->call_details); gpr_free(s_valid); return connection_sequence; @@ -441,14 +454,26 @@ void run_spec(const test_spec *spec) { char *servers_hostports_str; int *actual_connection_sequence; request_data rdata; - servers_fixture *f = setup_servers("127.0.0.1", spec->num_servers); + servers_fixture *f; + grpc_channel_args args; + grpc_arg arg; + rdata.call_details = + gpr_malloc(sizeof(grpc_call_details) * spec->num_servers); + f = setup_servers("127.0.0.1", &rdata, spec->num_servers); /* Create client. */ servers_hostports_str = gpr_strjoin_sep((const char **)f->servers_hostports, f->num_servers, ",", NULL); gpr_asprintf(&client_hostport, "ipv4:%s?lb_policy=round_robin", servers_hostports_str); - client = grpc_insecure_channel_create(client_hostport, NULL, NULL); + + arg.type = GRPC_ARG_INTEGER; + arg.key = "grpc.testing.fixed_reconnect_backoff"; + arg.value.integer = 100; + args.num_args = 1; + args.args = &arg; + + client = grpc_insecure_channel_create(client_hostport, &args, NULL); gpr_log(GPR_INFO, "Testing '%s' with servers=%s client=%s", spec->description, servers_hostports_str, client_hostport); @@ -460,6 +485,7 @@ void run_spec(const test_spec *spec) { gpr_free(client_hostport); gpr_free(servers_hostports_str); gpr_free(actual_connection_sequence); + gpr_free(rdata.call_details); grpc_channel_destroy(client); teardown_servers(f); diff --git a/test/core/end2end/data/server1_cert.c b/test/core/end2end/data/server1_cert.c index d31f2e2d0e..82d65cf551 100644 --- a/test/core/end2end/data/server1_cert.c +++ b/test/core/end2end/data/server1_cert.c @@ -34,82 +34,82 @@ const char test_server1_cert[] = { 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, - 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x43, 0x6d, 0x7a, 0x43, 0x43, - 0x41, 0x67, 0x53, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x42, - 0x41, 0x7a, 0x41, 0x4e, 0x42, 0x67, 0x6b, 0x71, 0x68, 0x6b, 0x69, 0x47, - 0x39, 0x77, 0x30, 0x42, 0x41, 0x51, 0x55, 0x46, 0x41, 0x44, 0x42, 0x57, + 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x43, 0x6e, 0x44, 0x43, 0x43, + 0x41, 0x67, 0x57, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x42, + 0x42, 0x7a, 0x41, 0x4e, 0x42, 0x67, 0x6b, 0x71, 0x68, 0x6b, 0x69, 0x47, + 0x39, 0x77, 0x30, 0x42, 0x41, 0x51, 0x73, 0x46, 0x41, 0x44, 0x42, 0x57, 0x4d, 0x51, 0x73, 0x77, 0x43, 0x51, 0x59, 0x44, 0x56, 0x51, 0x51, 0x47, 0x45, 0x77, 0x4a, 0x42, 0x56, 0x54, 0x45, 0x54, 0x0a, 0x4d, 0x42, 0x45, - 0x47, 0x41, 0x31, 0x55, 0x45, 0x43, 0x41, 0x77, 0x4b, 0x55, 0x32, 0x39, + 0x47, 0x41, 0x31, 0x55, 0x45, 0x43, 0x42, 0x4d, 0x4b, 0x55, 0x32, 0x39, 0x74, 0x5a, 0x53, 0x31, 0x54, 0x64, 0x47, 0x46, 0x30, 0x5a, 0x54, 0x45, - 0x68, 0x4d, 0x42, 0x38, 0x47, 0x41, 0x31, 0x55, 0x45, 0x43, 0x67, 0x77, + 0x68, 0x4d, 0x42, 0x38, 0x47, 0x41, 0x31, 0x55, 0x45, 0x43, 0x68, 0x4d, 0x59, 0x53, 0x57, 0x35, 0x30, 0x5a, 0x58, 0x4a, 0x75, 0x5a, 0x58, 0x51, 0x67, 0x56, 0x32, 0x6c, 0x6b, 0x5a, 0x32, 0x6c, 0x30, 0x63, 0x79, 0x42, 0x51, 0x0a, 0x64, 0x48, 0x6b, 0x67, 0x54, 0x48, 0x52, 0x6b, 0x4d, 0x51, - 0x38, 0x77, 0x44, 0x51, 0x59, 0x44, 0x56, 0x51, 0x51, 0x44, 0x44, 0x41, + 0x38, 0x77, 0x44, 0x51, 0x59, 0x44, 0x56, 0x51, 0x51, 0x44, 0x45, 0x77, 0x5a, 0x30, 0x5a, 0x58, 0x4e, 0x30, 0x59, 0x32, 0x45, 0x77, 0x48, 0x68, - 0x63, 0x4e, 0x4d, 0x54, 0x51, 0x77, 0x4e, 0x7a, 0x49, 0x79, 0x4d, 0x44, - 0x59, 0x77, 0x4d, 0x44, 0x55, 0x33, 0x57, 0x68, 0x63, 0x4e, 0x4d, 0x6a, - 0x51, 0x77, 0x4e, 0x7a, 0x45, 0x35, 0x0a, 0x4d, 0x44, 0x59, 0x77, 0x4d, - 0x44, 0x55, 0x33, 0x57, 0x6a, 0x42, 0x6b, 0x4d, 0x51, 0x73, 0x77, 0x43, + 0x63, 0x4e, 0x4d, 0x54, 0x55, 0x78, 0x4d, 0x54, 0x41, 0x30, 0x4d, 0x44, + 0x49, 0x79, 0x4d, 0x44, 0x49, 0x30, 0x57, 0x68, 0x63, 0x4e, 0x4d, 0x6a, + 0x55, 0x78, 0x4d, 0x54, 0x41, 0x78, 0x0a, 0x4d, 0x44, 0x49, 0x79, 0x4d, + 0x44, 0x49, 0x30, 0x57, 0x6a, 0x42, 0x6c, 0x4d, 0x51, 0x73, 0x77, 0x43, 0x51, 0x59, 0x44, 0x56, 0x51, 0x51, 0x47, 0x45, 0x77, 0x4a, 0x56, 0x55, 0x7a, 0x45, 0x52, 0x4d, 0x41, 0x38, 0x47, 0x41, 0x31, 0x55, 0x45, 0x43, 0x42, 0x4d, 0x49, 0x53, 0x57, 0x78, 0x73, 0x61, 0x57, 0x35, 0x76, 0x61, 0x58, 0x4d, 0x78, 0x45, 0x44, 0x41, 0x4f, 0x42, 0x67, 0x4e, 0x56, 0x0a, 0x42, 0x41, 0x63, 0x54, 0x42, 0x30, 0x4e, 0x6f, 0x61, 0x57, 0x4e, 0x68, - 0x5a, 0x32, 0x38, 0x78, 0x46, 0x44, 0x41, 0x53, 0x42, 0x67, 0x4e, 0x56, - 0x42, 0x41, 0x6f, 0x54, 0x43, 0x30, 0x64, 0x76, 0x62, 0x32, 0x64, 0x73, - 0x5a, 0x53, 0x42, 0x4a, 0x62, 0x6d, 0x4d, 0x75, 0x4d, 0x52, 0x6f, 0x77, - 0x47, 0x41, 0x59, 0x44, 0x56, 0x51, 0x51, 0x44, 0x46, 0x42, 0x45, 0x71, - 0x4c, 0x6e, 0x52, 0x6c, 0x0a, 0x63, 0x33, 0x51, 0x75, 0x5a, 0x32, 0x39, - 0x76, 0x5a, 0x32, 0x78, 0x6c, 0x4c, 0x6d, 0x4e, 0x76, 0x62, 0x54, 0x43, - 0x42, 0x6e, 0x7a, 0x41, 0x4e, 0x42, 0x67, 0x6b, 0x71, 0x68, 0x6b, 0x69, - 0x47, 0x39, 0x77, 0x30, 0x42, 0x41, 0x51, 0x45, 0x46, 0x41, 0x41, 0x4f, - 0x42, 0x6a, 0x51, 0x41, 0x77, 0x67, 0x59, 0x6b, 0x43, 0x67, 0x59, 0x45, - 0x41, 0x34, 0x63, 0x4d, 0x56, 0x4a, 0x79, 0x67, 0x73, 0x0a, 0x4a, 0x55, - 0x6d, 0x6c, 0x67, 0x4d, 0x4d, 0x7a, 0x67, 0x64, 0x69, 0x30, 0x68, 0x31, - 0x58, 0x6f, 0x43, 0x52, 0x37, 0x2b, 0x77, 0x77, 0x31, 0x70, 0x6f, 0x70, - 0x30, 0x34, 0x4f, 0x4d, 0x4d, 0x79, 0x79, 0x37, 0x48, 0x2f, 0x69, 0x30, - 0x50, 0x4a, 0x32, 0x57, 0x36, 0x59, 0x33, 0x35, 0x2b, 0x62, 0x34, 0x43, - 0x4d, 0x38, 0x51, 0x72, 0x6b, 0x59, 0x65, 0x45, 0x61, 0x66, 0x55, 0x47, - 0x44, 0x4f, 0x0a, 0x52, 0x59, 0x58, 0x36, 0x79, 0x56, 0x2f, 0x63, 0x48, - 0x47, 0x47, 0x73, 0x44, 0x2f, 0x78, 0x30, 0x32, 0x79, 0x65, 0x36, 0x65, - 0x79, 0x31, 0x55, 0x44, 0x74, 0x6b, 0x47, 0x41, 0x44, 0x2f, 0x6d, 0x70, - 0x44, 0x45, 0x78, 0x38, 0x59, 0x43, 0x72, 0x6a, 0x41, 0x63, 0x31, 0x56, - 0x66, 0x76, 0x74, 0x38, 0x46, 0x6b, 0x36, 0x43, 0x6e, 0x31, 0x57, 0x56, - 0x49, 0x78, 0x56, 0x2f, 0x4a, 0x33, 0x30, 0x0a, 0x33, 0x78, 0x6a, 0x42, - 0x73, 0x46, 0x67, 0x42, 0x79, 0x51, 0x35, 0x35, 0x52, 0x42, 0x70, 0x31, - 0x4f, 0x4c, 0x5a, 0x66, 0x56, 0x4c, 0x6f, 0x36, 0x41, 0x6c, 0x65, 0x42, - 0x44, 0x53, 0x62, 0x63, 0x78, 0x61, 0x45, 0x43, 0x41, 0x77, 0x45, 0x41, - 0x41, 0x61, 0x4e, 0x72, 0x4d, 0x47, 0x6b, 0x77, 0x43, 0x51, 0x59, 0x44, - 0x56, 0x52, 0x30, 0x54, 0x42, 0x41, 0x49, 0x77, 0x41, 0x44, 0x41, 0x4c, - 0x0a, 0x42, 0x67, 0x4e, 0x56, 0x48, 0x51, 0x38, 0x45, 0x42, 0x41, 0x4d, - 0x43, 0x42, 0x65, 0x41, 0x77, 0x54, 0x77, 0x59, 0x44, 0x56, 0x52, 0x30, - 0x52, 0x42, 0x45, 0x67, 0x77, 0x52, 0x6f, 0x49, 0x51, 0x4b, 0x69, 0x35, - 0x30, 0x5a, 0x58, 0x4e, 0x30, 0x4c, 0x6d, 0x64, 0x76, 0x62, 0x32, 0x64, - 0x73, 0x5a, 0x53, 0x35, 0x6d, 0x63, 0x6f, 0x49, 0x59, 0x64, 0x32, 0x46, - 0x30, 0x5a, 0x58, 0x4a, 0x36, 0x0a, 0x62, 0x32, 0x39, 0x70, 0x4c, 0x6e, - 0x52, 0x6c, 0x63, 0x33, 0x51, 0x75, 0x5a, 0x32, 0x39, 0x76, 0x5a, 0x32, - 0x78, 0x6c, 0x4c, 0x6d, 0x4a, 0x6c, 0x67, 0x68, 0x49, 0x71, 0x4c, 0x6e, - 0x52, 0x6c, 0x63, 0x33, 0x51, 0x75, 0x65, 0x57, 0x39, 0x31, 0x64, 0x48, - 0x56, 0x69, 0x5a, 0x53, 0x35, 0x6a, 0x62, 0x32, 0x32, 0x48, 0x42, 0x4d, - 0x43, 0x6f, 0x41, 0x51, 0x4d, 0x77, 0x44, 0x51, 0x59, 0x4a, 0x0a, 0x4b, - 0x6f, 0x5a, 0x49, 0x68, 0x76, 0x63, 0x4e, 0x41, 0x51, 0x45, 0x46, 0x42, - 0x51, 0x41, 0x44, 0x67, 0x59, 0x45, 0x41, 0x4d, 0x32, 0x49, 0x69, 0x30, - 0x4c, 0x67, 0x54, 0x47, 0x62, 0x4a, 0x31, 0x6a, 0x34, 0x6f, 0x71, 0x58, - 0x39, 0x62, 0x78, 0x56, 0x63, 0x78, 0x6d, 0x2b, 0x2f, 0x52, 0x35, 0x59, - 0x66, 0x38, 0x6f, 0x69, 0x30, 0x61, 0x5a, 0x71, 0x54, 0x4a, 0x6c, 0x6e, - 0x4c, 0x59, 0x53, 0x0a, 0x77, 0x58, 0x63, 0x42, 0x79, 0x6b, 0x78, 0x54, - 0x78, 0x31, 0x38, 0x31, 0x73, 0x37, 0x57, 0x79, 0x66, 0x4a, 0x34, 0x39, - 0x57, 0x77, 0x72, 0x59, 0x58, 0x6f, 0x37, 0x38, 0x7a, 0x54, 0x44, 0x41, - 0x6e, 0x66, 0x31, 0x6d, 0x61, 0x30, 0x66, 0x50, 0x71, 0x33, 0x65, 0x34, - 0x6d, 0x70, 0x73, 0x70, 0x76, 0x79, 0x6e, 0x64, 0x4c, 0x68, 0x31, 0x61, - 0x2b, 0x4f, 0x61, 0x72, 0x48, 0x61, 0x31, 0x65, 0x0a, 0x61, 0x54, 0x30, - 0x44, 0x49, 0x49, 0x59, 0x6b, 0x37, 0x71, 0x65, 0x45, 0x61, 0x31, 0x59, - 0x63, 0x56, 0x6c, 0x6a, 0x78, 0x32, 0x4b, 0x79, 0x4c, 0x64, 0x30, 0x72, - 0x31, 0x42, 0x42, 0x41, 0x66, 0x72, 0x77, 0x79, 0x47, 0x61, 0x45, 0x50, - 0x56, 0x65, 0x4a, 0x51, 0x56, 0x59, 0x57, 0x61, 0x4f, 0x4a, 0x52, 0x55, - 0x32, 0x77, 0x65, 0x2f, 0x4b, 0x44, 0x34, 0x6f, 0x6a, 0x66, 0x39, 0x73, - 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x43, + 0x5a, 0x32, 0x38, 0x78, 0x46, 0x54, 0x41, 0x54, 0x42, 0x67, 0x4e, 0x56, + 0x42, 0x41, 0x6f, 0x54, 0x44, 0x45, 0x56, 0x34, 0x59, 0x57, 0x31, 0x77, + 0x62, 0x47, 0x55, 0x73, 0x49, 0x45, 0x4e, 0x76, 0x4c, 0x6a, 0x45, 0x61, + 0x4d, 0x42, 0x67, 0x47, 0x41, 0x31, 0x55, 0x45, 0x41, 0x78, 0x51, 0x52, + 0x4b, 0x69, 0x35, 0x30, 0x0a, 0x5a, 0x58, 0x4e, 0x30, 0x4c, 0x6d, 0x64, + 0x76, 0x62, 0x32, 0x64, 0x73, 0x5a, 0x53, 0x35, 0x6a, 0x62, 0x32, 0x30, + 0x77, 0x67, 0x5a, 0x38, 0x77, 0x44, 0x51, 0x59, 0x4a, 0x4b, 0x6f, 0x5a, + 0x49, 0x68, 0x76, 0x63, 0x4e, 0x41, 0x51, 0x45, 0x42, 0x42, 0x51, 0x41, + 0x44, 0x67, 0x59, 0x30, 0x41, 0x4d, 0x49, 0x47, 0x4a, 0x41, 0x6f, 0x47, + 0x42, 0x41, 0x4f, 0x48, 0x44, 0x46, 0x53, 0x63, 0x6f, 0x0a, 0x4c, 0x43, + 0x56, 0x4a, 0x70, 0x59, 0x44, 0x44, 0x4d, 0x34, 0x48, 0x59, 0x74, 0x49, + 0x64, 0x56, 0x36, 0x41, 0x6b, 0x65, 0x2f, 0x73, 0x4d, 0x4e, 0x61, 0x61, + 0x4b, 0x64, 0x4f, 0x44, 0x6a, 0x44, 0x4d, 0x73, 0x75, 0x78, 0x2f, 0x34, + 0x74, 0x44, 0x79, 0x64, 0x6c, 0x75, 0x6d, 0x4e, 0x2b, 0x66, 0x6d, 0x2b, + 0x41, 0x6a, 0x50, 0x45, 0x4b, 0x35, 0x47, 0x48, 0x68, 0x47, 0x6e, 0x31, + 0x42, 0x67, 0x0a, 0x7a, 0x6b, 0x57, 0x46, 0x2b, 0x73, 0x6c, 0x66, 0x33, + 0x42, 0x78, 0x68, 0x72, 0x41, 0x2f, 0x38, 0x64, 0x4e, 0x73, 0x6e, 0x75, + 0x6e, 0x73, 0x74, 0x56, 0x41, 0x37, 0x5a, 0x42, 0x67, 0x41, 0x2f, 0x35, + 0x71, 0x51, 0x78, 0x4d, 0x66, 0x47, 0x41, 0x71, 0x34, 0x77, 0x48, 0x4e, + 0x56, 0x58, 0x37, 0x37, 0x66, 0x42, 0x5a, 0x4f, 0x67, 0x70, 0x39, 0x56, + 0x6c, 0x53, 0x4d, 0x56, 0x66, 0x79, 0x64, 0x0a, 0x39, 0x4e, 0x38, 0x59, + 0x77, 0x62, 0x42, 0x59, 0x41, 0x63, 0x6b, 0x4f, 0x65, 0x55, 0x51, 0x61, + 0x64, 0x54, 0x69, 0x32, 0x58, 0x31, 0x53, 0x36, 0x4f, 0x67, 0x4a, 0x58, + 0x67, 0x51, 0x30, 0x6d, 0x33, 0x4d, 0x57, 0x68, 0x41, 0x67, 0x4d, 0x42, + 0x41, 0x41, 0x47, 0x6a, 0x61, 0x7a, 0x42, 0x70, 0x4d, 0x41, 0x6b, 0x47, + 0x41, 0x31, 0x55, 0x64, 0x45, 0x77, 0x51, 0x43, 0x4d, 0x41, 0x41, 0x77, + 0x0a, 0x43, 0x77, 0x59, 0x44, 0x56, 0x52, 0x30, 0x50, 0x42, 0x41, 0x51, + 0x44, 0x41, 0x67, 0x58, 0x67, 0x4d, 0x45, 0x38, 0x47, 0x41, 0x31, 0x55, + 0x64, 0x45, 0x51, 0x52, 0x49, 0x4d, 0x45, 0x61, 0x43, 0x45, 0x43, 0x6f, + 0x75, 0x64, 0x47, 0x56, 0x7a, 0x64, 0x43, 0x35, 0x6e, 0x62, 0x32, 0x39, + 0x6e, 0x62, 0x47, 0x55, 0x75, 0x5a, 0x6e, 0x4b, 0x43, 0x47, 0x48, 0x64, + 0x68, 0x64, 0x47, 0x56, 0x79, 0x0a, 0x65, 0x6d, 0x39, 0x76, 0x61, 0x53, + 0x35, 0x30, 0x5a, 0x58, 0x4e, 0x30, 0x4c, 0x6d, 0x64, 0x76, 0x62, 0x32, + 0x64, 0x73, 0x5a, 0x53, 0x35, 0x69, 0x5a, 0x59, 0x49, 0x53, 0x4b, 0x69, + 0x35, 0x30, 0x5a, 0x58, 0x4e, 0x30, 0x4c, 0x6e, 0x6c, 0x76, 0x64, 0x58, + 0x52, 0x31, 0x59, 0x6d, 0x55, 0x75, 0x59, 0x32, 0x39, 0x74, 0x68, 0x77, + 0x54, 0x41, 0x71, 0x41, 0x45, 0x44, 0x4d, 0x41, 0x30, 0x47, 0x0a, 0x43, + 0x53, 0x71, 0x47, 0x53, 0x49, 0x62, 0x33, 0x44, 0x51, 0x45, 0x42, 0x43, + 0x77, 0x55, 0x41, 0x41, 0x34, 0x47, 0x42, 0x41, 0x4a, 0x46, 0x58, 0x56, + 0x69, 0x66, 0x51, 0x4e, 0x75, 0x62, 0x31, 0x4c, 0x55, 0x50, 0x34, 0x4a, + 0x6c, 0x6e, 0x58, 0x35, 0x6c, 0x58, 0x4e, 0x6c, 0x6f, 0x38, 0x46, 0x78, + 0x5a, 0x32, 0x61, 0x31, 0x32, 0x41, 0x46, 0x51, 0x73, 0x2b, 0x62, 0x7a, + 0x6f, 0x4a, 0x36, 0x0a, 0x68, 0x4d, 0x30, 0x34, 0x34, 0x45, 0x44, 0x6a, + 0x71, 0x79, 0x78, 0x55, 0x71, 0x53, 0x62, 0x56, 0x65, 0x50, 0x4b, 0x30, + 0x6e, 0x69, 0x33, 0x77, 0x31, 0x66, 0x48, 0x51, 0x42, 0x35, 0x72, 0x59, + 0x39, 0x79, 0x59, 0x43, 0x35, 0x66, 0x38, 0x47, 0x37, 0x61, 0x71, 0x71, + 0x54, 0x59, 0x31, 0x51, 0x4f, 0x68, 0x6f, 0x55, 0x6b, 0x38, 0x5a, 0x54, + 0x53, 0x54, 0x52, 0x70, 0x6e, 0x6b, 0x54, 0x68, 0x0a, 0x79, 0x34, 0x6a, + 0x6a, 0x64, 0x76, 0x54, 0x5a, 0x65, 0x4c, 0x44, 0x56, 0x42, 0x6c, 0x75, + 0x65, 0x5a, 0x55, 0x54, 0x44, 0x52, 0x6d, 0x79, 0x32, 0x66, 0x65, 0x59, + 0x35, 0x61, 0x5a, 0x49, 0x55, 0x31, 0x38, 0x76, 0x46, 0x44, 0x4b, 0x30, + 0x38, 0x64, 0x54, 0x47, 0x30, 0x41, 0x38, 0x37, 0x70, 0x70, 0x70, 0x75, + 0x76, 0x31, 0x4c, 0x4e, 0x49, 0x52, 0x33, 0x6c, 0x6f, 0x76, 0x65, 0x55, + 0x38, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x00}; diff --git a/test/core/end2end/fixtures/h2_fakesec.c b/test/core/end2end/fixtures/h2_fakesec.c index 3e64cc08e8..bc009e1df1 100644 --- a/test/core/end2end/fixtures/h2_fakesec.c +++ b/test/core/end2end/fixtures/h2_fakesec.c @@ -73,14 +73,14 @@ static void process_auth_failure(void *state, grpc_auth_context *ctx, cb(user_data, NULL, 0, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, NULL); } -static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args, - grpc_credentials *creds) { +static void chttp2_init_client_secure_fullstack( + grpc_end2end_test_fixture *f, grpc_channel_args *client_args, + grpc_channel_credentials *creds) { fullstack_secure_fixture_data *ffd = f->fixture_data; f->client = grpc_secure_channel_create(creds, ffd->localaddr, client_args, NULL); GPR_ASSERT(f->client != NULL); - grpc_credentials_release(creds); + grpc_channel_credentials_release(creds); } static void chttp2_init_server_secure_fullstack( @@ -106,7 +106,7 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { static void chttp2_init_client_fake_secure_fullstack( grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { - grpc_credentials *fake_ts_creds = + grpc_channel_credentials *fake_ts_creds = grpc_fake_transport_security_credentials_create(); chttp2_init_client_secure_fullstack(f, client_args, fake_ts_creds); } diff --git a/test/core/end2end/fixtures/h2_oauth2.c b/test/core/end2end/fixtures/h2_oauth2.c index 10db6c2c6a..7a34cc67d8 100644 --- a/test/core/end2end/fixtures/h2_oauth2.c +++ b/test/core/end2end/fixtures/h2_oauth2.c @@ -118,14 +118,14 @@ static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack( return f; } -static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args, - grpc_credentials *creds) { +static void chttp2_init_client_secure_fullstack( + grpc_end2end_test_fixture *f, grpc_channel_args *client_args, + grpc_channel_credentials *creds) { fullstack_secure_fixture_data *ffd = f->fixture_data; f->client = grpc_secure_channel_create(creds, ffd->localaddr, client_args, NULL); GPR_ASSERT(f->client != NULL); - grpc_credentials_release(creds); + grpc_channel_credentials_release(creds); } static void chttp2_init_server_secure_fullstack( @@ -151,12 +151,12 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack( grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { - grpc_credentials *ssl_creds = + grpc_channel_credentials *ssl_creds = grpc_ssl_credentials_create(test_root_cert, NULL, NULL); - grpc_credentials *oauth2_creds = + grpc_call_credentials *oauth2_creds = grpc_md_only_test_credentials_create("Authorization", oauth2_md, 1); - grpc_credentials *ssl_oauth2_creds = - grpc_composite_credentials_create(ssl_creds, oauth2_creds, NULL); + grpc_channel_credentials *ssl_oauth2_creds = + grpc_composite_channel_credentials_create(ssl_creds, oauth2_creds, NULL); grpc_arg ssl_name_override = {GRPC_ARG_STRING, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, {"foo.test.google.fr"}}; @@ -164,8 +164,8 @@ static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack( grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); chttp2_init_client_secure_fullstack(f, new_client_args, ssl_oauth2_creds); grpc_channel_args_destroy(new_client_args); - grpc_credentials_release(ssl_creds); - grpc_credentials_release(oauth2_creds); + grpc_channel_credentials_release(ssl_creds); + grpc_call_credentials_release(oauth2_creds); } static int fail_server_auth_check(grpc_channel_args *server_args) { diff --git a/test/core/end2end/fixtures/h2_ssl+poll.c b/test/core/end2end/fixtures/h2_ssl+poll.c index c2f41f4886..37e1758f00 100644 --- a/test/core/end2end/fixtures/h2_ssl+poll.c +++ b/test/core/end2end/fixtures/h2_ssl+poll.c @@ -76,14 +76,14 @@ static void process_auth_failure(void *state, grpc_auth_context *ctx, cb(user_data, NULL, 0, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, NULL); } -static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args, - grpc_credentials *creds) { +static void chttp2_init_client_secure_fullstack( + grpc_end2end_test_fixture *f, grpc_channel_args *client_args, + grpc_channel_credentials *creds) { fullstack_secure_fixture_data *ffd = f->fixture_data; f->client = grpc_secure_channel_create(creds, ffd->localaddr, client_args, NULL); GPR_ASSERT(f->client != NULL); - grpc_credentials_release(creds); + grpc_channel_credentials_release(creds); } static void chttp2_init_server_secure_fullstack( @@ -109,7 +109,8 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { static void chttp2_init_client_simple_ssl_secure_fullstack( grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { - grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL, NULL); + grpc_channel_credentials *ssl_creds = + grpc_ssl_credentials_create(NULL, NULL, NULL); grpc_arg ssl_name_override = {GRPC_ARG_STRING, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, {"foo.test.google.fr"}}; diff --git a/test/core/end2end/fixtures/h2_ssl.c b/test/core/end2end/fixtures/h2_ssl.c index 896c60c507..f5a006bd08 100644 --- a/test/core/end2end/fixtures/h2_ssl.c +++ b/test/core/end2end/fixtures/h2_ssl.c @@ -76,14 +76,14 @@ static void process_auth_failure(void *state, grpc_auth_context *ctx, cb(user_data, NULL, 0, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, NULL); } -static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args, - grpc_credentials *creds) { +static void chttp2_init_client_secure_fullstack( + grpc_end2end_test_fixture *f, grpc_channel_args *client_args, + grpc_channel_credentials *creds) { fullstack_secure_fixture_data *ffd = f->fixture_data; f->client = grpc_secure_channel_create(creds, ffd->localaddr, client_args, NULL); GPR_ASSERT(f->client != NULL); - grpc_credentials_release(creds); + grpc_channel_credentials_release(creds); } static void chttp2_init_server_secure_fullstack( @@ -109,7 +109,8 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { static void chttp2_init_client_simple_ssl_secure_fullstack( grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { - grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL, NULL); + grpc_channel_credentials *ssl_creds = + grpc_ssl_credentials_create(NULL, NULL, NULL); grpc_arg ssl_name_override = {GRPC_ARG_STRING, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, {"foo.test.google.fr"}}; diff --git a/test/core/end2end/fixtures/h2_ssl_proxy.c b/test/core/end2end/fixtures/h2_ssl_proxy.c index 413a8b84cd..7233cdbe2d 100644 --- a/test/core/end2end/fixtures/h2_ssl_proxy.c +++ b/test/core/end2end/fixtures/h2_ssl_proxy.c @@ -66,7 +66,8 @@ static grpc_server *create_proxy_server(const char *port) { static grpc_channel *create_proxy_client(const char *target) { grpc_channel *channel; - grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL, NULL); + grpc_channel_credentials *ssl_creds = + grpc_ssl_credentials_create(NULL, NULL, NULL); grpc_arg ssl_name_override = {GRPC_ARG_STRING, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, {"foo.test.google.fr"}}; @@ -74,7 +75,7 @@ static grpc_channel *create_proxy_client(const char *target) { client_args.num_args = 1; client_args.args = &ssl_name_override; channel = grpc_secure_channel_create(ssl_creds, target, &client_args, NULL); - grpc_credentials_release(ssl_creds); + grpc_channel_credentials_release(ssl_creds); return channel; } @@ -104,15 +105,15 @@ static void process_auth_failure(void *state, grpc_auth_context *ctx, cb(user_data, NULL, 0, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, NULL); } -static void chttp2_init_client_secure_fullstack(grpc_end2end_test_fixture *f, - grpc_channel_args *client_args, - grpc_credentials *creds) { +static void chttp2_init_client_secure_fullstack( + grpc_end2end_test_fixture *f, grpc_channel_args *client_args, + grpc_channel_credentials *creds) { fullstack_secure_fixture_data *ffd = f->fixture_data; f->client = grpc_secure_channel_create( creds, grpc_end2end_proxy_get_client_target(ffd->proxy), client_args, NULL); GPR_ASSERT(f->client != NULL); - grpc_credentials_release(creds); + grpc_channel_credentials_release(creds); } static void chttp2_init_server_secure_fullstack( @@ -138,7 +139,8 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { static void chttp2_init_client_simple_ssl_secure_fullstack( grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { - grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL, NULL); + grpc_channel_credentials *ssl_creds = + grpc_ssl_credentials_create(NULL, NULL, NULL); grpc_arg ssl_name_override = {GRPC_ARG_STRING, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, {"foo.test.google.fr"}}; diff --git a/test/core/end2end/fixtures/proxy.c b/test/core/end2end/fixtures/proxy.c index 434e75dd15..1090ad667d 100644 --- a/test/core/end2end/fixtures/proxy.c +++ b/test/core/end2end/fixtures/proxy.c @@ -146,6 +146,7 @@ void grpc_end2end_proxy_destroy(grpc_end2end_proxy *proxy) { } static void unrefpc(proxy_call *pc, const char *reason) { + gpr_log(GPR_DEBUG, "PROXY UNREF %s", reason); if (gpr_unref(&pc->refs)) { grpc_call_destroy(pc->c2p); grpc_call_destroy(pc->p2s); @@ -157,7 +158,10 @@ static void unrefpc(proxy_call *pc, const char *reason) { } } -static void refpc(proxy_call *pc, const char *reason) { gpr_ref(&pc->refs); } +static void refpc(proxy_call *pc, const char *reason) { + gpr_log(GPR_DEBUG, "PROXY REF %s", reason); + gpr_ref(&pc->refs); +} static void on_c2p_sent_initial_metadata(void *arg, int success) { proxy_call *pc = arg; diff --git a/test/core/end2end/gen_build_yaml.py b/test/core/end2end/gen_build_yaml.py index af8f48576c..38d3b2218a 100755 --- a/test/core/end2end/gen_build_yaml.py +++ b/test/core/end2end/gen_build_yaml.py @@ -46,21 +46,21 @@ uds_fixture_options = default_unsecure_fixture_options._replace(dns_resolver=Fal # maps fixture name to whether it requires the security library END2END_FIXTURES = { + 'h2_compress': default_unsecure_fixture_options, 'h2_fakesec': default_secure_fixture_options._replace(ci_mac=False), 'h2_full': default_unsecure_fixture_options, - 'h2_uchannel': default_unsecure_fixture_options, - 'h2_compress': default_unsecure_fixture_options, - 'h2_uds': uds_fixture_options, - 'h2_uds+poll': uds_fixture_options._replace(platforms=['linux']), 'h2_full+poll': default_unsecure_fixture_options._replace(platforms=['linux']), + 'h2_oauth2': default_secure_fixture_options._replace(ci_mac=False), 'h2_proxy': default_unsecure_fixture_options._replace(includes_proxy=True, ci_mac=False), + 'h2_sockpair_1byte': socketpair_unsecure_fixture_options._replace(ci_mac=False), + 'h2_sockpair': socketpair_unsecure_fixture_options._replace(ci_mac=False), + 'h2_sockpair+trace': socketpair_unsecure_fixture_options, 'h2_ssl': default_secure_fixture_options, 'h2_ssl+poll': default_secure_fixture_options._replace(platforms=['linux']), 'h2_ssl_proxy': default_secure_fixture_options._replace(includes_proxy=True, ci_mac=False), - 'h2_oauth2': default_secure_fixture_options._replace(ci_mac=False), - 'h2_sockpair': socketpair_unsecure_fixture_options._replace(ci_mac=False), - 'h2_sockpair_1byte': socketpair_unsecure_fixture_options._replace(ci_mac=False), - 'h2_sockpair+trace': socketpair_unsecure_fixture_options, + 'h2_uchannel': default_unsecure_fixture_options, + 'h2_uds+poll': uds_fixture_options._replace(platforms=['linux']), + 'h2_uds': uds_fixture_options, } TestOptions = collections.namedtuple('TestOptions', 'needs_fullstack needs_dns proxyable flaky secure') @@ -70,38 +70,40 @@ connectivity_test_options = default_test_options._replace(needs_fullstack=True) # maps test names to options END2END_TESTS = { 'bad_hostname': default_test_options, - 'cancel_after_client_done': default_test_options, + 'binary_metadata': default_test_options, + 'call_creds': default_test_options._replace(secure=True), 'cancel_after_accept': default_test_options, + 'cancel_after_client_done': default_test_options, 'cancel_after_invoke': default_test_options, 'cancel_before_invoke': default_test_options, 'cancel_in_a_vacuum': default_test_options, + 'cancel_with_status': default_test_options, 'census_simple_request': default_test_options, 'channel_connectivity': connectivity_test_options._replace(proxyable=False), + 'compressed_payload': default_test_options._replace(proxyable=False), 'default_host': default_test_options._replace(needs_fullstack=True, needs_dns=True), 'disappearing_server': connectivity_test_options, - 'shutdown_finishes_calls': default_test_options, - 'shutdown_finishes_tags': default_test_options, 'empty_batch': default_test_options, 'graceful_server_shutdown': default_test_options, + 'high_initial_seqno': default_test_options, 'invoke_large_request': default_test_options, + 'large_metadata': default_test_options, 'max_concurrent_streams': default_test_options._replace(proxyable=False), 'max_message_length': default_test_options, + 'metadata': default_test_options, + 'negative_deadline': default_test_options, 'no_op': default_test_options, + 'payload': default_test_options, 'ping_pong_streaming': default_test_options, 'registered_call': default_test_options, - 'binary_metadata': default_test_options, - 'metadata': default_test_options, - 'call_creds': default_test_options._replace(secure=True), - 'payload': default_test_options, - 'trailing_metadata': default_test_options, - 'compressed_payload': default_test_options._replace(proxyable=False), 'request_with_flags': default_test_options._replace(proxyable=False), - 'large_metadata': default_test_options, 'request_with_payload': default_test_options, 'server_finishes_request': default_test_options, + 'shutdown_finishes_calls': default_test_options, + 'shutdown_finishes_tags': default_test_options, 'simple_delayed_request': connectivity_test_options, 'simple_request': default_test_options, - 'high_initial_seqno': default_test_options, + 'trailing_metadata': default_test_options, } diff --git a/test/core/end2end/tests/call_creds.c b/test/core/end2end/tests/call_creds.c index 4aeade1336..bbfad21b62 100644 --- a/test/core/end2end/tests/call_creds.c +++ b/test/core/end2end/tests/call_creds.c @@ -132,27 +132,6 @@ static void print_auth_context(int is_client, const grpc_auth_context *ctx) { } } -static void test_call_creds_failure(grpc_end2end_test_config config) { - grpc_call *c; - grpc_credentials *creds = NULL; - grpc_end2end_test_fixture f = - begin_test(config, "test_call_creds_failure", 0); - gpr_timespec deadline = five_seconds_time(); - c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - "/foo", "foo.test.google.fr", deadline, NULL); - GPR_ASSERT(c); - - /* Try with credentials unfit to be set on a call (channel creds). */ - creds = grpc_fake_transport_security_credentials_create(); - GPR_ASSERT(grpc_call_set_credentials(c, creds) != GRPC_CALL_OK); - grpc_credentials_release(creds); - - grpc_call_destroy(c); - - end_test(&f); - config.tear_down_data(&f); -} - static void request_response_with_payload_and_call_creds( const char *test_name, grpc_end2end_test_config config, override_mode mode) { @@ -180,7 +159,7 @@ static void request_response_with_payload_and_call_creds( char *details = NULL; size_t details_capacity = 0; int was_cancelled = 2; - grpc_credentials *creds = NULL; + grpc_call_credentials *creds = NULL; grpc_auth_context *s_auth_context = NULL; grpc_auth_context *c_auth_context = NULL; @@ -197,7 +176,7 @@ static void request_response_with_payload_and_call_creds( case NONE: break; case OVERRIDE: - grpc_credentials_release(creds); + grpc_call_credentials_release(creds); creds = grpc_google_iam_credentials_create(overridden_iam_token, overridden_iam_selector, NULL); GPR_ASSERT(creds != NULL); @@ -207,7 +186,7 @@ static void request_response_with_payload_and_call_creds( GPR_ASSERT(grpc_call_set_credentials(c, NULL) == GRPC_CALL_OK); break; } - grpc_credentials_release(creds); + grpc_call_credentials_release(creds); grpc_metadata_array_init(&initial_metadata_recv); grpc_metadata_array_init(&trailing_metadata_recv); @@ -412,7 +391,7 @@ static void test_request_with_server_rejecting_client_creds( gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world"); grpc_byte_buffer *request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); - grpc_credentials *creds; + grpc_call_credentials *creds; f = begin_test(config, "test_request_with_server_rejecting_client_creds", 1); cqv = cq_verifier_create(f.cq); @@ -424,7 +403,7 @@ static void test_request_with_server_rejecting_client_creds( creds = grpc_google_iam_credentials_create(iam_token, iam_selector, NULL); GPR_ASSERT(creds != NULL); GPR_ASSERT(grpc_call_set_credentials(c, creds) == GRPC_CALL_OK); - grpc_credentials_release(creds); + grpc_call_credentials_release(creds); grpc_metadata_array_init(&initial_metadata_recv); grpc_metadata_array_init(&trailing_metadata_recv); @@ -490,7 +469,6 @@ static void test_request_with_server_rejecting_client_creds( void grpc_end2end_tests(grpc_end2end_test_config config) { if (config.feature_mask & FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS) { - test_call_creds_failure(config); test_request_response_with_payload_and_call_creds(config); test_request_response_with_payload_and_overridden_call_creds(config); test_request_response_with_payload_and_deleted_call_creds(config); diff --git a/test/core/end2end/tests/cancel_with_status.c b/test/core/end2end/tests/cancel_with_status.c new file mode 100644 index 0000000000..eecfa83fa4 --- /dev/null +++ b/test/core/end2end/tests/cancel_with_status.c @@ -0,0 +1,183 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "test/core/end2end/end2end_tests.h" + +#include <stdio.h> +#include <string.h> + +#include "src/core/support/string.h" +#include <grpc/byte_buffer.h> +#include <grpc/grpc.h> +#include <grpc/support/alloc.h> +#include <grpc/support/log.h> +#include <grpc/support/time.h> +#include <grpc/support/useful.h> +#include "test/core/end2end/cq_verifier.h" + +enum { TIMEOUT = 200000 }; + +static void *tag(gpr_intptr t) { return (void *)t; } + +static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, + const char *test_name, + grpc_channel_args *client_args, + grpc_channel_args *server_args) { + grpc_end2end_test_fixture f; + gpr_log(GPR_INFO, "%s/%s", test_name, config.name); + f = config.create_fixture(client_args, server_args); + config.init_client(&f, client_args); + config.init_server(&f, server_args); + return f; +} + +static gpr_timespec n_seconds_time(int n) { + return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n); +} + +static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); } + +static void drain_cq(grpc_completion_queue *cq) { + grpc_event ev; + do { + ev = grpc_completion_queue_next(cq, five_seconds_time(), NULL); + } while (ev.type != GRPC_QUEUE_SHUTDOWN); +} + +static void shutdown_server(grpc_end2end_test_fixture *f) { + if (!f->server) return; + grpc_server_shutdown_and_notify(f->server, f->cq, tag(1000)); + GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(1000), + GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), + NULL).type == GRPC_OP_COMPLETE); + grpc_server_destroy(f->server); + f->server = NULL; +} + +static void shutdown_client(grpc_end2end_test_fixture *f) { + if (!f->client) return; + grpc_channel_destroy(f->client); + f->client = NULL; +} + +static void end_test(grpc_end2end_test_fixture *f) { + shutdown_server(f); + shutdown_client(f); + + grpc_completion_queue_shutdown(f->cq); + drain_cq(f->cq); + grpc_completion_queue_destroy(f->cq); +} + +static void simple_request_body(grpc_end2end_test_fixture f, size_t num_ops) { + grpc_call *c; + gpr_timespec deadline = five_seconds_time(); + cq_verifier *cqv = cq_verifier_create(f.cq); + grpc_op ops[6]; + grpc_op *op; + grpc_metadata_array initial_metadata_recv; + grpc_metadata_array trailing_metadata_recv; + grpc_status_code status; + grpc_call_error error; + char *details = NULL; + size_t details_capacity = 0; + + gpr_log(GPR_DEBUG, "test with %d ops", num_ops); + + c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + "/foo", "foo.test.google.fr:1234", deadline, + NULL); + GPR_ASSERT(c); + + grpc_metadata_array_init(&initial_metadata_recv); + grpc_metadata_array_init(&trailing_metadata_recv); + + op = ops; + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; + op->data.recv_status_on_client.status = &status; + op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata = &initial_metadata_recv; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op->flags = 0; + op->reserved = NULL; + op++; + GPR_ASSERT(num_ops <= (size_t)(op - ops)); + error = grpc_call_start_batch(c, ops, num_ops, tag(1), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + grpc_call_cancel_with_status(c, GRPC_STATUS_UNIMPLEMENTED, "xyz", NULL); + + cq_expect_completion(cqv, tag(1), 1); + cq_verify(cqv); + + GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); + GPR_ASSERT(0 == strcmp(details, "xyz")); + + gpr_free(details); + grpc_metadata_array_destroy(&initial_metadata_recv); + grpc_metadata_array_destroy(&trailing_metadata_recv); + + grpc_call_destroy(c); + + cq_verifier_destroy(cqv); +} + +static void test_invoke_simple_request(grpc_end2end_test_config config, size_t num_ops) { + grpc_end2end_test_fixture f; + + f = begin_test(config, "test_invoke_simple_request", NULL, NULL); + simple_request_body(f, num_ops); + end_test(&f); + config.tear_down_data(&f); +} + +void grpc_end2end_tests(grpc_end2end_test_config config) { + size_t i; + for (i = 1; i <= 4; i++) { + test_invoke_simple_request(config, i); + } +} diff --git a/test/core/end2end/tests/max_message_length.c b/test/core/end2end/tests/max_message_length.c index 3dad47f37b..b3d8304d0b 100644 --- a/test/core/end2end/tests/max_message_length.c +++ b/test/core/end2end/tests/max_message_length.c @@ -109,6 +109,7 @@ static void test_max_message_length(grpc_end2end_test_config config) { gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world"); grpc_byte_buffer *request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); + grpc_byte_buffer *recv_payload; grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; grpc_metadata_array request_metadata_recv; @@ -183,6 +184,11 @@ static void test_max_message_length(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message = &recv_payload; + op->flags = 0; + op->reserved = NULL; + op++; error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); @@ -194,6 +200,7 @@ static void test_max_message_length(grpc_end2end_test_config config) { GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr:1234")); GPR_ASSERT(was_cancelled == 1); + GPR_ASSERT(recv_payload == NULL); gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); diff --git a/test/core/end2end/tests/negative_deadline.c b/test/core/end2end/tests/negative_deadline.c new file mode 100644 index 0000000000..abcc1ba358 --- /dev/null +++ b/test/core/end2end/tests/negative_deadline.c @@ -0,0 +1,180 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "test/core/end2end/end2end_tests.h" + +#include <stdio.h> +#include <string.h> + +#include "src/core/support/string.h" +#include <grpc/byte_buffer.h> +#include <grpc/grpc.h> +#include <grpc/support/alloc.h> +#include <grpc/support/log.h> +#include <grpc/support/time.h> +#include <grpc/support/useful.h> +#include "test/core/end2end/cq_verifier.h" + +enum { TIMEOUT = 200000 }; + +static void *tag(gpr_intptr t) { return (void *)t; } + +static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, + const char *test_name, + grpc_channel_args *client_args, + grpc_channel_args *server_args) { + grpc_end2end_test_fixture f; + gpr_log(GPR_INFO, "%s/%s", test_name, config.name); + f = config.create_fixture(client_args, server_args); + config.init_client(&f, client_args); + config.init_server(&f, server_args); + return f; +} + +static gpr_timespec n_seconds_time(int n) { + return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n); +} + +static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); } + +static void drain_cq(grpc_completion_queue *cq) { + grpc_event ev; + do { + ev = grpc_completion_queue_next(cq, five_seconds_time(), NULL); + } while (ev.type != GRPC_QUEUE_SHUTDOWN); +} + +static void shutdown_server(grpc_end2end_test_fixture *f) { + if (!f->server) return; + grpc_server_shutdown_and_notify(f->server, f->cq, tag(1000)); + GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(1000), + GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), + NULL).type == GRPC_OP_COMPLETE); + grpc_server_destroy(f->server); + f->server = NULL; +} + +static void shutdown_client(grpc_end2end_test_fixture *f) { + if (!f->client) return; + grpc_channel_destroy(f->client); + f->client = NULL; +} + +static void end_test(grpc_end2end_test_fixture *f) { + shutdown_server(f); + shutdown_client(f); + + grpc_completion_queue_shutdown(f->cq); + drain_cq(f->cq); + grpc_completion_queue_destroy(f->cq); +} + +static void simple_request_body(grpc_end2end_test_fixture f, size_t num_ops) { + grpc_call *c; + gpr_timespec deadline = gpr_inf_past(GPR_CLOCK_REALTIME); + cq_verifier *cqv = cq_verifier_create(f.cq); + grpc_op ops[6]; + grpc_op *op; + grpc_metadata_array initial_metadata_recv; + grpc_metadata_array trailing_metadata_recv; + grpc_status_code status; + grpc_call_error error; + char *details = NULL; + size_t details_capacity = 0; + + gpr_log(GPR_DEBUG, "test with %d ops", num_ops); + + c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + "/foo", "foo.test.google.fr:1234", deadline, + NULL); + GPR_ASSERT(c); + + grpc_metadata_array_init(&initial_metadata_recv); + grpc_metadata_array_init(&trailing_metadata_recv); + + op = ops; + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; + op->data.recv_status_on_client.status = &status; + op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata = &initial_metadata_recv; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op->flags = 0; + op->reserved = NULL; + op++; + GPR_ASSERT(num_ops <= (size_t)(op - ops)); + error = grpc_call_start_batch(c, ops, num_ops, tag(1), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + cq_expect_completion(cqv, tag(1), 1); + cq_verify(cqv); + + GPR_ASSERT(status == GRPC_STATUS_DEADLINE_EXCEEDED); + + gpr_free(details); + grpc_metadata_array_destroy(&initial_metadata_recv); + grpc_metadata_array_destroy(&trailing_metadata_recv); + + grpc_call_destroy(c); + + cq_verifier_destroy(cqv); +} + +static void test_invoke_simple_request(grpc_end2end_test_config config, size_t num_ops) { + grpc_end2end_test_fixture f; + + f = begin_test(config, "test_invoke_simple_request", NULL, NULL); + simple_request_body(f, num_ops); + end_test(&f); + config.tear_down_data(&f); +} + +void grpc_end2end_tests(grpc_end2end_test_config config) { + size_t i; + for (i = 1; i <= 4; i++) { + test_invoke_simple_request(config, i); + } +} diff --git a/test/core/end2end/tests/request_with_flags.c b/test/core/end2end/tests/request_with_flags.c index d7c4cff608..5ea845e0e5 100644 --- a/test/core/end2end/tests/request_with_flags.c +++ b/test/core/end2end/tests/request_with_flags.c @@ -41,7 +41,7 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> #include <grpc/support/useful.h> -#include "src/core/transport/stream_op.h" +#include "src/core/transport/byte_stream.h" #include "test/core/end2end/cq_verifier.h" enum { TIMEOUT = 200000 }; diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c index 5c1e0f4b94..dcb35e5309 100644 --- a/test/core/security/credentials_test.c +++ b/test/core/security/credentials_test.c @@ -50,11 +50,24 @@ #include <openssl/rsa.h> +/* -- Mock channel credentials. -- */ + +static grpc_channel_credentials *grpc_mock_channel_credentials_create( + const grpc_channel_credentials_vtable *vtable) { + grpc_channel_credentials *c = gpr_malloc(sizeof(*c)); + memset(c, 0, sizeof(*c)); + c->type = "mock"; + c->vtable = vtable; + gpr_ref_init(&c->refcount, 1); + return c; +} + +/* -- Constants. -- */ + static const char test_google_iam_authorization_token[] = "blahblahblhahb"; static const char test_google_iam_authority_selector[] = "respectmyauthoritah"; static const char test_oauth2_bearer_token[] = "Bearer blaaslkdjfaslkdfasdsfasf"; -static const char test_root_cert[] = "I am the root!"; /* This JSON key was generated with the GCE console and revoked immediately. The identifiers have been changed as well. @@ -113,6 +126,8 @@ static const char test_signed_jwt[] = static const char test_service_url[] = "https://foo.com/foo.v1"; static const char other_test_service_url[] = "https://bar.com/bar.v1"; +/* -- Utils. -- */ + static char *test_json_key_str(void) { size_t result_len = strlen(test_json_key_str_part1) + strlen(test_json_key_str_part2) + @@ -141,6 +156,8 @@ static grpc_httpcli_response http_response(int status, const char *body) { return response; } +/* -- Tests. -- */ + static void test_empty_md_store(void) { grpc_credentials_md_store *store = grpc_credentials_md_store_create(0); GPR_ASSERT(store->num_entries == 0); @@ -219,7 +236,7 @@ static void test_oauth2_token_fetcher_creds_parsing_ok(void) { GPR_ASSERT(token_lifetime.tv_sec == 3599); GPR_ASSERT(token_lifetime.tv_nsec == 0); GPR_ASSERT(token_md->num_entries == 1); - GPR_ASSERT(gpr_slice_str_cmp(token_md->entries[0].key, "Authorization") == 0); + GPR_ASSERT(gpr_slice_str_cmp(token_md->entries[0].key, "authorization") == 0); GPR_ASSERT(gpr_slice_str_cmp(token_md->entries[0].value, "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_") == 0); @@ -319,7 +336,7 @@ static void check_google_iam_metadata(grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, size_t num_md, grpc_credentials_status status) { - grpc_credentials *c = (grpc_credentials *)user_data; + grpc_call_credentials *c = (grpc_call_credentials *)user_data; expected_md emd[] = {{GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, test_google_iam_authorization_token}, {GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, @@ -327,17 +344,15 @@ static void check_google_iam_metadata(grpc_exec_ctx *exec_ctx, void *user_data, GPR_ASSERT(status == GRPC_CREDENTIALS_OK); GPR_ASSERT(num_md == 2); check_metadata(emd, md_elems, num_md); - grpc_credentials_unref(c); + grpc_call_credentials_unref(c); } static void test_google_iam_creds(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_credentials *creds = grpc_google_iam_credentials_create( + grpc_call_credentials *creds = grpc_google_iam_credentials_create( test_google_iam_authorization_token, test_google_iam_authority_selector, NULL); - GPR_ASSERT(grpc_credentials_has_request_metadata(creds)); - GPR_ASSERT(grpc_credentials_has_request_metadata_only(creds)); - grpc_credentials_get_request_metadata(&exec_ctx, creds, NULL, + grpc_call_credentials_get_request_metadata(&exec_ctx, creds, NULL, test_service_url, check_google_iam_metadata, creds); grpc_exec_ctx_finish(&exec_ctx); @@ -348,81 +363,58 @@ static void check_access_token_metadata(grpc_exec_ctx *exec_ctx, grpc_credentials_md *md_elems, size_t num_md, grpc_credentials_status status) { - grpc_credentials *c = (grpc_credentials *)user_data; + grpc_call_credentials *c = (grpc_call_credentials *)user_data; expected_md emd[] = {{GRPC_AUTHORIZATION_METADATA_KEY, "Bearer blah"}}; GPR_ASSERT(status == GRPC_CREDENTIALS_OK); GPR_ASSERT(num_md == 1); check_metadata(emd, md_elems, num_md); - grpc_credentials_unref(c); + grpc_call_credentials_unref(c); } static void test_access_token_creds(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_credentials *creds = grpc_access_token_credentials_create("blah", NULL); - GPR_ASSERT(grpc_credentials_has_request_metadata(creds)); - GPR_ASSERT(grpc_credentials_has_request_metadata_only(creds)); - GPR_ASSERT(strcmp(creds->type, GRPC_CREDENTIALS_TYPE_OAUTH2) == 0); - grpc_credentials_get_request_metadata(&exec_ctx, creds, NULL, - test_service_url, - check_access_token_metadata, creds); + grpc_call_credentials *creds = + grpc_access_token_credentials_create("blah", NULL); + GPR_ASSERT(strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0); + grpc_call_credentials_get_request_metadata( + &exec_ctx, creds, NULL, test_service_url, check_access_token_metadata, + creds); grpc_exec_ctx_finish(&exec_ctx); } -static void check_ssl_oauth2_composite_metadata( +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) { + GPR_ASSERT(strcmp(c->type, "mock") == 0); + GPR_ASSERT(call_creds != NULL); + GPR_ASSERT(strcmp(call_creds->type, GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0); + return GRPC_SECURITY_OK; +} + +static void test_channel_oauth2_composite_creds(void) { + grpc_channel_args *new_args; + grpc_channel_credentials_vtable vtable = { + NULL, check_channel_oauth2_create_security_connector}; + grpc_channel_credentials *channel_creds = + grpc_mock_channel_credentials_create(&vtable); + grpc_call_credentials *oauth2_creds = + grpc_access_token_credentials_create("blah", NULL); + grpc_channel_credentials *channel_oauth2_creds = + grpc_composite_channel_credentials_create(channel_creds, oauth2_creds, + NULL); + 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); + grpc_channel_credentials_release(channel_oauth2_creds); +} + +static void check_oauth2_google_iam_composite_metadata( grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, size_t num_md, grpc_credentials_status status) { - grpc_credentials *c = (grpc_credentials *)user_data; - expected_md emd[] = { - {GRPC_AUTHORIZATION_METADATA_KEY, test_oauth2_bearer_token}}; - GPR_ASSERT(status == GRPC_CREDENTIALS_OK); - GPR_ASSERT(num_md == 1); - check_metadata(emd, md_elems, num_md); - grpc_credentials_unref(c); -} - -static void test_ssl_oauth2_composite_creds(void) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_credentials *ssl_creds = - grpc_ssl_credentials_create(test_root_cert, NULL, NULL); - const grpc_credentials_array *creds_array; - grpc_credentials *oauth2_creds = grpc_md_only_test_credentials_create( - "Authorization", test_oauth2_bearer_token, 0); - grpc_credentials *composite_creds = - grpc_composite_credentials_create(ssl_creds, oauth2_creds, NULL); - grpc_credentials_unref(ssl_creds); - grpc_credentials_unref(oauth2_creds); - GPR_ASSERT(strcmp(composite_creds->type, GRPC_CREDENTIALS_TYPE_COMPOSITE) == - 0); - GPR_ASSERT(grpc_credentials_has_request_metadata(composite_creds)); - GPR_ASSERT(!grpc_credentials_has_request_metadata_only(composite_creds)); - creds_array = grpc_composite_credentials_get_credentials(composite_creds); - GPR_ASSERT(creds_array->num_creds == 2); - GPR_ASSERT(strcmp(creds_array->creds_array[0]->type, - GRPC_CREDENTIALS_TYPE_SSL) == 0); - GPR_ASSERT(strcmp(creds_array->creds_array[1]->type, - GRPC_CREDENTIALS_TYPE_OAUTH2) == 0); - grpc_credentials_get_request_metadata( - &exec_ctx, composite_creds, NULL, test_service_url, - check_ssl_oauth2_composite_metadata, composite_creds); - grpc_exec_ctx_finish(&exec_ctx); -} - -void test_ssl_fake_transport_security_composite_creds_failure(void) { - grpc_credentials *ssl_creds = grpc_ssl_credentials_create(NULL, NULL, NULL); - grpc_credentials *fake_transport_security_creds = - grpc_fake_transport_security_credentials_create(); - - /* 2 connector credentials: should not work. */ - GPR_ASSERT(grpc_composite_credentials_create( - ssl_creds, fake_transport_security_creds, NULL) == NULL); - grpc_credentials_unref(ssl_creds); - grpc_credentials_unref(fake_transport_security_creds); -} - -static void check_ssl_oauth2_google_iam_composite_metadata( - grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, - size_t num_md, grpc_credentials_status status) { - grpc_credentials *c = (grpc_credentials *)user_data; + grpc_call_credentials *c = (grpc_call_credentials *)user_data; expected_md emd[] = { {GRPC_AUTHORIZATION_METADATA_KEY, test_oauth2_bearer_token}, {GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, @@ -432,51 +424,88 @@ static void check_ssl_oauth2_google_iam_composite_metadata( GPR_ASSERT(status == GRPC_CREDENTIALS_OK); GPR_ASSERT(num_md == 3); check_metadata(emd, md_elems, num_md); - grpc_credentials_unref(c); + grpc_call_credentials_unref(c); } -static void test_ssl_oauth2_google_iam_composite_creds(void) { +static void test_oauth2_google_iam_composite_creds(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_credentials *ssl_creds = - grpc_ssl_credentials_create(test_root_cert, NULL, NULL); - const grpc_credentials_array *creds_array; - grpc_credentials *oauth2_creds = grpc_md_only_test_credentials_create( - "Authorization", test_oauth2_bearer_token, 0); - grpc_credentials *aux_creds = - grpc_composite_credentials_create(ssl_creds, oauth2_creds, NULL); - grpc_credentials *google_iam_creds = grpc_google_iam_credentials_create( + const grpc_call_credentials_array *creds_array; + grpc_call_credentials *oauth2_creds = grpc_md_only_test_credentials_create( + "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, NULL); - grpc_credentials *composite_creds = - grpc_composite_credentials_create(aux_creds, google_iam_creds, NULL); - grpc_credentials_unref(ssl_creds); - grpc_credentials_unref(oauth2_creds); - grpc_credentials_unref(aux_creds); - grpc_credentials_unref(google_iam_creds); - GPR_ASSERT(strcmp(composite_creds->type, GRPC_CREDENTIALS_TYPE_COMPOSITE) == - 0); - GPR_ASSERT(grpc_credentials_has_request_metadata(composite_creds)); - GPR_ASSERT(!grpc_credentials_has_request_metadata_only(composite_creds)); - creds_array = grpc_composite_credentials_get_credentials(composite_creds); - GPR_ASSERT(creds_array->num_creds == 3); + 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); + GPR_ASSERT( + strcmp(composite_creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0); + creds_array = + grpc_composite_call_credentials_get_credentials(composite_creds); + GPR_ASSERT(creds_array->num_creds == 2); GPR_ASSERT(strcmp(creds_array->creds_array[0]->type, - GRPC_CREDENTIALS_TYPE_SSL) == 0); + GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0); GPR_ASSERT(strcmp(creds_array->creds_array[1]->type, - GRPC_CREDENTIALS_TYPE_OAUTH2) == 0); - GPR_ASSERT(strcmp(creds_array->creds_array[2]->type, - GRPC_CREDENTIALS_TYPE_IAM) == 0); - grpc_credentials_get_request_metadata( + GRPC_CALL_CREDENTIALS_TYPE_IAM) == 0); + grpc_call_credentials_get_request_metadata( &exec_ctx, composite_creds, NULL, test_service_url, - check_ssl_oauth2_google_iam_composite_metadata, composite_creds); + check_oauth2_google_iam_composite_metadata, composite_creds); grpc_exec_ctx_finish(&exec_ctx); } +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) { + const grpc_call_credentials_array *creds_array; + GPR_ASSERT(strcmp(c->type, "mock") == 0); + GPR_ASSERT(call_creds != NULL); + GPR_ASSERT(strcmp(call_creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == + 0); + creds_array = grpc_composite_call_credentials_get_credentials(call_creds); + GPR_ASSERT(strcmp(creds_array->creds_array[0]->type, + GRPC_CALL_CREDENTIALS_TYPE_OAUTH2) == 0); + GPR_ASSERT(strcmp(creds_array->creds_array[1]->type, + GRPC_CALL_CREDENTIALS_TYPE_IAM) == 0); + return GRPC_SECURITY_OK; +} + +static void test_channel_oauth2_google_iam_composite_creds(void) { + grpc_channel_args *new_args; + grpc_channel_credentials_vtable vtable = { + NULL, check_channel_oauth2_google_iam_create_security_connector}; + grpc_channel_credentials *channel_creds = + grpc_mock_channel_credentials_create(&vtable); + grpc_call_credentials *oauth2_creds = + grpc_access_token_credentials_create("blah", NULL); + grpc_channel_credentials *channel_oauth2_creds = + grpc_composite_channel_credentials_create(channel_creds, oauth2_creds, NULL); + grpc_call_credentials *google_iam_creds = grpc_google_iam_credentials_create( + test_google_iam_authorization_token, test_google_iam_authority_selector, + NULL); + grpc_channel_credentials *channel_oauth2_iam_creds = + grpc_composite_channel_credentials_create(channel_oauth2_creds, + google_iam_creds, NULL); + grpc_channel_credentials_release(channel_creds); + grpc_call_credentials_release(oauth2_creds); + grpc_channel_credentials_release(channel_oauth2_creds); + 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); + + grpc_channel_credentials_release(channel_oauth2_iam_creds); +} + static void on_oauth2_creds_get_metadata_success( grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, size_t num_md, grpc_credentials_status status) { GPR_ASSERT(status == GRPC_CREDENTIALS_OK); GPR_ASSERT(num_md == 1); - GPR_ASSERT(gpr_slice_str_cmp(md_elems[0].key, "Authorization") == 0); + GPR_ASSERT(gpr_slice_str_cmp(md_elems[0].key, "authorization") == 0); GPR_ASSERT(gpr_slice_str_cmp(md_elems[0].value, "Bearer ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_") == 0); @@ -545,15 +574,13 @@ static int httpcli_get_should_not_be_called( static void test_compute_engine_creds_success(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_credentials *compute_engine_creds = + grpc_call_credentials *compute_engine_creds = grpc_google_compute_engine_credentials_create(NULL); - GPR_ASSERT(grpc_credentials_has_request_metadata(compute_engine_creds)); - GPR_ASSERT(grpc_credentials_has_request_metadata_only(compute_engine_creds)); /* First request: http get should be called. */ grpc_httpcli_set_override(compute_engine_httpcli_get_success_override, httpcli_post_should_not_be_called); - grpc_credentials_get_request_metadata( + grpc_call_credentials_get_request_metadata( &exec_ctx, compute_engine_creds, NULL, test_service_url, on_oauth2_creds_get_metadata_success, (void *)test_user_data); grpc_exec_ctx_flush(&exec_ctx); @@ -561,27 +588,25 @@ static void test_compute_engine_creds_success(void) { /* Second request: the cached token should be served directly. */ grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); - grpc_credentials_get_request_metadata( + grpc_call_credentials_get_request_metadata( &exec_ctx, compute_engine_creds, NULL, test_service_url, on_oauth2_creds_get_metadata_success, (void *)test_user_data); grpc_exec_ctx_finish(&exec_ctx); - grpc_credentials_unref(compute_engine_creds); + grpc_call_credentials_unref(compute_engine_creds); grpc_httpcli_set_override(NULL, NULL); } static void test_compute_engine_creds_failure(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_credentials *compute_engine_creds = + grpc_call_credentials *compute_engine_creds = grpc_google_compute_engine_credentials_create(NULL); grpc_httpcli_set_override(compute_engine_httpcli_get_failure_override, httpcli_post_should_not_be_called); - GPR_ASSERT(grpc_credentials_has_request_metadata(compute_engine_creds)); - GPR_ASSERT(grpc_credentials_has_request_metadata_only(compute_engine_creds)); - grpc_credentials_get_request_metadata( + grpc_call_credentials_get_request_metadata( &exec_ctx, compute_engine_creds, NULL, test_service_url, on_oauth2_creds_get_metadata_failure, (void *)test_user_data); - grpc_credentials_unref(compute_engine_creds); + grpc_call_credentials_unref(compute_engine_creds); grpc_httpcli_set_override(NULL, NULL); grpc_exec_ctx_finish(&exec_ctx); } @@ -631,16 +656,14 @@ static int refresh_token_httpcli_post_failure( static void test_refresh_token_creds_success(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_credentials *refresh_token_creds = + grpc_call_credentials *refresh_token_creds = grpc_google_refresh_token_credentials_create(test_refresh_token_str, NULL); - GPR_ASSERT(grpc_credentials_has_request_metadata(refresh_token_creds)); - GPR_ASSERT(grpc_credentials_has_request_metadata_only(refresh_token_creds)); /* First request: http get should be called. */ grpc_httpcli_set_override(httpcli_get_should_not_be_called, refresh_token_httpcli_post_success); - grpc_credentials_get_request_metadata( + grpc_call_credentials_get_request_metadata( &exec_ctx, refresh_token_creds, NULL, test_service_url, on_oauth2_creds_get_metadata_success, (void *)test_user_data); grpc_exec_ctx_flush(&exec_ctx); @@ -648,29 +671,27 @@ static void test_refresh_token_creds_success(void) { /* Second request: the cached token should be served directly. */ grpc_httpcli_set_override(httpcli_get_should_not_be_called, httpcli_post_should_not_be_called); - grpc_credentials_get_request_metadata( + grpc_call_credentials_get_request_metadata( &exec_ctx, refresh_token_creds, NULL, test_service_url, on_oauth2_creds_get_metadata_success, (void *)test_user_data); grpc_exec_ctx_flush(&exec_ctx); - grpc_credentials_unref(refresh_token_creds); + grpc_call_credentials_unref(refresh_token_creds); grpc_httpcli_set_override(NULL, NULL); grpc_exec_ctx_finish(&exec_ctx); } static void test_refresh_token_creds_failure(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_credentials *refresh_token_creds = + grpc_call_credentials *refresh_token_creds = grpc_google_refresh_token_credentials_create(test_refresh_token_str, NULL); grpc_httpcli_set_override(httpcli_get_should_not_be_called, refresh_token_httpcli_post_failure); - GPR_ASSERT(grpc_credentials_has_request_metadata(refresh_token_creds)); - GPR_ASSERT(grpc_credentials_has_request_metadata_only(refresh_token_creds)); - grpc_credentials_get_request_metadata( + grpc_call_credentials_get_request_metadata( &exec_ctx, refresh_token_creds, NULL, test_service_url, on_oauth2_creds_get_metadata_failure, (void *)test_user_data); - grpc_credentials_unref(refresh_token_creds); + grpc_call_credentials_unref(refresh_token_creds); grpc_httpcli_set_override(NULL, NULL); grpc_exec_ctx_finish(&exec_ctx); } @@ -730,7 +751,7 @@ static void on_jwt_creds_get_metadata_success(grpc_exec_ctx *exec_ctx, gpr_asprintf(&expected_md_value, "Bearer %s", test_signed_jwt); GPR_ASSERT(status == GRPC_CREDENTIALS_OK); GPR_ASSERT(num_md == 1); - GPR_ASSERT(gpr_slice_str_cmp(md_elems[0].key, "Authorization") == 0); + GPR_ASSERT(gpr_slice_str_cmp(md_elems[0].key, "authorization") == 0); GPR_ASSERT(gpr_slice_str_cmp(md_elems[0].value, expected_md_value) == 0); GPR_ASSERT(user_data != NULL); GPR_ASSERT(strcmp((const char *)user_data, test_user_data) == 0); @@ -751,15 +772,13 @@ static void on_jwt_creds_get_metadata_failure(grpc_exec_ctx *exec_ctx, 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_credentials *jwt_creds = + grpc_call_credentials *jwt_creds = grpc_service_account_jwt_access_credentials_create( json_key_string, grpc_max_auth_token_lifetime, NULL); - GPR_ASSERT(grpc_credentials_has_request_metadata(jwt_creds)); - GPR_ASSERT(grpc_credentials_has_request_metadata_only(jwt_creds)); /* First request: jwt_encode_and_sign should be called. */ grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success); - grpc_credentials_get_request_metadata( + grpc_call_credentials_get_request_metadata( &exec_ctx, jwt_creds, NULL, test_service_url, on_jwt_creds_get_metadata_success, (void *)test_user_data); grpc_exec_ctx_flush(&exec_ctx); @@ -767,7 +786,7 @@ static void test_jwt_creds_success(void) { /* Second request: the cached token should be served directly. */ grpc_jwt_encode_and_sign_set_override( encode_and_sign_jwt_should_not_be_called); - grpc_credentials_get_request_metadata( + grpc_call_credentials_get_request_metadata( &exec_ctx, jwt_creds, NULL, test_service_url, on_jwt_creds_get_metadata_success, (void *)test_user_data); grpc_exec_ctx_flush(&exec_ctx); @@ -775,32 +794,30 @@ static void test_jwt_creds_success(void) { /* Third request: Different service url so jwt_encode_and_sign should be called again (no caching). */ grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success); - grpc_credentials_get_request_metadata( + grpc_call_credentials_get_request_metadata( &exec_ctx, jwt_creds, NULL, other_test_service_url, on_jwt_creds_get_metadata_success, (void *)test_user_data); grpc_exec_ctx_flush(&exec_ctx); gpr_free(json_key_string); - grpc_credentials_unref(jwt_creds); + grpc_call_credentials_unref(jwt_creds); grpc_jwt_encode_and_sign_set_override(NULL); } 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_credentials *jwt_creds = + grpc_call_credentials *jwt_creds = grpc_service_account_jwt_access_credentials_create( json_key_string, grpc_max_auth_token_lifetime, NULL); - GPR_ASSERT(grpc_credentials_has_request_metadata(jwt_creds)); - GPR_ASSERT(grpc_credentials_has_request_metadata_only(jwt_creds)); grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_failure); - grpc_credentials_get_request_metadata( + grpc_call_credentials_get_request_metadata( &exec_ctx, jwt_creds, NULL, test_service_url, on_jwt_creds_get_metadata_failure, (void *)test_user_data); gpr_free(json_key_string); - grpc_credentials_unref(jwt_creds); + grpc_call_credentials_unref(jwt_creds); grpc_jwt_encode_and_sign_set_override(NULL); grpc_exec_ctx_finish(&exec_ctx); } @@ -818,52 +835,39 @@ static void set_google_default_creds_env_var_with_file_contents( gpr_free(creds_file_name); } -static grpc_credentials *composite_inner_creds(grpc_credentials *creds, - const char *inner_creds_type) { - size_t i; - grpc_composite_credentials *composite; - GPR_ASSERT(strcmp(creds->type, GRPC_CREDENTIALS_TYPE_COMPOSITE) == 0); - composite = (grpc_composite_credentials *)creds; - for (i = 0; i < composite->inner.num_creds; i++) { - grpc_credentials *c = composite->inner.creds_array[i]; - if (strcmp(c->type, inner_creds_type) == 0) return c; - } - GPR_ASSERT(0); /* Not found. */ -} - static void test_google_default_creds_auth_key(void) { grpc_service_account_jwt_access_credentials *jwt; - grpc_credentials *creds; + grpc_composite_channel_credentials *creds; char *json_key = test_json_key_str(); grpc_flush_cached_google_default_credentials(); set_google_default_creds_env_var_with_file_contents( "json_key_google_default_creds", json_key); gpr_free(json_key); - creds = grpc_google_default_credentials_create(); + creds = (grpc_composite_channel_credentials *) + grpc_google_default_credentials_create(); GPR_ASSERT(creds != NULL); - jwt = (grpc_service_account_jwt_access_credentials *)composite_inner_creds( - creds, GRPC_CREDENTIALS_TYPE_JWT); + jwt = (grpc_service_account_jwt_access_credentials *)creds->call_creds; GPR_ASSERT( strcmp(jwt->key.client_id, "777-abaslkan11hlb6nmim3bpspl31ud.apps.googleusercontent.com") == 0); - grpc_credentials_unref(creds); + grpc_channel_credentials_unref(&creds->base); gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ } static void test_google_default_creds_access_token(void) { grpc_google_refresh_token_credentials *refresh; - grpc_credentials *creds; + grpc_composite_channel_credentials *creds; grpc_flush_cached_google_default_credentials(); set_google_default_creds_env_var_with_file_contents( "refresh_token_google_default_creds", test_refresh_token_str); - creds = grpc_google_default_credentials_create(); + creds = (grpc_composite_channel_credentials *) + grpc_google_default_credentials_create(); GPR_ASSERT(creds != NULL); - refresh = (grpc_google_refresh_token_credentials *)composite_inner_creds( - creds, GRPC_CREDENTIALS_TYPE_OAUTH2); + refresh = (grpc_google_refresh_token_credentials *)creds->call_creds; GPR_ASSERT(strcmp(refresh->refresh_token.client_id, "32555999999.apps.googleusercontent.com") == 0); - grpc_credentials_unref(creds); + grpc_channel_credentials_unref(&creds->base); gpr_setenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR, ""); /* Reset. */ } @@ -935,7 +939,7 @@ static void plugin_destroy(void *state) { } static void test_metadata_plugin_success(void) { - grpc_credentials *creds; + grpc_call_credentials *creds; plugin_state state = PLUGIN_INITIAL_STATE; grpc_metadata_credentials_plugin plugin; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; @@ -946,17 +950,17 @@ static void test_metadata_plugin_success(void) { creds = grpc_metadata_credentials_create_from_plugin(plugin, NULL); GPR_ASSERT(state == PLUGIN_INITIAL_STATE); - grpc_credentials_get_request_metadata( + grpc_call_credentials_get_request_metadata( &exec_ctx, creds, NULL, test_service_url, on_plugin_metadata_received_success, NULL); GPR_ASSERT(state == PLUGIN_GET_METADATA_CALLED_STATE); - grpc_credentials_release(creds); + grpc_call_credentials_release(creds); GPR_ASSERT(state == PLUGIN_DESTROY_CALLED_STATE); grpc_exec_ctx_finish(&exec_ctx); } static void test_metadata_plugin_failure(void) { - grpc_credentials *creds; + grpc_call_credentials *creds; plugin_state state = PLUGIN_INITIAL_STATE; grpc_metadata_credentials_plugin plugin; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; @@ -967,11 +971,11 @@ static void test_metadata_plugin_failure(void) { creds = grpc_metadata_credentials_create_from_plugin(plugin, NULL); GPR_ASSERT(state == PLUGIN_INITIAL_STATE); - grpc_credentials_get_request_metadata( + grpc_call_credentials_get_request_metadata( &exec_ctx, creds, NULL, test_service_url, on_plugin_metadata_received_failure, NULL); GPR_ASSERT(state == PLUGIN_GET_METADATA_CALLED_STATE); - grpc_credentials_release(creds); + grpc_call_credentials_release(creds); GPR_ASSERT(state == PLUGIN_DESTROY_CALLED_STATE); grpc_exec_ctx_finish(&exec_ctx); } @@ -993,8 +997,9 @@ int main(int argc, char **argv) { test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime(); test_google_iam_creds(); test_access_token_creds(); - test_ssl_oauth2_composite_creds(); - test_ssl_oauth2_google_iam_composite_creds(); + test_channel_oauth2_composite_creds(); + test_oauth2_google_iam_composite_creds(); + test_channel_oauth2_google_iam_composite_creds(); test_compute_engine_creds_success(); test_compute_engine_creds_failure(); test_refresh_token_creds_success(); diff --git a/test/core/security/fetch_oauth2.c b/test/core/security/fetch_oauth2.c index 764d8da9b6..ee1178cbdd 100644 --- a/test/core/security/fetch_oauth2.c +++ b/test/core/security/fetch_oauth2.c @@ -46,7 +46,7 @@ #include "src/core/support/file.h" #include "test/core/security/oauth2_utils.h" -static grpc_credentials *create_refresh_token_creds( +static grpc_call_credentials *create_refresh_token_creds( const char *json_refresh_token_file_path) { int success; gpr_slice refresh_token = @@ -60,7 +60,7 @@ static grpc_credentials *create_refresh_token_creds( } int main(int argc, char **argv) { - grpc_credentials *creds = NULL; + grpc_call_credentials *creds = NULL; char *json_key_file_path = NULL; char *json_refresh_token_file_path = NULL; char *token = NULL; @@ -115,7 +115,7 @@ int main(int argc, char **argv) { printf("Got token: %s.\n", token); gpr_free(token); } - grpc_credentials_release(creds); + grpc_call_credentials_release(creds); gpr_cmdline_destroy(cl); grpc_shutdown(); return 0; diff --git a/test/core/security/oauth2_utils.c b/test/core/security/oauth2_utils.c index f99d170592..fcfe8a6377 100644 --- a/test/core/security/oauth2_utils.c +++ b/test/core/security/oauth2_utils.c @@ -75,7 +75,8 @@ static void on_oauth2_response(grpc_exec_ctx *exec_ctx, void *user_data, static void do_nothing(grpc_exec_ctx *exec_ctx, void *unused, int success) {} -char *grpc_test_fetch_oauth2_token_with_credentials(grpc_credentials *creds) { +char *grpc_test_fetch_oauth2_token_with_credentials( + grpc_call_credentials *creds) { oauth2_request request; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_closure do_nothing_closure; @@ -84,8 +85,8 @@ char *grpc_test_fetch_oauth2_token_with_credentials(grpc_credentials *creds) { grpc_closure_init(&do_nothing_closure, do_nothing, NULL); - grpc_credentials_get_request_metadata(&exec_ctx, creds, &request.pollset, "", - on_oauth2_response, &request); + grpc_call_credentials_get_request_metadata(&exec_ctx, creds, &request.pollset, + "", on_oauth2_response, &request); grpc_exec_ctx_finish(&exec_ctx); diff --git a/test/core/security/oauth2_utils.h b/test/core/security/oauth2_utils.h index 8082351b8a..b35fe7987f 100644 --- a/test/core/security/oauth2_utils.h +++ b/test/core/security/oauth2_utils.h @@ -42,7 +42,8 @@ extern "C" { /* Fetch oauth2 access token with a credentials object. Does not take ownership. Returns NULL on a failure. The caller should call gpr_free on the token. */ -char *grpc_test_fetch_oauth2_token_with_credentials(grpc_credentials *creds); +char *grpc_test_fetch_oauth2_token_with_credentials( + grpc_call_credentials *creds); #ifdef __cplusplus } diff --git a/test/core/security/print_google_default_creds_token.c b/test/core/security/print_google_default_creds_token.c index f207e05794..eb63724715 100644 --- a/test/core/security/print_google_default_creds_token.c +++ b/test/core/security/print_google_default_creds_token.c @@ -72,7 +72,7 @@ int main(int argc, char **argv) { int result = 0; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; synchronizer sync; - grpc_credentials *creds = NULL; + grpc_channel_credentials *creds = NULL; char *service_url = "https://test.foo.google.com/Foo"; gpr_cmdline *cl = gpr_cmdline_create("print_google_default_creds_token"); gpr_cmdline_add_string(cl, "service_url", @@ -91,9 +91,9 @@ int main(int argc, char **argv) { grpc_pollset_init(&sync.pollset); sync.is_done = 0; - grpc_credentials_get_request_metadata(&exec_ctx, creds, &sync.pollset, - service_url, on_metadata_response, - &sync); + grpc_call_credentials_get_request_metadata( + &exec_ctx, ((grpc_composite_channel_credentials *)creds)->call_creds, + &sync.pollset, service_url, on_metadata_response, &sync); gpr_mu_lock(GRPC_POLLSET_MU(&sync.pollset)); while (!sync.is_done) { @@ -107,7 +107,7 @@ int main(int argc, char **argv) { } gpr_mu_unlock(GRPC_POLLSET_MU(&sync.pollset)); - grpc_credentials_release(creds); + grpc_channel_credentials_release(creds); end: gpr_cmdline_destroy(cl); diff --git a/test/core/transport/chttp2/hpack_encoder_test.c b/test/core/transport/chttp2/hpack_encoder_test.c new file mode 100644 index 0000000000..6553e0da20 --- /dev/null +++ b/test/core/transport/chttp2/hpack_encoder_test.c @@ -0,0 +1,200 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/transport/chttp2/hpack_encoder.h" + +#include <stdio.h> + +#include "src/core/support/string.h" +#include "src/core/transport/chttp2/hpack_parser.h" +#include <grpc/support/alloc.h> +#include <grpc/support/log.h> +#include <grpc/support/string_util.h> +#include "test/core/util/parse_hexstring.h" +#include "test/core/util/slice_splitter.h" +#include "test/core/util/test_config.h" + +#define TEST(x) run_test(x, #x) + +grpc_mdctx *g_mdctx; +grpc_chttp2_hpack_compressor g_compressor; +int g_failure = 0; + +void **to_delete = NULL; +size_t num_to_delete = 0; +size_t cap_to_delete = 0; + +/* verify that the output generated by encoding the stream matches the + hexstring passed in */ +static void verify(size_t window_available, int eof, size_t expect_window_used, + const char *expected, size_t nheaders, ...) { + gpr_slice_buffer output; + gpr_slice merged; + gpr_slice expect = parse_hexstring(expected); + size_t i; + va_list l; + grpc_linked_mdelem *e = gpr_malloc(sizeof(*e) * nheaders); + grpc_metadata_batch b; + + grpc_metadata_batch_init(&b); + + va_start(l, nheaders); + for (i = 0; i < nheaders; i++) { + char *key = va_arg(l, char *); + char *value = va_arg(l, char *); + if (i) { + e[i - 1].next = &e[i]; + e[i].prev = &e[i - 1]; + } + e[i].md = grpc_mdelem_from_strings(g_mdctx, key, value); + } + e[0].prev = NULL; + e[nheaders - 1].next = NULL; + va_end(l); + + b.list.head = &e[0]; + b.list.tail = &e[nheaders - 1]; + + if (cap_to_delete == num_to_delete) { + cap_to_delete = GPR_MAX(2 * cap_to_delete, 1000); + to_delete = gpr_realloc(to_delete, sizeof(*to_delete) * cap_to_delete); + } + to_delete[num_to_delete++] = e; + + gpr_slice_buffer_init(&output); + + grpc_chttp2_encode_header(&g_compressor, 0xdeadbeef, &b, eof, &output); + merged = grpc_slice_merge(output.slices, output.count); + gpr_slice_buffer_destroy(&output); + grpc_metadata_batch_destroy(&b); + + if (0 != gpr_slice_cmp(merged, expect)) { + char *expect_str = gpr_dump_slice(expect, GPR_DUMP_HEX | GPR_DUMP_ASCII); + char *got_str = gpr_dump_slice(merged, GPR_DUMP_HEX | GPR_DUMP_ASCII); + gpr_log(GPR_ERROR, "mismatched output for %s", expected); + gpr_log(GPR_ERROR, "EXPECT: %s", expect_str); + gpr_log(GPR_ERROR, "GOT: %s", got_str); + gpr_free(expect_str); + gpr_free(got_str); + g_failure = 1; + } + + gpr_slice_unref(merged); + gpr_slice_unref(expect); +} + +static void test_basic_headers(void) { + int i; + + verify(0, 0, 0, "000005 0104 deadbeef 40 0161 0161", 1, "a", "a"); + verify(0, 0, 0, "000001 0104 deadbeef be", 1, "a", "a"); + verify(0, 0, 0, "000001 0104 deadbeef be", 1, "a", "a"); + verify(0, 0, 0, "000006 0104 deadbeef be 40 0162 0163", 2, "a", "a", "b", + "c"); + verify(0, 0, 0, "000002 0104 deadbeef bf be", 2, "a", "a", "b", "c"); + verify(0, 0, 0, "000004 0104 deadbeef 7f 00 0164", 1, "a", "d"); + + /* flush out what's there to make a few values look very popular */ + for (i = 0; i < 350; i++) { + verify(0, 0, 0, "000003 0104 deadbeef c0 bf be", 3, "a", "a", "b", "c", "a", + "d"); + } + + verify(0, 0, 0, "000006 0104 deadbeef c0 00 016b 0176", 2, "a", "a", "k", + "v"); + /* this could be 000004 0104 deadbeef 0f 30 0176 also */ + verify(0, 0, 0, "000004 0104 deadbeef 0f 2f 0176", 1, "a", "v"); +} + +static void encode_int_to_str(int i, char *p) { + p[0] = (char)('a' + i % 26); + i /= 26; + GPR_ASSERT(i < 26); + p[1] = (char)('a' + i); + p[2] = 0; +} + +static void test_decode_table_overflow(void) { + int i; + char key[3], value[3]; + char *expect; + + for (i = 0; i < 114; i++) { + encode_int_to_str(i, key); + encode_int_to_str(i + 1, value); + + if (i + 61 >= 127) { + gpr_asprintf(&expect, + "000009 0104 deadbeef ff%02x 40 02%02x%02x 02%02x%02x", + i + 61 - 127, key[0], key[1], value[0], value[1]); + } else if (i > 0) { + gpr_asprintf(&expect, + "000008 0104 deadbeef %02x 40 02%02x%02x 02%02x%02x", + 0x80 + 61 + i, key[0], key[1], value[0], value[1]); + } else { + gpr_asprintf(&expect, "000007 0104 deadbeef 40 02%02x%02x 02%02x%02x", + key[0], key[1], value[0], value[1]); + } + + if (i > 0) { + verify(0, 0, 0, expect, 2, "aa", "ba", key, value); + } else { + verify(0, 0, 0, expect, 1, key, value); + } + gpr_free(expect); + } + + /* if the above passes, then we must have just knocked this pair out of the + decoder stack, and so we'll be forced to re-encode it */ + verify(0, 0, 0, "000007 0104 deadbeef 40 026161 026261", 1, "aa", "ba"); +} + +static void run_test(void (*test)(), const char *name) { + gpr_log(GPR_INFO, "RUN TEST: %s", name); + g_mdctx = grpc_mdctx_create_with_seed(0); + grpc_chttp2_hpack_compressor_init(&g_compressor, g_mdctx); + test(); + grpc_chttp2_hpack_compressor_destroy(&g_compressor); + grpc_mdctx_unref(g_mdctx); +} + +int main(int argc, char **argv) { + size_t i; + grpc_test_init(argc, argv); + TEST(test_basic_headers); + TEST(test_decode_table_overflow); + for (i = 0; i < num_to_delete; i++) { + gpr_free(to_delete[i]); + } + return g_failure; +} diff --git a/test/core/transport/chttp2/stream_encoder_test.c b/test/core/transport/chttp2/stream_encoder_test.c deleted file mode 100644 index 71db98c69e..0000000000 --- a/test/core/transport/chttp2/stream_encoder_test.c +++ /dev/null @@ -1,359 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/transport/chttp2/stream_encoder.h" - -#include <stdio.h> - -#include "src/core/support/string.h" -#include "src/core/transport/chttp2/hpack_parser.h" -#include <grpc/support/alloc.h> -#include <grpc/support/log.h> -#include <grpc/support/string_util.h> -#include "test/core/util/parse_hexstring.h" -#include "test/core/util/slice_splitter.h" -#include "test/core/util/test_config.h" - -#define TEST(x) run_test(x, #x) - -grpc_mdctx *g_mdctx; -grpc_chttp2_hpack_compressor g_compressor; -int g_failure = 0; -grpc_stream_op_buffer g_sopb; - -void **to_delete = NULL; -size_t num_to_delete = 0; -size_t cap_to_delete = 0; - -static gpr_slice create_test_slice(size_t length) { - gpr_slice slice = gpr_slice_malloc(length); - size_t i; - for (i = 0; i < length; i++) { - GPR_SLICE_START_PTR(slice)[i] = (gpr_uint8)i; - } - return slice; -} - -/* verify that the output generated by encoding the stream matches the - hexstring passed in */ -static void verify_sopb(size_t window_available, int eof, - size_t expect_window_used, const char *expected) { - gpr_slice_buffer output; - grpc_stream_op_buffer encops; - gpr_slice merged; - gpr_slice expect = parse_hexstring(expected); - gpr_slice_buffer_init(&output); - grpc_sopb_init(&encops); - GPR_ASSERT(expect_window_used == - grpc_chttp2_preencode(g_sopb.ops, &g_sopb.nops, - (gpr_uint32)window_available, &encops)); - grpc_chttp2_encode(encops.ops, encops.nops, eof, 0xdeadbeef, &g_compressor, - &output); - encops.nops = 0; - merged = grpc_slice_merge(output.slices, output.count); - gpr_slice_buffer_destroy(&output); - grpc_sopb_destroy(&encops); - - if (0 != gpr_slice_cmp(merged, expect)) { - char *expect_str = gpr_dump_slice(expect, GPR_DUMP_HEX | GPR_DUMP_ASCII); - char *got_str = gpr_dump_slice(merged, GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_ERROR, "mismatched output for %s", expected); - gpr_log(GPR_ERROR, "EXPECT: %s", expect_str); - gpr_log(GPR_ERROR, "GOT: %s", got_str); - gpr_free(expect_str); - gpr_free(got_str); - g_failure = 1; - } - - gpr_slice_unref(merged); - gpr_slice_unref(expect); -} - -static void test_small_data_framing(void) { - grpc_sopb_add_no_op(&g_sopb); - verify_sopb(10, 0, 0, ""); - - grpc_sopb_add_slice(&g_sopb, create_test_slice(3)); - verify_sopb(10, 0, 3, "000003 0000 deadbeef 000102"); - - grpc_sopb_add_slice(&g_sopb, create_test_slice(4)); - verify_sopb(10, 0, 4, "000004 0000 deadbeef 00010203"); - - grpc_sopb_add_slice(&g_sopb, create_test_slice(3)); - grpc_sopb_add_slice(&g_sopb, create_test_slice(4)); - verify_sopb(10, 0, 7, "000007 0000 deadbeef 000102 00010203"); - - grpc_sopb_add_slice(&g_sopb, create_test_slice(0)); - grpc_sopb_add_slice(&g_sopb, create_test_slice(0)); - grpc_sopb_add_slice(&g_sopb, create_test_slice(0)); - grpc_sopb_add_slice(&g_sopb, create_test_slice(0)); - grpc_sopb_add_slice(&g_sopb, create_test_slice(3)); - verify_sopb(10, 0, 3, "000003 0000 deadbeef 000102"); - - verify_sopb(10, 1, 0, "000000 0001 deadbeef"); - - grpc_sopb_add_begin_message(&g_sopb, 255, 0); - verify_sopb(10, 0, 5, "000005 0000 deadbeef 00000000ff"); -} - -static void add_sopb_headers(size_t n, ...) { - size_t i; - grpc_metadata_batch b; - va_list l; - grpc_linked_mdelem *e = gpr_malloc(sizeof(*e) * n); - - grpc_metadata_batch_init(&b); - - va_start(l, n); - for (i = 0; i < n; i++) { - char *key = va_arg(l, char *); - char *value = va_arg(l, char *); - if (i) { - e[i - 1].next = &e[i]; - e[i].prev = &e[i - 1]; - } - e[i].md = grpc_mdelem_from_strings(g_mdctx, key, value); - } - e[0].prev = NULL; - e[n - 1].next = NULL; - va_end(l); - - b.list.head = &e[0]; - b.list.tail = &e[n - 1]; - - if (cap_to_delete == num_to_delete) { - cap_to_delete = GPR_MAX(2 * cap_to_delete, 1000); - to_delete = gpr_realloc(to_delete, sizeof(*to_delete) * cap_to_delete); - } - to_delete[num_to_delete++] = e; - - grpc_sopb_add_metadata(&g_sopb, b); -} - -static void test_basic_headers(void) { - int i; - - add_sopb_headers(1, "a", "a"); - verify_sopb(0, 0, 0, "000005 0104 deadbeef 40 0161 0161"); - - add_sopb_headers(1, "a", "a"); - verify_sopb(0, 0, 0, "000001 0104 deadbeef be"); - - add_sopb_headers(1, "a", "a"); - verify_sopb(0, 0, 0, "000001 0104 deadbeef be"); - - add_sopb_headers(2, "a", "a", "b", "c"); - verify_sopb(0, 0, 0, "000006 0104 deadbeef be 40 0162 0163"); - - add_sopb_headers(2, "a", "a", "b", "c"); - verify_sopb(0, 0, 0, "000002 0104 deadbeef bf be"); - - add_sopb_headers(1, "a", "d"); - verify_sopb(0, 0, 0, "000004 0104 deadbeef 7f 00 0164"); - - /* flush out what's there to make a few values look very popular */ - for (i = 0; i < 350; i++) { - add_sopb_headers(3, "a", "a", "b", "c", "a", "d"); - verify_sopb(0, 0, 0, "000003 0104 deadbeef c0 bf be"); - } - - add_sopb_headers(2, "a", "a", "k", "v"); - verify_sopb(0, 0, 0, "000006 0104 deadbeef c0 00 016b 0176"); - - add_sopb_headers(1, "a", "v"); - /* this could be 000004 0104 deadbeef 0f 30 0176 also */ - verify_sopb(0, 0, 0, "000004 0104 deadbeef 0f 2f 0176"); -} - -static void encode_int_to_str(int i, char *p) { - p[0] = (char)('a' + i % 26); - i /= 26; - GPR_ASSERT(i < 26); - p[1] = (char)('a' + i); - p[2] = 0; -} - -static void test_decode_table_overflow(void) { - int i; - char key[3], value[3]; - char *expect; - - for (i = 0; i < 114; i++) { - if (i > 0) { - add_sopb_headers(1, "aa", "ba"); - } - - encode_int_to_str(i, key); - encode_int_to_str(i + 1, value); - - if (i + 61 >= 127) { - gpr_asprintf(&expect, - "000002 0104 deadbeef ff%02x 000007 0104 deadbeef 40 " - "02%02x%02x 02%02x%02x", - i + 61 - 127, key[0], key[1], value[0], value[1]); - } else if (i > 0) { - gpr_asprintf(&expect, - "000001 0104 deadbeef %02x 000007 0104 deadbeef 40 " - "02%02x%02x 02%02x%02x", - 0x80 + 61 + i, key[0], key[1], value[0], value[1]); - } else { - gpr_asprintf(&expect, "000007 0104 deadbeef 40 02%02x%02x 02%02x%02x", - key[0], key[1], value[0], value[1]); - } - - add_sopb_headers(1, key, value); - verify_sopb(0, 0, 0, expect); - gpr_free(expect); - } - - /* if the above passes, then we must have just knocked this pair out of the - decoder stack, and so we'll be forced to re-encode it */ - add_sopb_headers(1, "aa", "ba"); - verify_sopb(0, 0, 0, "000007 0104 deadbeef 40 026161 026261"); -} - -static void randstr(char *p, int bufsz) { - int i; - int len = 1 + rand() % bufsz; - for (i = 0; i < len; i++) { - p[i] = (char)('a' + rand() % 26); - } - p[len] = 0; -} - -typedef struct { - char key[300]; - char value[300]; - int got_hdr; -} test_decode_random_header_state; - -static void chk_hdr(void *p, grpc_mdelem *el) { - test_decode_random_header_state *st = p; - GPR_ASSERT(0 == gpr_slice_str_cmp(el->key->slice, st->key)); - GPR_ASSERT(0 == gpr_slice_str_cmp(el->value->slice, st->value)); - st->got_hdr = 1; - GRPC_MDELEM_UNREF(el); -} - -static void test_decode_random_headers_inner(int max_len) { - int i; - test_decode_random_header_state st; - gpr_slice_buffer output; - gpr_slice merged; - grpc_stream_op_buffer encops; - grpc_chttp2_hpack_parser parser; - - grpc_chttp2_hpack_parser_init(&parser, g_mdctx); - grpc_sopb_init(&encops); - - gpr_log(GPR_INFO, "max_len = %d", max_len); - - for (i = 0; i < 10000; i++) { - randstr(st.key, max_len); - randstr(st.value, max_len); - - add_sopb_headers(1, st.key, st.value); - gpr_slice_buffer_init(&output); - GPR_ASSERT(0 == - grpc_chttp2_preencode(g_sopb.ops, &g_sopb.nops, 0, &encops)); - grpc_chttp2_encode(encops.ops, encops.nops, 0, 0xdeadbeef, &g_compressor, - &output); - encops.nops = 0; - merged = grpc_slice_merge(output.slices, output.count); - gpr_slice_buffer_destroy(&output); - - st.got_hdr = 0; - parser.on_header = chk_hdr; - parser.on_header_user_data = &st; - grpc_chttp2_hpack_parser_parse(&parser, GPR_SLICE_START_PTR(merged) + 9, - GPR_SLICE_END_PTR(merged)); - GPR_ASSERT(st.got_hdr); - - gpr_slice_unref(merged); - } - - grpc_chttp2_hpack_parser_destroy(&parser); - grpc_sopb_destroy(&encops); -} - -#define DECL_TEST_DECODE_RANDOM_HEADERS(n) \ - static void test_decode_random_headers_##n(void) { \ - test_decode_random_headers_inner(n); \ - } \ - int keeps_formatting_correct_##n - -DECL_TEST_DECODE_RANDOM_HEADERS(1); -DECL_TEST_DECODE_RANDOM_HEADERS(2); -DECL_TEST_DECODE_RANDOM_HEADERS(3); -DECL_TEST_DECODE_RANDOM_HEADERS(5); -DECL_TEST_DECODE_RANDOM_HEADERS(8); -DECL_TEST_DECODE_RANDOM_HEADERS(13); -DECL_TEST_DECODE_RANDOM_HEADERS(21); -DECL_TEST_DECODE_RANDOM_HEADERS(34); -DECL_TEST_DECODE_RANDOM_HEADERS(55); -DECL_TEST_DECODE_RANDOM_HEADERS(89); -DECL_TEST_DECODE_RANDOM_HEADERS(144); - -static void run_test(void (*test)(), const char *name) { - gpr_log(GPR_INFO, "RUN TEST: %s", name); - g_mdctx = grpc_mdctx_create_with_seed(0); - grpc_chttp2_hpack_compressor_init(&g_compressor, g_mdctx); - grpc_sopb_init(&g_sopb); - test(); - grpc_chttp2_hpack_compressor_destroy(&g_compressor); - grpc_mdctx_unref(g_mdctx); - grpc_sopb_destroy(&g_sopb); -} - -int main(int argc, char **argv) { - size_t i; - grpc_test_init(argc, argv); - TEST(test_small_data_framing); - TEST(test_basic_headers); - TEST(test_decode_table_overflow); - TEST(test_decode_random_headers_1); - TEST(test_decode_random_headers_2); - TEST(test_decode_random_headers_3); - TEST(test_decode_random_headers_5); - TEST(test_decode_random_headers_8); - TEST(test_decode_random_headers_13); - TEST(test_decode_random_headers_21); - TEST(test_decode_random_headers_34); - TEST(test_decode_random_headers_55); - TEST(test_decode_random_headers_89); - TEST(test_decode_random_headers_144); - for (i = 0; i < num_to_delete; i++) { - gpr_free(to_delete[i]); - } - return g_failure; -} diff --git a/test/core/transport/stream_op_test.c b/test/core/transport/stream_op_test.c deleted file mode 100644 index 546080deb9..0000000000 --- a/test/core/transport/stream_op_test.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/transport/stream_op.h" - -#include <string.h> - -#include <grpc/support/log.h> -#include "test/core/util/test_config.h" - -static void assert_slices_equal(gpr_slice a, gpr_slice b) { - GPR_ASSERT(a.refcount == b.refcount); - if (a.refcount) { - GPR_ASSERT(a.data.refcounted.bytes == b.data.refcounted.bytes); - GPR_ASSERT(a.data.refcounted.length == b.data.refcounted.length); - } else { - GPR_ASSERT(a.data.inlined.length == b.data.inlined.length); - GPR_ASSERT(0 == memcmp(a.data.inlined.bytes, b.data.inlined.bytes, - a.data.inlined.length)); - } -} - -int main(int argc, char **argv) { - /* some basic test data */ - gpr_slice test_slice_1 = gpr_slice_malloc(1); - gpr_slice test_slice_2 = gpr_slice_malloc(2); - gpr_slice test_slice_3 = gpr_slice_malloc(3); - gpr_slice test_slice_4 = gpr_slice_malloc(4); - unsigned i; - - grpc_stream_op_buffer buf; - grpc_stream_op_buffer buf2; - - grpc_test_init(argc, argv); - /* initialize one of our buffers */ - grpc_sopb_init(&buf); - /* it should start out empty */ - GPR_ASSERT(buf.nops == 0); - - /* add some data to the buffer */ - grpc_sopb_add_begin_message(&buf, 1, 2); - grpc_sopb_add_slice(&buf, test_slice_1); - grpc_sopb_add_slice(&buf, test_slice_2); - grpc_sopb_add_slice(&buf, test_slice_3); - grpc_sopb_add_slice(&buf, test_slice_4); - grpc_sopb_add_no_op(&buf); - - /* verify that the data went in ok */ - GPR_ASSERT(buf.nops == 6); - GPR_ASSERT(buf.ops[0].type == GRPC_OP_BEGIN_MESSAGE); - GPR_ASSERT(buf.ops[0].data.begin_message.length == 1); - GPR_ASSERT(buf.ops[0].data.begin_message.flags == 2); - GPR_ASSERT(buf.ops[1].type == GRPC_OP_SLICE); - assert_slices_equal(buf.ops[1].data.slice, test_slice_1); - GPR_ASSERT(buf.ops[2].type == GRPC_OP_SLICE); - assert_slices_equal(buf.ops[2].data.slice, test_slice_2); - GPR_ASSERT(buf.ops[3].type == GRPC_OP_SLICE); - assert_slices_equal(buf.ops[3].data.slice, test_slice_3); - GPR_ASSERT(buf.ops[4].type == GRPC_OP_SLICE); - assert_slices_equal(buf.ops[4].data.slice, test_slice_4); - GPR_ASSERT(buf.ops[5].type == GRPC_NO_OP); - - /* initialize the second buffer */ - grpc_sopb_init(&buf2); - /* add a no-op, and then the original buffer */ - grpc_sopb_add_no_op(&buf2); - grpc_sopb_append(&buf2, buf.ops, buf.nops); - /* should be one element bigger than the original */ - GPR_ASSERT(buf2.nops == buf.nops + 1); - GPR_ASSERT(buf2.ops[0].type == GRPC_NO_OP); - /* and the tail should be the same */ - for (i = 0; i < buf.nops; i++) { - GPR_ASSERT(buf2.ops[i + 1].type == buf.ops[i].type); - } - - /* destroy the buffers */ - grpc_sopb_destroy(&buf); - grpc_sopb_destroy(&buf2); - - gpr_slice_unref(test_slice_1); - gpr_slice_unref(test_slice_2); - gpr_slice_unref(test_slice_3); - gpr_slice_unref(test_slice_4); - - return 0; -} diff --git a/test/cpp/client/credentials_test.cc b/test/cpp/client/credentials_test.cc index 743ad065d1..418a54439a 100644 --- a/test/cpp/client/credentials_test.cc +++ b/test/cpp/client/credentials_test.cc @@ -46,8 +46,8 @@ class CredentialsTest : public ::testing::Test { }; TEST_F(CredentialsTest, InvalidGoogleRefreshToken) { - std::shared_ptr<Credentials> bad1 = GoogleRefreshTokenCredentials(""); - EXPECT_EQ(static_cast<Credentials*>(nullptr), bad1.get()); + std::shared_ptr<CallCredentials> bad1 = GoogleRefreshTokenCredentials(""); + EXPECT_EQ(static_cast<CallCredentials*>(nullptr), bad1.get()); } } // namespace testing diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index cfb6c21edc..74290c36d2 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -199,7 +199,7 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<bool> { void ResetStub() { std::shared_ptr<Channel> channel = - CreateChannel(server_address_.str(), InsecureCredentials()); + CreateChannel(server_address_.str(), InsecureChannelCredentials()); stub_ = grpc::cpp::test::util::TestService::NewStub(channel); } @@ -749,7 +749,7 @@ TEST_P(AsyncEnd2endTest, ServerCheckDone) { TEST_P(AsyncEnd2endTest, UnimplementedRpc) { std::shared_ptr<Channel> channel = - CreateChannel(server_address_.str(), InsecureCredentials()); + CreateChannel(server_address_.str(), InsecureChannelCredentials()); std::unique_ptr<grpc::cpp::test::util::UnimplementedService::Stub> stub; stub = grpc::cpp::test::util::UnimplementedService::NewStub(channel); EchoRequest send_request; diff --git a/test/cpp/end2end/client_crash_test.cc b/test/cpp/end2end/client_crash_test.cc index 058e696166..116785bbf2 100644 --- a/test/cpp/end2end/client_crash_test.cc +++ b/test/cpp/end2end/client_crash_test.cc @@ -74,7 +74,7 @@ class CrashTest : public ::testing::Test { })); GPR_ASSERT(server_); return grpc::cpp::test::util::TestService::NewStub( - CreateChannel(addr, InsecureCredentials())); + CreateChannel(addr, InsecureChannelCredentials())); } void KillServer() { server_.reset(); } diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 89a556c587..6da933302c 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -146,13 +146,13 @@ class TestAuthMetadataProcessor : public AuthMetadataProcessor { TestAuthMetadataProcessor(bool is_blocking) : is_blocking_(is_blocking) {} - std::shared_ptr<Credentials> GetCompatibleClientCreds() { + std::shared_ptr<CallCredentials> GetCompatibleClientCreds() { return MetadataCredentialsFromPlugin( std::unique_ptr<MetadataCredentialsPlugin>( new TestMetadataCredentialsPlugin(kGoodGuy, is_blocking_, true))); } - std::shared_ptr<Credentials> GetIncompatibleClientCreds() { + std::shared_ptr<CallCredentials> GetIncompatibleClientCreds() { return MetadataCredentialsFromPlugin( std::unique_ptr<MetadataCredentialsPlugin>( new TestMetadataCredentialsPlugin("Mr Hyde", is_blocking_, true))); @@ -407,7 +407,7 @@ class End2endTest : public ::testing::TestWithParam<TestScenario> { } EXPECT_TRUE(is_server_started_); ChannelArguments args; - auto channel_creds = InsecureCredentials(); + auto channel_creds = InsecureChannelCredentials(); if (GetParam().use_tls) { SslCredentialsOptions ssl_opts = {test_root_cert, "", ""}; args.SetSslTargetNameOverride("foo.test.google.fr"); @@ -429,7 +429,7 @@ class End2endTest : public ::testing::TestWithParam<TestScenario> { builder.RegisterService(proxy_service_.get()); proxy_server_ = builder.BuildAndStart(); - channel_ = CreateChannel(proxyaddr.str(), InsecureCredentials()); + channel_ = CreateChannel(proxyaddr.str(), InsecureChannelCredentials()); } stub_ = grpc::cpp::test::util::TestService::NewStub(channel_); @@ -575,6 +575,18 @@ void CancelRpc(ClientContext* context, int delay_us, TestServiceImpl* service) { context->TryCancel(); } +TEST_P(End2endTest, CancelRpcBeforeStart) { + ResetStub(); + EchoRequest request; + EchoResponse response; + ClientContext context; + request.set_message("hello"); + context.TryCancel(); + Status s = stub_->Echo(&context, request, &response); + EXPECT_EQ("", response.message()); + EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code()); +} + // Client cancels request stream after sending two messages TEST_P(End2endTest, ClientCancelsRequestStream) { ResetStub(); @@ -751,7 +763,8 @@ TEST_P(End2endTest, ChannelStateTimeout) { std::ostringstream server_address; server_address << "127.0.0.1:" << port; // Channel to non-existing server - auto channel = CreateChannel(server_address.str(), InsecureCredentials()); + auto channel = + CreateChannel(server_address.str(), InsecureChannelCredentials()); // Start IDLE EXPECT_EQ(GRPC_CHANNEL_IDLE, channel->GetState(true)); @@ -971,33 +984,6 @@ TEST_P(SecureEnd2endTest, SimpleRpcWithHost) { EXPECT_TRUE(s.ok()); } -// rpc and stream should fail on bad credentials. -TEST_P(SecureEnd2endTest, BadCredentials) { - std::shared_ptr<Credentials> bad_creds = GoogleRefreshTokenCredentials(""); - EXPECT_EQ(static_cast<Credentials*>(nullptr), bad_creds.get()); - std::shared_ptr<Channel> channel = - CreateChannel(server_address_.str(), bad_creds); - std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub( - grpc::cpp::test::util::TestService::NewStub(channel)); - EchoRequest request; - EchoResponse response; - ClientContext context; - request.set_message("Hello"); - - Status s = stub->Echo(&context, request, &response); - EXPECT_EQ("", response.message()); - EXPECT_FALSE(s.ok()); - EXPECT_EQ(StatusCode::INVALID_ARGUMENT, s.error_code()); - EXPECT_EQ("Invalid credentials.", s.error_message()); - - ClientContext context2; - auto stream = stub->BidiStream(&context2); - s = stream->Finish(); - EXPECT_FALSE(s.ok()); - EXPECT_EQ(StatusCode::INVALID_ARGUMENT, s.error_code()); - EXPECT_EQ("Invalid credentials.", s.error_message()); -} - bool MetadataContains( const std::multimap<grpc::string_ref, grpc::string_ref>& metadata, const grpc::string& key, const grpc::string& value) { @@ -1055,7 +1041,7 @@ TEST_P(SecureEnd2endTest, SetPerCallCredentials) { EchoRequest request; EchoResponse response; ClientContext context; - std::shared_ptr<Credentials> creds = + std::shared_ptr<CallCredentials> creds = GoogleIAMCredentials("fake_token", "fake_selector"); context.set_credentials(creds); request.set_message("Hello"); @@ -1072,30 +1058,15 @@ TEST_P(SecureEnd2endTest, SetPerCallCredentials) { "fake_selector")); } -TEST_P(SecureEnd2endTest, InsecurePerCallCredentials) { - ResetStub(); - EchoRequest request; - EchoResponse response; - ClientContext context; - std::shared_ptr<Credentials> creds = InsecureCredentials(); - context.set_credentials(creds); - request.set_message("Hello"); - request.mutable_param()->set_echo_metadata(true); - - Status s = stub_->Echo(&context, request, &response); - EXPECT_EQ(StatusCode::CANCELLED, s.error_code()); - EXPECT_EQ("Failed to set credentials to rpc.", s.error_message()); -} - TEST_P(SecureEnd2endTest, OverridePerCallCredentials) { ResetStub(); EchoRequest request; EchoResponse response; ClientContext context; - std::shared_ptr<Credentials> creds1 = + std::shared_ptr<CallCredentials> creds1 = GoogleIAMCredentials("fake_token1", "fake_selector1"); context.set_credentials(creds1); - std::shared_ptr<Credentials> creds2 = + std::shared_ptr<CallCredentials> creds2 = GoogleIAMCredentials("fake_token2", "fake_selector2"); context.set_credentials(creds2); request.set_message("Hello"); @@ -1217,14 +1188,14 @@ TEST_P(SecureEnd2endTest, ClientAuthContext) { } INSTANTIATE_TEST_CASE_P(End2end, End2endTest, - ::testing::Values(TestScenario(false, true), - TestScenario(false, false))); + ::testing::Values(TestScenario(false, false), + TestScenario(false, true))); INSTANTIATE_TEST_CASE_P(ProxyEnd2end, ProxyEnd2endTest, - ::testing::Values(TestScenario(true, true), - TestScenario(true, false), + ::testing::Values(TestScenario(false, false), TestScenario(false, true), - TestScenario(false, false))); + TestScenario(true, false), + TestScenario(true, true))); INSTANTIATE_TEST_CASE_P(SecureEnd2end, SecureEnd2endTest, ::testing::Values(TestScenario(false, true))); diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc index 6a46916728..082119d6d5 100644 --- a/test/cpp/end2end/generic_end2end_test.cc +++ b/test/cpp/end2end/generic_end2end_test.cc @@ -120,7 +120,7 @@ class GenericEnd2endTest : public ::testing::Test { void ResetStub() { std::shared_ptr<Channel> channel = - CreateChannel(server_address_.str(), InsecureCredentials()); + CreateChannel(server_address_.str(), InsecureChannelCredentials()); generic_stub_.reset(new GenericStub(channel)); } diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index 80057d893e..bd34cfba67 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -244,7 +244,7 @@ class MockTest : public ::testing::Test { void ResetStub() { std::shared_ptr<Channel> channel = - CreateChannel(server_address_.str(), InsecureCredentials()); + CreateChannel(server_address_.str(), InsecureChannelCredentials()); stub_ = grpc::cpp::test::util::TestService::NewStub(channel); } diff --git a/test/cpp/end2end/server_crash_test_client.cc b/test/cpp/end2end/server_crash_test_client.cc index 17869362c2..2baefcbf42 100644 --- a/test/cpp/end2end/server_crash_test_client.cc +++ b/test/cpp/end2end/server_crash_test_client.cc @@ -58,7 +58,7 @@ using namespace gflags; int main(int argc, char** argv) { ParseCommandLineFlags(&argc, &argv, true); auto stub = grpc::cpp::test::util::TestService::NewStub( - grpc::CreateChannel(FLAGS_address, grpc::InsecureCredentials())); + grpc::CreateChannel(FLAGS_address, grpc::InsecureChannelCredentials())); EchoRequest request; EchoResponse response; diff --git a/test/cpp/end2end/shutdown_test.cc b/test/cpp/end2end/shutdown_test.cc index 0549bb8b5f..b1b18b2a7f 100644 --- a/test/cpp/end2end/shutdown_test.cc +++ b/test/cpp/end2end/shutdown_test.cc @@ -93,7 +93,7 @@ class ShutdownTest : public ::testing::Test { void ResetStub() { string target = "dns:localhost:" + to_string(port_); - channel_ = CreateChannel(target, InsecureCredentials()); + channel_ = CreateChannel(target, InsecureChannelCredentials()); stub_ = grpc::cpp::test::util::TestService::NewStub(channel_); } diff --git a/test/cpp/end2end/streaming_throughput_test.cc b/test/cpp/end2end/streaming_throughput_test.cc index d4ab1486cc..b7e103a1ae 100644 --- a/test/cpp/end2end/streaming_throughput_test.cc +++ b/test/cpp/end2end/streaming_throughput_test.cc @@ -160,7 +160,7 @@ class End2endTest : public ::testing::Test { void ResetStub() { std::shared_ptr<Channel> channel = - CreateChannel(server_address_.str(), InsecureCredentials()); + CreateChannel(server_address_.str(), InsecureChannelCredentials()); stub_ = grpc::cpp::test::util::TestService::NewStub(channel); } diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 75a07d89c5..fb82b96135 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -190,7 +190,7 @@ class End2endTest : public ::testing::Test { void ResetStub() { std::shared_ptr<Channel> channel = - CreateChannel(server_address_.str(), InsecureCredentials()); + CreateChannel(server_address_.str(), InsecureChannelCredentials()); stub_ = grpc::cpp::test::util::TestService::NewStub(channel); } diff --git a/test/cpp/end2end/zookeeper_test.cc b/test/cpp/end2end/zookeeper_test.cc index d4c7f0489f..e88c0f9c68 100644 --- a/test/cpp/end2end/zookeeper_test.cc +++ b/test/cpp/end2end/zookeeper_test.cc @@ -157,7 +157,7 @@ class ZookeeperTest : public ::testing::Test { void ResetStub() { string target = "zookeeper://" + zookeeper_address_ + "/test"; - channel_ = CreateChannel(target, InsecureCredentials()); + channel_ = CreateChannel(target, InsecureChannelCredentials()); stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel_)); } diff --git a/test/cpp/interop/client_helper.cc b/test/cpp/interop/client_helper.cc index 61b46d25aa..5caf0f2d1d 100644 --- a/test/cpp/interop/client_helper.cc +++ b/test/cpp/interop/client_helper.cc @@ -76,11 +76,11 @@ grpc::string GetServiceAccountJsonKey() { } grpc::string GetOauth2AccessToken() { - std::shared_ptr<Credentials> creds = GoogleComputeEngineCredentials(); - SecureCredentials* secure_creds = - dynamic_cast<SecureCredentials*>(creds.get()); + std::shared_ptr<CallCredentials> creds = GoogleComputeEngineCredentials(); + SecureCallCredentials* secure_creds = + dynamic_cast<SecureCallCredentials*>(creds.get()); GPR_ASSERT(secure_creds != nullptr); - grpc_credentials* c_creds = secure_creds->GetRawCreds(); + grpc_call_credentials* c_creds = secure_creds->GetRawCreds(); char* token = grpc_test_fetch_oauth2_token_with_credentials(c_creds); GPR_ASSERT(token != nullptr); gpr_log(GPR_INFO, "Get raw oauth2 access token: %s", token); @@ -98,13 +98,13 @@ std::shared_ptr<Channel> CreateChannelForTestCase( FLAGS_server_port); if (test_case == "compute_engine_creds") { - std::shared_ptr<Credentials> creds; + std::shared_ptr<CallCredentials> creds; GPR_ASSERT(FLAGS_use_tls); creds = GoogleComputeEngineCredentials(); return CreateTestChannel(host_port, FLAGS_server_host_override, FLAGS_use_tls, !FLAGS_use_test_ca, creds); } else if (test_case == "jwt_token_creds") { - std::shared_ptr<Credentials> creds; + std::shared_ptr<CallCredentials> creds; GPR_ASSERT(FLAGS_use_tls); grpc::string json_key = GetServiceAccountJsonKey(); std::chrono::seconds token_lifetime = std::chrono::hours(1); @@ -114,7 +114,7 @@ std::shared_ptr<Channel> CreateChannelForTestCase( FLAGS_use_tls, !FLAGS_use_test_ca, creds); } else if (test_case == "oauth2_auth_token") { grpc::string raw_token = GetOauth2AccessToken(); - std::shared_ptr<Credentials> creds = AccessTokenCredentials(raw_token); + std::shared_ptr<CallCredentials> creds = AccessTokenCredentials(raw_token); return CreateTestChannel(host_port, FLAGS_server_host_override, FLAGS_use_tls, !FLAGS_use_test_ca, creds); } else { diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index 96502e5879..6340007fa4 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -46,7 +46,7 @@ #include <grpc++/client_context.h> #include <grpc++/security/credentials.h> -#include "src/core/transport/stream_op.h" +#include "src/core/transport/byte_stream.h" #include "test/cpp/interop/client_helper.h" #include "test/proto/test.grpc.pb.h" #include "test/proto/empty.grpc.pb.h" @@ -244,7 +244,7 @@ void InteropClient::DoPerRpcCreds(const grpc::string& json_key) { ClientContext context; std::chrono::seconds token_lifetime = std::chrono::hours(1); - std::shared_ptr<Credentials> creds = + std::shared_ptr<CallCredentials> creds = ServiceAccountJWTAccessCredentials(json_key, token_lifetime.count()); context.set_credentials(creds); diff --git a/test/cpp/interop/stress_interop_client.cc b/test/cpp/interop/stress_interop_client.cc index f8c55cf795..3be2571493 100644 --- a/test/cpp/interop/stress_interop_client.cc +++ b/test/cpp/interop/stress_interop_client.cc @@ -89,9 +89,9 @@ StressTestInteropClient::StressTestInteropClient( test_duration_secs_(test_duration_secs), sleep_duration_ms_(sleep_duration_ms) { // TODO(sreek): This will change once we add support for other tests - // that won't work with InsecureCredentials() + // that won't work with InsecureChannelCredentials() std::shared_ptr<Channel> channel( - CreateChannel(server_address, InsecureCredentials())); + CreateChannel(server_address, InsecureChannelCredentials())); interop_client_.reset(new InteropClient(channel, false)); } diff --git a/test/cpp/interop/stress_test.cc b/test/cpp/interop/stress_test.cc index 5d1419728e..018f4ab4f7 100644 --- a/test/cpp/interop/stress_test.cc +++ b/test/cpp/interop/stress_test.cc @@ -41,6 +41,7 @@ #include <grpc/support/time.h> #include <grpc++/create_channel.h> #include <grpc++/grpc++.h> +#include <grpc++/impl/thd.h> #include "test/cpp/interop/interop_client.h" #include "test/cpp/interop/stress_interop_client.h" @@ -80,7 +81,6 @@ DEFINE_string(test_cases, "", using std::make_pair; using std::pair; -using std::thread; using std::vector; using grpc::testing::kTestCaseList; @@ -202,7 +202,7 @@ int main(int argc, char** argv) { gpr_log(GPR_INFO, "Starting test(s).."); - vector<thread> test_threads; + vector<grpc::thread> test_threads; int thread_idx = 0; for (auto it = server_addresses.begin(); it != server_addresses.end(); it++) { StressTestInteropClient* client = new StressTestInteropClient( @@ -210,7 +210,7 @@ int main(int argc, char** argv) { FLAGS_sleep_duration_ms); test_threads.emplace_back( - thread(&StressTestInteropClient::MainLoop, client)); + grpc::thread(&StressTestInteropClient::MainLoop, client)); } for (auto it = test_threads.begin(); it != test_threads.end(); it++) { diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index 2c6247deea..67bdcb2f32 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -162,7 +162,7 @@ std::unique_ptr<ScenarioResult> RunScenario( auto* servers = new ServerData[num_servers]; for (size_t i = 0; i < num_servers; i++) { servers[i].stub = WorkerService::NewStub( - CreateChannel(workers[i], InsecureCredentials())); + CreateChannel(workers[i], InsecureChannelCredentials())); ServerArgs args; result_server_config = server_config; *args.mutable_setup() = server_config; @@ -189,7 +189,7 @@ std::unique_ptr<ScenarioResult> RunScenario( auto* clients = new ClientData[num_clients]; for (size_t i = 0; i < num_clients; i++) { clients[i].stub = WorkerService::NewStub( - CreateChannel(workers[i + num_servers], InsecureCredentials())); + CreateChannel(workers[i + num_servers], InsecureChannelCredentials())); ClientArgs args; result_client_config = client_config; *args.mutable_setup() = client_config; diff --git a/test/cpp/qps/report.h b/test/cpp/qps/report.h index 78779231d3..5caf3fe69a 100644 --- a/test/cpp/qps/report.h +++ b/test/cpp/qps/report.h @@ -115,8 +115,8 @@ class PerfDbReporter : public Reporter { test_name_(test_name), sys_info_(sys_info), tag_(tag) { - perf_db_client_.init( - grpc::CreateChannel(server_address, grpc::InsecureCredentials())); + perf_db_client_.init(grpc::CreateChannel( + server_address, grpc::InsecureChannelCredentials())); } ~PerfDbReporter() GRPC_OVERRIDE { SendData(); }; diff --git a/test/cpp/util/cli_call_test.cc b/test/cpp/util/cli_call_test.cc index 9c8d59987e..32cd8e4103 100644 --- a/test/cpp/util/cli_call_test.cc +++ b/test/cpp/util/cli_call_test.cc @@ -89,7 +89,8 @@ class CliCallTest : public ::testing::Test { void TearDown() GRPC_OVERRIDE { server_->Shutdown(); } void ResetStub() { - channel_ = CreateChannel(server_address_.str(), InsecureCredentials()); + channel_ = + CreateChannel(server_address_.str(), InsecureChannelCredentials()); stub_ = grpc::cpp::test::util::TestService::NewStub(channel_); } diff --git a/test/cpp/util/create_test_channel.cc b/test/cpp/util/create_test_channel.cc index f0d5bfc7eb..0cd9f9e767 100644 --- a/test/cpp/util/create_test_channel.cc +++ b/test/cpp/util/create_test_channel.cc @@ -58,13 +58,14 @@ namespace grpc { std::shared_ptr<Channel> CreateTestChannel( const grpc::string& server, const grpc::string& override_hostname, bool enable_ssl, bool use_prod_roots, - const std::shared_ptr<Credentials>& creds) { + const std::shared_ptr<CallCredentials>& creds) { ChannelArguments channel_args; if (enable_ssl) { const char* roots_certs = use_prod_roots ? "" : test_root_cert; SslCredentialsOptions ssl_opts = {roots_certs, "", ""}; - std::shared_ptr<Credentials> channel_creds = SslCredentials(ssl_opts); + std::shared_ptr<ChannelCredentials> channel_creds = + SslCredentials(ssl_opts); if (!server.empty() && !override_hostname.empty()) { channel_args.SetSslTargetNameOverride(override_hostname); @@ -72,11 +73,11 @@ std::shared_ptr<Channel> CreateTestChannel( const grpc::string& connect_to = server.empty() ? override_hostname : server; if (creds.get()) { - channel_creds = CompositeCredentials(creds, channel_creds); + channel_creds = CompositeChannelCredentials(channel_creds, creds); } return CreateCustomChannel(connect_to, channel_creds, channel_args); } else { - return CreateChannel(server, InsecureCredentials()); + return CreateChannel(server, InsecureChannelCredentials()); } } @@ -84,7 +85,7 @@ std::shared_ptr<Channel> CreateTestChannel( const grpc::string& server, const grpc::string& override_hostname, bool enable_ssl, bool use_prod_roots) { return CreateTestChannel(server, override_hostname, enable_ssl, - use_prod_roots, std::shared_ptr<Credentials>()); + use_prod_roots, std::shared_ptr<CallCredentials>()); } // Shortcut for end2end and interop tests. diff --git a/test/cpp/util/create_test_channel.h b/test/cpp/util/create_test_channel.h index a4750689a0..b50d653de3 100644 --- a/test/cpp/util/create_test_channel.h +++ b/test/cpp/util/create_test_channel.h @@ -51,7 +51,7 @@ std::shared_ptr<Channel> CreateTestChannel( std::shared_ptr<Channel> CreateTestChannel( const grpc::string& server, const grpc::string& override_hostname, bool enable_ssl, bool use_prod_roots, - const std::shared_ptr<Credentials>& creds); + const std::shared_ptr<CallCredentials>& creds); } // namespace grpc diff --git a/test/cpp/util/grpc_cli.cc b/test/cpp/util/grpc_cli.cc index 334b6efb6a..3f40b242fc 100644 --- a/test/cpp/util/grpc_cli.cc +++ b/test/cpp/util/grpc_cli.cc @@ -148,9 +148,9 @@ int main(int argc, char** argv) { std::stringstream input_stream; input_stream << input_file.rdbuf(); - std::shared_ptr<grpc::Credentials> creds; + std::shared_ptr<grpc::ChannelCredentials> creds; if (!FLAGS_enable_ssl) { - creds = grpc::InsecureCredentials(); + creds = grpc::InsecureChannelCredentials(); } else { if (FLAGS_use_auth) { creds = grpc::GoogleDefaultCredentials(); |