diff options
Diffstat (limited to 'test')
45 files changed, 1030 insertions, 107 deletions
diff --git a/test/core/client_channel/resolvers/dns_resolver_test.cc b/test/core/client_channel/resolvers/dns_resolver_test.cc index e3fba2838c..103b2916c4 100644 --- a/test/core/client_channel/resolvers/dns_resolver_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_test.cc @@ -70,11 +70,12 @@ int main(int argc, char** argv) { test_succeeds(dns, "dns:10.2.1.1"); test_succeeds(dns, "dns:10.2.1.1:1234"); - test_succeeds(dns, "ipv4:www.google.com"); + test_succeeds(dns, "dns:www.google.com"); + test_succeeds(dns, "dns:///www.google.com"); if (grpc_resolve_address == grpc_resolve_address_ares) { - test_succeeds(dns, "ipv4://8.8.8.8/8.8.8.8:8888"); + test_succeeds(dns, "dns://8.8.8.8/8.8.8.8:8888"); } else { - test_fails(dns, "ipv4://8.8.8.8/8.8.8.8:8888"); + test_fails(dns, "dns://8.8.8.8/8.8.8.8:8888"); } { diff --git a/test/core/end2end/end2end_nosec_tests.cc b/test/core/end2end/end2end_nosec_tests.cc index 297408cd92..59eb643a93 100644 --- a/test/core/end2end/end2end_nosec_tests.cc +++ b/test/core/end2end/end2end_nosec_tests.cc @@ -132,6 +132,8 @@ extern void retry_exceeds_buffer_size_in_subsequent_batch(grpc_end2end_test_conf extern void retry_exceeds_buffer_size_in_subsequent_batch_pre_init(void); extern void retry_non_retriable_status(grpc_end2end_test_config config); extern void retry_non_retriable_status_pre_init(void); +extern void retry_non_retriable_status_before_recv_trailing_metadata_started(grpc_end2end_test_config config); +extern void retry_non_retriable_status_before_recv_trailing_metadata_started_pre_init(void); extern void retry_recv_initial_metadata(grpc_end2end_test_config config); extern void retry_recv_initial_metadata_pre_init(void); extern void retry_recv_message(grpc_end2end_test_config config); @@ -236,6 +238,7 @@ void grpc_end2end_tests_pre_init(void) { retry_exceeds_buffer_size_in_initial_batch_pre_init(); retry_exceeds_buffer_size_in_subsequent_batch_pre_init(); retry_non_retriable_status_pre_init(); + retry_non_retriable_status_before_recv_trailing_metadata_started_pre_init(); retry_recv_initial_metadata_pre_init(); retry_recv_message_pre_init(); retry_server_pushback_delay_pre_init(); @@ -320,6 +323,7 @@ void grpc_end2end_tests(int argc, char **argv, retry_exceeds_buffer_size_in_initial_batch(config); retry_exceeds_buffer_size_in_subsequent_batch(config); retry_non_retriable_status(config); + retry_non_retriable_status_before_recv_trailing_metadata_started(config); retry_recv_initial_metadata(config); retry_recv_message(config); retry_server_pushback_delay(config); @@ -552,6 +556,10 @@ void grpc_end2end_tests(int argc, char **argv, retry_non_retriable_status(config); continue; } + if (0 == strcmp("retry_non_retriable_status_before_recv_trailing_metadata_started", argv[i])) { + retry_non_retriable_status_before_recv_trailing_metadata_started(config); + continue; + } if (0 == strcmp("retry_recv_initial_metadata", argv[i])) { retry_recv_initial_metadata(config); continue; diff --git a/test/core/end2end/end2end_tests.cc b/test/core/end2end/end2end_tests.cc index 9b3f655254..9f164b4ead 100644 --- a/test/core/end2end/end2end_tests.cc +++ b/test/core/end2end/end2end_tests.cc @@ -134,6 +134,8 @@ extern void retry_exceeds_buffer_size_in_subsequent_batch(grpc_end2end_test_conf extern void retry_exceeds_buffer_size_in_subsequent_batch_pre_init(void); extern void retry_non_retriable_status(grpc_end2end_test_config config); extern void retry_non_retriable_status_pre_init(void); +extern void retry_non_retriable_status_before_recv_trailing_metadata_started(grpc_end2end_test_config config); +extern void retry_non_retriable_status_before_recv_trailing_metadata_started_pre_init(void); extern void retry_recv_initial_metadata(grpc_end2end_test_config config); extern void retry_recv_initial_metadata_pre_init(void); extern void retry_recv_message(grpc_end2end_test_config config); @@ -239,6 +241,7 @@ void grpc_end2end_tests_pre_init(void) { retry_exceeds_buffer_size_in_initial_batch_pre_init(); retry_exceeds_buffer_size_in_subsequent_batch_pre_init(); retry_non_retriable_status_pre_init(); + retry_non_retriable_status_before_recv_trailing_metadata_started_pre_init(); retry_recv_initial_metadata_pre_init(); retry_recv_message_pre_init(); retry_server_pushback_delay_pre_init(); @@ -324,6 +327,7 @@ void grpc_end2end_tests(int argc, char **argv, retry_exceeds_buffer_size_in_initial_batch(config); retry_exceeds_buffer_size_in_subsequent_batch(config); retry_non_retriable_status(config); + retry_non_retriable_status_before_recv_trailing_metadata_started(config); retry_recv_initial_metadata(config); retry_recv_message(config); retry_server_pushback_delay(config); @@ -560,6 +564,10 @@ void grpc_end2end_tests(int argc, char **argv, retry_non_retriable_status(config); continue; } + if (0 == strcmp("retry_non_retriable_status_before_recv_trailing_metadata_started", argv[i])) { + retry_non_retriable_status_before_recv_trailing_metadata_started(config); + continue; + } if (0 == strcmp("retry_recv_initial_metadata", argv[i])) { retry_recv_initial_metadata(config); continue; diff --git a/test/core/end2end/gen_build_yaml.py b/test/core/end2end/gen_build_yaml.py index c7b0362574..c355fc24b5 100755 --- a/test/core/end2end/gen_build_yaml.py +++ b/test/core/end2end/gen_build_yaml.py @@ -170,6 +170,9 @@ END2END_TESTS = { proxyable=False), 'retry_non_retriable_status': default_test_options._replace( cpu_cost=LOWCPU, needs_client_channel=True, proxyable=False), + 'retry_non_retriable_status_before_recv_trailing_metadata_started': + default_test_options._replace( + cpu_cost=LOWCPU, needs_client_channel=True, proxyable=False), 'retry_recv_initial_metadata': default_test_options._replace( cpu_cost=LOWCPU, needs_client_channel=True, proxyable=False), 'retry_recv_message': default_test_options._replace( diff --git a/test/core/end2end/generate_tests.bzl b/test/core/end2end/generate_tests.bzl index 37fd1837f4..11fc576165 100755 --- a/test/core/end2end/generate_tests.bzl +++ b/test/core/end2end/generate_tests.bzl @@ -158,6 +158,8 @@ END2END_TESTS = { needs_client_channel=True, proxyable=False), 'retry_non_retriable_status': test_options(needs_client_channel=True, proxyable=False), + 'retry_non_retriable_status_before_recv_trailing_metadata_started': + test_options(needs_client_channel=True, proxyable=False), 'retry_recv_initial_metadata': test_options(needs_client_channel=True, proxyable=False), 'retry_recv_message': test_options(needs_client_channel=True, diff --git a/test/core/end2end/tests/retry_non_retriable_status_before_recv_trailing_metadata_started.cc b/test/core/end2end/tests/retry_non_retriable_status_before_recv_trailing_metadata_started.cc new file mode 100644 index 0000000000..eb016a3de9 --- /dev/null +++ b/test/core/end2end/tests/retry_non_retriable_status_before_recv_trailing_metadata_started.cc @@ -0,0 +1,266 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/end2end/end2end_tests.h" + +#include <stdio.h> +#include <string.h> + +#include <grpc/byte_buffer.h> +#include <grpc/grpc.h> +#include <grpc/support/alloc.h> +#include <grpc/support/log.h> +#include <grpc/support/string_util.h> +#include <grpc/support/time.h> + +#include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/gpr/string.h" +#include "src/core/lib/gpr/useful.h" +#include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/lib/transport/static_metadata.h" + +#include "test/core/end2end/cq_verifier.h" +#include "test/core/end2end/tests/cancel_test_helpers.h" + +static void* tag(intptr_t 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, "Running test: %s/%s", test_name, config.name); + f = config.create_fixture(client_args, server_args); + config.init_server(&f, server_args); + config.init_client(&f, client_args); + return f; +} + +static gpr_timespec n_seconds_from_now(int n) { + return grpc_timeout_seconds_to_deadline(n); +} + +static gpr_timespec five_seconds_from_now(void) { + return n_seconds_from_now(5); +} + +static void drain_cq(grpc_completion_queue* cq) { + grpc_event ev; + do { + ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr); + } 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->shutdown_cq, tag(1000)); + GPR_ASSERT(grpc_completion_queue_pluck(f->shutdown_cq, tag(1000), + grpc_timeout_seconds_to_deadline(5), + nullptr) + .type == GRPC_OP_COMPLETE); + grpc_server_destroy(f->server); + f->server = nullptr; +} + +static void shutdown_client(grpc_end2end_test_fixture* f) { + if (!f->client) return; + grpc_channel_destroy(f->client); + f->client = nullptr; +} + +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); + grpc_completion_queue_destroy(f->shutdown_cq); +} + +// Tests that we don't retry for non-retryable status codes, even if +// status is received before the recv_trailing_metadata op is started. +// - 1 retry allowed for ABORTED status +// - first attempt gets INVALID_ARGUMENT, so no retry is done +static void +test_retry_non_retriable_status_before_recv_trailing_metadata_started( + grpc_end2end_test_config config) { + grpc_call* c; + grpc_call* s; + grpc_op ops[6]; + grpc_op* op; + grpc_metadata_array initial_metadata_recv; + grpc_metadata_array trailing_metadata_recv; + grpc_metadata_array request_metadata_recv; + grpc_call_details call_details; + grpc_slice request_payload_slice = grpc_slice_from_static_string("foo"); + grpc_slice response_payload_slice = grpc_slice_from_static_string("bar"); + grpc_byte_buffer* request_payload = + grpc_raw_byte_buffer_create(&request_payload_slice, 1); + grpc_byte_buffer* response_payload = + grpc_raw_byte_buffer_create(&response_payload_slice, 1); + grpc_byte_buffer* request_payload_recv = nullptr; + grpc_byte_buffer* response_payload_recv = nullptr; + grpc_status_code status; + grpc_call_error error; + grpc_slice details; + int was_cancelled = 2; + char* peer; + + grpc_arg arg; + arg.type = GRPC_ARG_STRING; + arg.key = const_cast<char*>(GRPC_ARG_SERVICE_CONFIG); + arg.value.string = const_cast<char*>( + "{\n" + " \"methodConfig\": [ {\n" + " \"name\": [\n" + " { \"service\": \"service\", \"method\": \"method\" }\n" + " ],\n" + " \"retryPolicy\": {\n" + " \"maxAttempts\": 2,\n" + " \"initialBackoff\": \"1s\",\n" + " \"maxBackoff\": \"120s\",\n" + " \"backoffMultiplier\": 1.6,\n" + " \"retryableStatusCodes\": [ \"ABORTED\" ]\n" + " }\n" + " } ]\n" + "}"); + grpc_channel_args client_args = {1, &arg}; + grpc_end2end_test_fixture f = + begin_test(config, "retry_non_retriable_status", &client_args, nullptr); + + cq_verifier* cqv = cq_verifier_create(f.cq); + + gpr_timespec deadline = five_seconds_from_now(); + c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/service/method"), + nullptr, deadline, nullptr); + GPR_ASSERT(c); + + peer = grpc_call_get_peer(c); + GPR_ASSERT(peer != nullptr); + gpr_log(GPR_DEBUG, "client_peer_before_call=%s", peer); + gpr_free(peer); + + grpc_metadata_array_init(&initial_metadata_recv); + grpc_metadata_array_init(&trailing_metadata_recv); + grpc_metadata_array_init(&request_metadata_recv); + grpc_call_details_init(&call_details); + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op++; + op->op = GRPC_OP_SEND_MESSAGE; + op->data.send_message.send_message = request_payload; + op++; + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message.recv_message = &response_payload_recv; + op++; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv; + op++; + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), nullptr); + GPR_ASSERT(GRPC_CALL_OK == error); + + error = + grpc_server_request_call(f.server, &s, &call_details, + &request_metadata_recv, f.cq, f.cq, tag(101)); + GPR_ASSERT(GRPC_CALL_OK == error); + CQ_EXPECT_COMPLETION(cqv, tag(101), true); + cq_verify(cqv); + + peer = grpc_call_get_peer(s); + GPR_ASSERT(peer != nullptr); + gpr_log(GPR_DEBUG, "server_peer=%s", peer); + gpr_free(peer); + peer = grpc_call_get_peer(c); + GPR_ASSERT(peer != nullptr); + gpr_log(GPR_DEBUG, "client_peer=%s", peer); + gpr_free(peer); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op++; + op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; + op->data.send_status_from_server.trailing_metadata_count = 0; + op->data.send_status_from_server.status = GRPC_STATUS_INVALID_ARGUMENT; + op->data.send_status_from_server.status_details = &status_details; + op++; + op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; + op->data.recv_close_on_server.cancelled = &was_cancelled; + op++; + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), nullptr); + GPR_ASSERT(GRPC_CALL_OK == error); + + CQ_EXPECT_COMPLETION(cqv, tag(102), true); + CQ_EXPECT_COMPLETION(cqv, tag(1), true); + cq_verify(cqv); + + memset(ops, 0, sizeof(ops)); + 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++; + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), nullptr); + GPR_ASSERT(GRPC_CALL_OK == error); + + CQ_EXPECT_COMPLETION(cqv, tag(2), true); + cq_verify(cqv); + + GPR_ASSERT(status == GRPC_STATUS_INVALID_ARGUMENT); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/service/method")); + GPR_ASSERT(0 == call_details.flags); + GPR_ASSERT(was_cancelled == 1); + + grpc_slice_unref(details); + grpc_metadata_array_destroy(&initial_metadata_recv); + grpc_metadata_array_destroy(&trailing_metadata_recv); + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_details_destroy(&call_details); + grpc_byte_buffer_destroy(request_payload); + grpc_byte_buffer_destroy(response_payload); + grpc_byte_buffer_destroy(request_payload_recv); + grpc_byte_buffer_destroy(response_payload_recv); + + grpc_call_unref(c); + grpc_call_unref(s); + + cq_verifier_destroy(cqv); + + end_test(&f); + config.tear_down_data(&f); +} + +void retry_non_retriable_status_before_recv_trailing_metadata_started( + grpc_end2end_test_config config) { + GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL); + test_retry_non_retriable_status_before_recv_trailing_metadata_started(config); +} + +void retry_non_retriable_status_before_recv_trailing_metadata_started_pre_init() { +} diff --git a/test/core/gprpp/ref_counted_ptr_test.cc b/test/core/gprpp/ref_counted_ptr_test.cc index 2e398a7722..c810345166 100644 --- a/test/core/gprpp/ref_counted_ptr_test.cc +++ b/test/core/gprpp/ref_counted_ptr_test.cc @@ -88,7 +88,7 @@ TEST(RefCountedPtr, CopyAssignmentWhenEmpty) { TEST(RefCountedPtr, CopyAssignmentToSelf) { RefCountedPtr<Foo> foo(New<Foo>()); - foo = foo; + foo = *&foo; // The "*&" avoids warnings from LLVM -Wself-assign. } TEST(RefCountedPtr, EnclosedScope) { diff --git a/test/core/handshake/readahead_handshaker_server_ssl.cc b/test/core/handshake/readahead_handshaker_server_ssl.cc index 9788320e0d..97e9c20ee4 100644 --- a/test/core/handshake/readahead_handshaker_server_ssl.cc +++ b/test/core/handshake/readahead_handshaker_server_ssl.cc @@ -64,7 +64,7 @@ static void readahead_handshaker_do_handshake( const grpc_handshaker_vtable readahead_handshaker_vtable = { readahead_handshaker_destroy, readahead_handshaker_shutdown, - readahead_handshaker_do_handshake}; + readahead_handshaker_do_handshake, "read_ahead"}; static grpc_handshaker* readahead_handshaker_create() { grpc_handshaker* h = diff --git a/test/core/iomgr/udp_server_test.cc b/test/core/iomgr/udp_server_test.cc index 3058e87bea..d167c0131f 100644 --- a/test/core/iomgr/udp_server_test.cc +++ b/test/core/iomgr/udp_server_test.cc @@ -40,6 +40,7 @@ #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/iomgr/socket_factory_posix.h" +#include "src/core/lib/iomgr/socket_utils_posix.h" #include "test/core/util/test_config.h" #define LOG_TEST(x) gpr_log(GPR_INFO, "%s", #x) @@ -55,6 +56,8 @@ static int g_number_of_starts = 0; int rcv_buf_size = 1024; int snd_buf_size = 1024; +static int g_num_listeners = 1; + class TestGrpcUdpHandler : public GrpcUdpHandler { public: TestGrpcUdpHandler(grpc_fd* emfd, void* user_data) @@ -75,6 +78,7 @@ class TestGrpcUdpHandler : public GrpcUdpHandler { g_number_of_reads++; g_number_of_bytes_read += static_cast<int>(byte_count); + gpr_log(GPR_DEBUG, "receive %zu on handler %p", byte_count, this); GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr))); gpr_mu_unlock(g_mu); @@ -213,7 +217,8 @@ static void test_no_op_with_port(void) { resolved_addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_in)); addr->sin_family = AF_INET; GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, rcv_buf_size, - snd_buf_size, &handler_factory)); + snd_buf_size, &handler_factory, + g_num_listeners)); grpc_udp_server_destroy(s, nullptr); @@ -244,9 +249,10 @@ static void test_no_op_with_port_and_socket_factory(void) { resolved_addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_in)); addr->sin_family = AF_INET; GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, rcv_buf_size, - snd_buf_size, &handler_factory)); - GPR_ASSERT(socket_factory->number_of_socket_calls == 1); - GPR_ASSERT(socket_factory->number_of_bind_calls == 1); + snd_buf_size, &handler_factory, + g_num_listeners)); + GPR_ASSERT(socket_factory->number_of_socket_calls == g_num_listeners); + GPR_ASSERT(socket_factory->number_of_bind_calls == g_num_listeners); grpc_udp_server_destroy(s, nullptr); @@ -271,15 +277,16 @@ static void test_no_op_with_port_and_start(void) { resolved_addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_in)); addr->sin_family = AF_INET; GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, rcv_buf_size, - snd_buf_size, &handler_factory)); + snd_buf_size, &handler_factory, + g_num_listeners)); grpc_udp_server_start(s, nullptr, 0, nullptr); - GPR_ASSERT(g_number_of_starts == 1); + GPR_ASSERT(g_number_of_starts == g_num_listeners); grpc_udp_server_destroy(s, nullptr); /* The server had a single FD, which is orphaned exactly once in * * grpc_udp_server_destroy. */ - GPR_ASSERT(g_number_of_orphan_calls == 1); + GPR_ASSERT(g_number_of_orphan_calls == g_num_listeners); shutdown_and_destroy_pollset(); } @@ -304,7 +311,8 @@ static void test_receive(int number_of_clients) { resolved_addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_storage)); addr->ss_family = AF_INET; GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, rcv_buf_size, - snd_buf_size, &handler_factory)); + snd_buf_size, &handler_factory, + g_num_listeners)); svrfd = grpc_udp_server_get_fd(s, 0); GPR_ASSERT(svrfd >= 0); @@ -347,13 +355,16 @@ static void test_receive(int number_of_clients) { /* The server had a single FD, which is orphaned exactly once in * * grpc_udp_server_destroy. */ - GPR_ASSERT(g_number_of_orphan_calls == 1); + GPR_ASSERT(g_number_of_orphan_calls == g_num_listeners); shutdown_and_destroy_pollset(); } int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_init(); + if (grpc_is_socket_reuse_port_supported()) { + g_num_listeners = 10; + } { grpc_core::ExecCtx exec_ctx; g_pollset = static_cast<grpc_pollset*>(gpr_zalloc(grpc_pollset_size())); diff --git a/test/core/security/grpc_alts_credentials_options_test.cc b/test/core/security/grpc_alts_credentials_options_test.cc index 1217065507..623db48ebc 100644 --- a/test/core/security/grpc_alts_credentials_options_test.cc +++ b/test/core/security/grpc_alts_credentials_options_test.cc @@ -30,39 +30,22 @@ const size_t kTargetServiceAccountNum = 2; -static void test_add_target_service_account_failure() { - /* Initialization. */ - grpc_alts_credentials_options* options = - grpc_alts_credentials_client_options_create(); - auto client_options = - reinterpret_cast<grpc_alts_credentials_client_options*>(options); - - /* Test. */ - GPR_ASSERT(!grpc_alts_credentials_client_options_add_target_service_account( - client_options, nullptr)); - GPR_ASSERT(!grpc_alts_credentials_client_options_add_target_service_account( - nullptr, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1)); - - /* Cleanup. */ - grpc_alts_credentials_options_destroy(options); -} - static void test_copy_client_options_failure() { /* Initialization. */ grpc_alts_credentials_options* options = grpc_alts_credentials_client_options_create(); - /* Test. */ GPR_ASSERT(grpc_alts_credentials_options_copy(nullptr) == nullptr); - /* Cleanup. */ grpc_alts_credentials_options_destroy(options); } static size_t get_target_service_account_num( - grpc_alts_credentials_client_options* options) { + grpc_alts_credentials_options* options) { + auto client_options = + reinterpret_cast<grpc_alts_credentials_client_options*>(options); size_t num = 0; - target_service_account* node = options->target_account_list_head; + target_service_account* node = client_options->target_account_list_head; while (node != nullptr) { num++; node = node->next; @@ -74,36 +57,31 @@ static void test_client_options_api_success() { /* Initialization. */ grpc_alts_credentials_options* options = grpc_alts_credentials_client_options_create(); - auto client_options = - reinterpret_cast<grpc_alts_credentials_client_options*>(options); - /* Set client options fields. */ grpc_alts_credentials_client_options_add_target_service_account( - client_options, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1); + options, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1); grpc_alts_credentials_client_options_add_target_service_account( - client_options, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2); - + options, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2); /* Validate client option fields. */ - GPR_ASSERT(get_target_service_account_num(client_options) == + GPR_ASSERT(get_target_service_account_num(options) == kTargetServiceAccountNum); + auto client_options = + reinterpret_cast<grpc_alts_credentials_client_options*>(options); GPR_ASSERT(strcmp(client_options->target_account_list_head->data, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2) == 0); GPR_ASSERT(strcmp(client_options->target_account_list_head->next->data, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1) == 0); - /* Perform a copy operation and validate its correctness. */ grpc_alts_credentials_options* new_options = grpc_alts_credentials_options_copy(options); + GPR_ASSERT(get_target_service_account_num(new_options) == + kTargetServiceAccountNum); auto new_client_options = reinterpret_cast<grpc_alts_credentials_client_options*>(new_options); - - GPR_ASSERT(get_target_service_account_num(new_client_options) == - kTargetServiceAccountNum); GPR_ASSERT(strcmp(new_client_options->target_account_list_head->data, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_2) == 0); GPR_ASSERT(strcmp(new_client_options->target_account_list_head->next->data, ALTS_CLIENT_OPTIONS_TEST_TARGET_SERVICE_ACCOUNT_1) == 0); - /* Cleanup.*/ grpc_alts_credentials_options_destroy(options); grpc_alts_credentials_options_destroy(new_options); @@ -111,7 +89,6 @@ static void test_client_options_api_success() { int main(int argc, char** argv) { /* Test. */ - test_add_target_service_account_failure(); test_copy_client_options_failure(); test_client_options_api_success(); return 0; diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c index b39ab352c6..52a1b03998 100644 --- a/test/core/surface/public_headers_must_be_c89.c +++ b/test/core/surface/public_headers_must_be_c89.c @@ -173,6 +173,12 @@ int main(int argc, char **argv) { printf("%lx", (unsigned long) grpc_server_add_secure_http2_port); printf("%lx", (unsigned long) grpc_call_set_credentials); printf("%lx", (unsigned long) grpc_server_credentials_set_auth_metadata_processor); + printf("%lx", (unsigned long) grpc_alts_credentials_client_options_create); + printf("%lx", (unsigned long) grpc_alts_credentials_server_options_create); + printf("%lx", (unsigned long) grpc_alts_credentials_client_options_add_target_service_account); + printf("%lx", (unsigned long) grpc_alts_credentials_options_destroy); + printf("%lx", (unsigned long) grpc_alts_credentials_create); + printf("%lx", (unsigned long) grpc_alts_server_credentials_create); printf("%lx", (unsigned long) grpc_raw_byte_buffer_create); printf("%lx", (unsigned long) grpc_raw_compressed_byte_buffer_create); printf("%lx", (unsigned long) grpc_byte_buffer_copy); diff --git a/test/core/tsi/alts/crypt/BUILD b/test/core/tsi/alts/crypt/BUILD index b2fcb65adb..cf9dbca316 100644 --- a/test/core/tsi/alts/crypt/BUILD +++ b/test/core/tsi/alts/crypt/BUILD @@ -16,7 +16,7 @@ load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_p licenses(["notice"]) # Apache v2 -grpc_package(name = "crypt", visibility = "public") +grpc_package(name = "test/core/tsi/alts/crypt", visibility = "public") grpc_cc_test( name = "alts_crypt_test", diff --git a/test/core/tsi/alts/fake_handshaker/BUILD b/test/core/tsi/alts/fake_handshaker/BUILD new file mode 100644 index 0000000000..a09a046d27 --- /dev/null +++ b/test/core/tsi/alts/fake_handshaker/BUILD @@ -0,0 +1,57 @@ +# Copyright 2018 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +licenses(["notice"]) # Apache v2 + +load("//bazel:grpc_build_system.bzl", "grpc_proto_library", "grpc_cc_library", "grpc_cc_binary", "grpc_package") + +grpc_package(name = "test/core/tsi/alts/fake_handshaker", visibility = "public") + +grpc_proto_library( + name = "transport_security_common_proto", + srcs = ["transport_security_common.proto"], + has_services = False, +) + +grpc_proto_library( + name = "handshaker_proto", + srcs = ["handshaker.proto"], + has_services = True, + deps = [ + "transport_security_common_proto", + ], +) + +grpc_cc_library( + name = "fake_handshaker_lib", + testonly = True, + srcs = ["fake_handshaker_server.cc"], + language = "C++", + deps = [ + "handshaker_proto", + "transport_security_common_proto", + "//:grpc++", + "//test/cpp/util:test_config", + ], +) + +grpc_cc_binary( + name = "fake_handshaker_server", + testonly = True, + srcs = ["fake_handshaker_server.cc"], + language = "C++", + deps = [ + "fake_handshaker_lib", + ], +) diff --git a/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc b/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc new file mode 100644 index 0000000000..f6a4791b49 --- /dev/null +++ b/test/core/tsi/alts/fake_handshaker/fake_handshaker_server.cc @@ -0,0 +1,268 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include <memory> +#include <sstream> +#include <string> + +#include <gflags/gflags.h> +#include <grpc/grpc.h> +#include <grpc/support/log.h> +#include <grpcpp/impl/codegen/async_stream.h> +#include <grpcpp/security/server_credentials.h> +#include <grpcpp/server.h> +#include <grpcpp/server_builder.h> +#include <grpcpp/server_context.h> + +#include "test/core/tsi/alts/fake_handshaker/handshaker.grpc.pb.h" +#include "test/core/tsi/alts/fake_handshaker/handshaker.pb.h" +#include "test/core/tsi/alts/fake_handshaker/transport_security_common.pb.h" +#include "test/cpp/util/test_config.h" + +DEFINE_int32(handshaker_port, 55056, + "TCP port on which the fake handshaker server listens to."); + +// Fake handshake messages. +constexpr char kClientInitFrame[] = "ClientInit"; +constexpr char kServerFrame[] = "ServerInitAndFinished"; +constexpr char kClientFinishFrame[] = "ClientFinished"; +// Error messages. +constexpr char kInvalidFrameError[] = "Invalid input frame."; +constexpr char kWrongStateError[] = "Wrong handshake state."; + +namespace grpc { +namespace gcp { + +// FakeHandshakeService implements a fake handshaker service using a fake key +// exchange protocol. The fake key exchange protocol is a 3-message protocol: +// - Client first sends ClientInit message to Server. +// - Server then sends ServerInitAndFinished message back to Client. +// - Client finally sends ClientFinished message to Server. +// This fake handshaker service is intended for ALTS integration testing without +// relying on real ALTS handshaker service inside GCE. +// It is thread-safe. +class FakeHandshakerService : public HandshakerService::Service { + public: + Status DoHandshake( + ServerContext* server_context, + ServerReaderWriter<HandshakerResp, HandshakerReq>* stream) override { + Status status; + HandshakerContext context; + HandshakerReq request; + HandshakerResp response; + gpr_log(GPR_DEBUG, "Start a new handshake."); + while (stream->Read(&request)) { + status = ProcessRequest(&context, request, &response); + if (!status.ok()) return WriteErrorResponse(stream, status); + stream->Write(response); + if (context.state == COMPLETED) return Status::OK; + request.Clear(); + } + return Status::OK; + } + + private: + // HandshakeState is used by fake handshaker server to keep track of client's + // handshake status. In the beginning of a handshake, the state is INITIAL. + // If start_client or start_server request is called, the state becomes at + // least STARTED. When the handshaker server produces the first fame, the + // state becomes SENT. After the handshaker server processes the final frame + // from the peer, the state becomes COMPLETED. + enum HandshakeState { INITIAL, STARTED, SENT, COMPLETED }; + + struct HandshakerContext { + bool is_client = true; + HandshakeState state = INITIAL; + }; + + Status ProcessRequest(HandshakerContext* context, + const HandshakerReq& request, + HandshakerResp* response) { + GPR_ASSERT(context != nullptr && response != nullptr); + response->Clear(); + if (request.has_client_start()) { + gpr_log(GPR_DEBUG, "Process client start request."); + return ProcessClientStart(context, request.client_start(), response); + } else if (request.has_server_start()) { + gpr_log(GPR_DEBUG, "Process server start request."); + return ProcessServerStart(context, request.server_start(), response); + } else if (request.has_next()) { + gpr_log(GPR_DEBUG, "Process next request."); + return ProcessNext(context, request.next(), response); + } + return Status(StatusCode::INVALID_ARGUMENT, "Request is empty."); + } + + Status ProcessClientStart(HandshakerContext* context, + const StartClientHandshakeReq& request, + HandshakerResp* response) { + GPR_ASSERT(context != nullptr && response != nullptr); + // Checks request. + if (context->state != INITIAL) { + return Status(StatusCode::FAILED_PRECONDITION, kWrongStateError); + } + if (request.application_protocols_size() == 0) { + return Status(StatusCode::INVALID_ARGUMENT, + "At least one application protocol needed."); + } + if (request.record_protocols_size() == 0) { + return Status(StatusCode::INVALID_ARGUMENT, + "At least one record protocol needed."); + } + // Sets response. + response->set_out_frames(kClientInitFrame); + response->set_bytes_consumed(0); + response->mutable_status()->set_code(StatusCode::OK); + // Updates handshaker context. + context->is_client = true; + context->state = SENT; + return Status::OK; + } + + Status ProcessServerStart(HandshakerContext* context, + const StartServerHandshakeReq& request, + HandshakerResp* response) { + GPR_ASSERT(context != nullptr && response != nullptr); + // Checks request. + if (context->state != INITIAL) { + return Status(StatusCode::FAILED_PRECONDITION, kWrongStateError); + } + if (request.application_protocols_size() == 0) { + return Status(StatusCode::INVALID_ARGUMENT, + "At least one application protocol needed."); + } + if (request.handshake_parameters().empty()) { + return Status(StatusCode::INVALID_ARGUMENT, + "At least one set of handshake parameters needed."); + } + // Sets response. + if (request.in_bytes().empty()) { + // start_server request does not have in_bytes. + response->set_bytes_consumed(0); + context->state = STARTED; + } else { + // start_server request has in_bytes. + if (request.in_bytes() == kClientInitFrame) { + response->set_out_frames(kServerFrame); + response->set_bytes_consumed(strlen(kClientInitFrame)); + context->state = SENT; + } else { + return Status(StatusCode::UNKNOWN, kInvalidFrameError); + } + } + response->mutable_status()->set_code(StatusCode::OK); + context->is_client = false; + return Status::OK; + } + + Status ProcessNext(HandshakerContext* context, + const NextHandshakeMessageReq& request, + HandshakerResp* response) { + GPR_ASSERT(context != nullptr && response != nullptr); + if (context->is_client) { + // Processes next request on client side. + if (context->state != SENT) { + return Status(StatusCode::FAILED_PRECONDITION, kWrongStateError); + } + if (request.in_bytes() != kServerFrame) { + return Status(StatusCode::UNKNOWN, kInvalidFrameError); + } + response->set_out_frames(kClientFinishFrame); + response->set_bytes_consumed(strlen(kServerFrame)); + context->state = COMPLETED; + } else { + // Processes next request on server side. + HandshakeState current_state = context->state; + if (current_state == STARTED) { + if (request.in_bytes() != kClientInitFrame) { + return Status(StatusCode::UNKNOWN, kInvalidFrameError); + } + response->set_out_frames(kServerFrame); + response->set_bytes_consumed(strlen(kClientInitFrame)); + context->state = SENT; + } else if (current_state == SENT) { + // Client finish frame may be sent along with the first payload from the + // client, handshaker only consumes the client finish frame. + if (request.in_bytes().substr(0, strlen(kClientFinishFrame)) != + kClientFinishFrame) { + return Status(StatusCode::UNKNOWN, kInvalidFrameError); + } + response->set_bytes_consumed(strlen(kClientFinishFrame)); + context->state = COMPLETED; + } else { + return Status(StatusCode::FAILED_PRECONDITION, kWrongStateError); + } + } + // At this point, processing next request succeeded. + response->mutable_status()->set_code(StatusCode::OK); + if (context->state == COMPLETED) { + *response->mutable_result() = GetHandshakerResult(); + } + return Status::OK; + } + + Status WriteErrorResponse( + ServerReaderWriter<HandshakerResp, HandshakerReq>* stream, + const Status& status) { + GPR_ASSERT(!status.ok()); + HandshakerResp response; + response.mutable_status()->set_code(status.error_code()); + response.mutable_status()->set_details(status.error_message()); + stream->Write(response); + return status; + } + + HandshakerResult GetHandshakerResult() { + HandshakerResult result; + result.set_application_protocol("grpc"); + result.set_record_protocol("ALTSRP_GCM_AES128_REKEY"); + result.mutable_peer_identity()->set_service_account("peer_identity"); + result.mutable_local_identity()->set_service_account("local_identity"); + string key(1024, '\0'); + result.set_key_data(key); + result.mutable_peer_rpc_versions()->mutable_max_rpc_version()->set_major(2); + result.mutable_peer_rpc_versions()->mutable_max_rpc_version()->set_minor(1); + result.mutable_peer_rpc_versions()->mutable_min_rpc_version()->set_major(2); + result.mutable_peer_rpc_versions()->mutable_min_rpc_version()->set_minor(1); + return result; + } +}; + +} // namespace gcp +} // namespace grpc + +void RunServer() { + GPR_ASSERT(FLAGS_handshaker_port != 0); + std::ostringstream server_address; + server_address << "[::1]:" << FLAGS_handshaker_port; + grpc::gcp::FakeHandshakerService service; + grpc::ServerBuilder builder; + builder.AddListeningPort(server_address.str(), + grpc::InsecureServerCredentials()); + builder.RegisterService(&service); + std::unique_ptr<grpc::Server> server(builder.BuildAndStart()); + gpr_log(GPR_INFO, "Fake handshaker server listening on %s", + server_address.str().c_str()); + server->Wait(); +} + +int main(int argc, char** argv) { + grpc::testing::InitTest(&argc, &argv, true); + RunServer(); + return 0; +} diff --git a/test/core/tsi/alts/fake_handshaker/handshaker.proto b/test/core/tsi/alts/fake_handshaker/handshaker.proto new file mode 100644 index 0000000000..8af9abfbf5 --- /dev/null +++ b/test/core/tsi/alts/fake_handshaker/handshaker.proto @@ -0,0 +1,224 @@ +// Copyright 2018 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +import "test/core/tsi/alts/fake_handshaker/transport_security_common.proto"; + +package grpc.gcp; + +option java_package = "io.grpc.alts.internal"; + +enum HandshakeProtocol { + // Default value. + HANDSHAKE_PROTOCOL_UNSPECIFIED = 0; + + // TLS handshake protocol. + TLS = 1; + + // Application Layer Transport Security handshake protocol. + ALTS = 2; +} + +enum NetworkProtocol { + NETWORK_PROTOCOL_UNSPECIFIED = 0; + TCP = 1; + UDP = 2; +} + +message Endpoint { + // IP address. It should contain an IPv4 or IPv6 string literal, e.g. + // "192.168.0.1" or "2001:db8::1". + string ip_address = 1; + + // Port number. + int32 port = 2; + + // Network protocol (e.g., TCP, UDP) associated with this endpoint. + NetworkProtocol protocol = 3; +} + +message Identity { + oneof identity_oneof { + // Service account of a connection endpoint. + string service_account = 1; + + // Hostname of a connection endpoint. + string hostname = 2; + } +} + +message StartClientHandshakeReq { + // Handshake security protocol requested by the client. + HandshakeProtocol handshake_security_protocol = 1; + + // The application protocols supported by the client, e.g., "h2" (for http2), + // "grpc". + repeated string application_protocols = 2; + + // The record protocols supported by the client, e.g., + // "ALTSRP_GCM_AES128". + repeated string record_protocols = 3; + + // (Optional) Describes which server identities are acceptable by the client. + // If target identities are provided and none of them matches the peer + // identity of the server, handshake will fail. + repeated Identity target_identities = 4; + + // (Optional) Application may specify a local identity. Otherwise, the + // handshaker chooses a default local identity. + Identity local_identity = 5; + + // (Optional) Local endpoint information of the connection to the server, + // such as local IP address, port number, and network protocol. + Endpoint local_endpoint = 6; + + // (Optional) Endpoint information of the remote server, such as IP address, + // port number, and network protocol. + Endpoint remote_endpoint = 7; + + // (Optional) If target name is provided, a secure naming check is performed + // to verify that the peer authenticated identity is indeed authorized to run + // the target name. + string target_name = 8; + + // (Optional) RPC protocol versions supported by the client. + RpcProtocolVersions rpc_versions = 9; +} + +message ServerHandshakeParameters { + // The record protocols supported by the server, e.g., + // "ALTSRP_GCM_AES128". + repeated string record_protocols = 1; + + // (Optional) A list of local identities supported by the server, if + // specified. Otherwise, the handshaker chooses a default local identity. + repeated Identity local_identities = 2; +} + +message StartServerHandshakeReq { + // The application protocols supported by the server, e.g., "h2" (for http2), + // "grpc". + repeated string application_protocols = 1; + + // Handshake parameters (record protocols and local identities supported by + // the server) mapped by the handshake protocol. Each handshake security + // protocol (e.g., TLS or ALTS) has its own set of record protocols and local + // identities. Since protobuf does not support enum as key to the map, the key + // to handshake_parameters is the integer value of HandshakeProtocol enum. + map<int32, ServerHandshakeParameters> handshake_parameters = 2; + + // Bytes in out_frames returned from the peer's HandshakerResp. It is possible + // that the peer's out_frames are split into multiple HandshakReq messages. + bytes in_bytes = 3; + + // (Optional) Local endpoint information of the connection to the client, + // such as local IP address, port number, and network protocol. + Endpoint local_endpoint = 4; + + // (Optional) Endpoint information of the remote client, such as IP address, + // port number, and network protocol. + Endpoint remote_endpoint = 5; + + // (Optional) RPC protocol versions supported by the server. + RpcProtocolVersions rpc_versions = 6; +} + +message NextHandshakeMessageReq { + // Bytes in out_frames returned from the peer's HandshakerResp. It is possible + // that the peer's out_frames are split into multiple NextHandshakerMessageReq + // messages. + bytes in_bytes = 1; +} + +message HandshakerReq { + oneof req_oneof { + // The start client handshake request message. + StartClientHandshakeReq client_start = 1; + + // The start server handshake request message. + StartServerHandshakeReq server_start = 2; + + // The next handshake request message. + NextHandshakeMessageReq next = 3; + } +} + +message HandshakerResult { + // The application protocol negotiated for this connection. + string application_protocol = 1; + + // The record protocol negotiated for this connection. + string record_protocol = 2; + + // Cryptographic key data. The key data may be more than the key length + // required for the record protocol, thus the client of the handshaker + // service needs to truncate the key data into the right key length. + bytes key_data = 3; + + // The authenticated identity of the peer. + Identity peer_identity = 4; + + // The local identity used in the handshake. + Identity local_identity = 5; + + // Indicate whether the handshaker service client should keep the channel + // between the handshaker service open, e.g., in order to handle + // post-handshake messages in the future. + bool keep_channel_open = 6; + + // The RPC protocol versions supported by the peer. + RpcProtocolVersions peer_rpc_versions = 7; +} + +message HandshakerStatus { + // The status code. This could be the gRPC status code. + uint32 code = 1; + + // The status details. + string details = 2; +} + +message HandshakerResp { + // Frames to be given to the peer for the NextHandshakeMessageReq. May be + // empty if no out_frames have to be sent to the peer or if in_bytes in the + // HandshakerReq are incomplete. All the non-empty out frames must be sent to + // the peer even if the handshaker status is not OK as these frames may + // contain the alert frames. + bytes out_frames = 1; + + // Number of bytes in the in_bytes consumed by the handshaker. It is possible + // that part of in_bytes in HandshakerReq was unrelated to the handshake + // process. + uint32 bytes_consumed = 2; + + // This is set iff the handshake was successful. out_frames may still be set + // to frames that needs to be forwarded to the peer. + HandshakerResult result = 3; + + // Status of the handshaker. + HandshakerStatus status = 4; +} + +service HandshakerService { + // Handshaker service accepts a stream of handshaker request, returning a + // stream of handshaker response. Client is expected to send exactly one + // message with either client_start or server_start followed by one or more + // messages with next. Each time client sends a request, the handshaker + // service expects to respond. Client does not have to wait for service's + // response before sending next request. + rpc DoHandshake(stream HandshakerReq) + returns (stream HandshakerResp) { + } +} diff --git a/test/core/tsi/alts/fake_handshaker/transport_security_common.proto b/test/core/tsi/alts/fake_handshaker/transport_security_common.proto new file mode 100644 index 0000000000..d0f861e644 --- /dev/null +++ b/test/core/tsi/alts/fake_handshaker/transport_security_common.proto @@ -0,0 +1,40 @@ +// Copyright 2018 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package grpc.gcp; + +option java_package = "io.grpc.alts.internal"; + +// The security level of the created channel. The list is sorted in increasing +// level of security. This order must always be maintained. +enum SecurityLevel { + SECURITY_NONE = 0; + INTEGRITY_ONLY = 1; + INTEGRITY_AND_PRIVACY = 2; +} + +// Max and min supported RPC protocol versions. +message RpcProtocolVersions { + // RPC version contains a major version and a minor version. + message Version { + uint32 major = 1; + uint32 minor = 2; + } + // Maximum supported RPC version. + Version max_rpc_version = 1; + // Minimum supported RPC version. + Version min_rpc_version = 2; +} diff --git a/test/core/tsi/alts/frame_protector/BUILD b/test/core/tsi/alts/frame_protector/BUILD index 94c2ab3747..dd1966b379 100644 --- a/test/core/tsi/alts/frame_protector/BUILD +++ b/test/core/tsi/alts/frame_protector/BUILD @@ -16,7 +16,7 @@ load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_p licenses(["notice"]) # Apache v2 -grpc_package(name = "frame_protector") +grpc_package(name = "test/core/tsi/alts/frame_protector") grpc_cc_test( name = "alts_counter_test", diff --git a/test/core/tsi/alts/handshaker/BUILD b/test/core/tsi/alts/handshaker/BUILD index fc2c395bdf..809742744c 100644 --- a/test/core/tsi/alts/handshaker/BUILD +++ b/test/core/tsi/alts/handshaker/BUILD @@ -16,7 +16,7 @@ load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_p licenses(["notice"]) # Apache v2 -grpc_package(name = "handshaker") +grpc_package(name = "test/core/tsi/alts/handshaker") grpc_cc_library( name = "alts_handshaker_service_api_test_lib", diff --git a/test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc b/test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc index 7072be6e3a..b9dd52a64a 100644 --- a/test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc +++ b/test/core/tsi/alts/handshaker/alts_handshaker_client_test.cc @@ -54,11 +54,9 @@ static alts_tsi_event* alts_tsi_event_create_for_testing(bool is_client) { : grpc_alts_credentials_server_options_create(); if (is_client) { grpc_alts_credentials_client_options_add_target_service_account( - reinterpret_cast<grpc_alts_credentials_client_options*>(e->options), - ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT1); + e->options, ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT1); grpc_alts_credentials_client_options_add_target_service_account( - reinterpret_cast<grpc_alts_credentials_client_options*>(e->options), - ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT2); + e->options, ALTS_HANDSHAKER_CLIENT_TEST_TARGET_SERVICE_ACCOUNT2); } grpc_gcp_rpc_protocol_versions* versions = &e->options->rpc_versions; GPR_ASSERT(grpc_gcp_rpc_protocol_versions_set_max( diff --git a/test/core/tsi/alts/zero_copy_frame_protector/BUILD b/test/core/tsi/alts/zero_copy_frame_protector/BUILD index 4c6fb91a76..2b41dae043 100644 --- a/test/core/tsi/alts/zero_copy_frame_protector/BUILD +++ b/test/core/tsi/alts/zero_copy_frame_protector/BUILD @@ -16,7 +16,7 @@ load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package") licenses(["notice"]) # Apache v2 -grpc_package(name = "zero_copy_frame_protector") +grpc_package(name = "test/core/tsi/alts/zero_copy_frame_protector") grpc_cc_test( name = "alts_grpc_record_protocol_test", diff --git a/test/core/tsi/ssl_transport_security_test.cc b/test/core/tsi/ssl_transport_security_test.cc index 88f1abc18c..cf1ac82413 100644 --- a/test/core/tsi/ssl_transport_security_test.cc +++ b/test/core/tsi/ssl_transport_security_test.cc @@ -34,6 +34,10 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> +extern "C" { +#include <openssl/crypto.h> +} + #define SSL_TSI_TEST_ALPN1 "foo" #define SSL_TSI_TEST_ALPN2 "toto" #define SSL_TSI_TEST_ALPN3 "baz" @@ -42,6 +46,14 @@ #define SSL_TSI_TEST_BAD_SERVER_KEY_CERT_PAIRS_NUM 1 #define SSL_TSI_TEST_CREDENTIALS_DIR "src/core/tsi/test_creds/" +// OpenSSL 1.1 uses AES256 for encryption session ticket by default so specify +// different STEK size. +#if OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(OPENSSL_IS_BORINGSSL) +const size_t kSessionTicketEncryptionKeySize = 80; +#else +const size_t kSessionTicketEncryptionKeySize = 48; +#endif + typedef enum AlpnMode { NO_ALPN, ALPN_CLIENT_NO_SERVER, @@ -624,7 +636,7 @@ void ssl_tsi_test_do_round_trip_odd_buffer_size() { void ssl_tsi_test_do_handshake_session_cache() { tsi_ssl_session_cache* session_cache = tsi_ssl_session_cache_create_lru(16); - char session_ticket_key[48]; + char session_ticket_key[kSessionTicketEncryptionKeySize]; auto do_handshake = [&session_ticket_key, &session_cache](bool session_reused) { tsi_test_fixture* fixture = ssl_tsi_test_fixture_create(); @@ -633,22 +645,22 @@ void ssl_tsi_test_do_handshake_session_cache() { ssl_fixture->server_name_indication = const_cast<char*>("waterzooi.test.google.be"); ssl_fixture->session_ticket_key = session_ticket_key; - ssl_fixture->session_ticket_key_size = 48; + ssl_fixture->session_ticket_key_size = sizeof(session_ticket_key); tsi_ssl_session_cache_ref(session_cache); ssl_fixture->session_cache = session_cache; ssl_fixture->session_reused = session_reused; tsi_test_do_round_trip(&ssl_fixture->base); tsi_test_fixture_destroy(fixture); }; - memset(session_ticket_key, 'a', 48); + memset(session_ticket_key, 'a', sizeof(session_ticket_key)); do_handshake(false); do_handshake(true); do_handshake(true); // Changing session_ticket_key on server invalidates ticket. - memset(session_ticket_key, 'b', 48); + memset(session_ticket_key, 'b', sizeof(session_ticket_key)); do_handshake(false); do_handshake(true); - memset(session_ticket_key, 'c', 48); + memset(session_ticket_key, 'c', sizeof(session_ticket_key)); do_handshake(false); do_handshake(true); tsi_ssl_session_cache_unref(session_cache); diff --git a/test/cpp/codegen/proto_utils_test.cc b/test/cpp/codegen/proto_utils_test.cc index 53e2a2864c..801660eef6 100644 --- a/test/cpp/codegen/proto_utils_test.cc +++ b/test/cpp/codegen/proto_utils_test.cc @@ -27,17 +27,16 @@ namespace grpc { namespace internal { -// Provide access to GrpcProtoBufferWriter internals. -class GrpcProtoBufferWriterPeer { +// Provide access to ProtoBufferWriter internals. +class ProtoBufferWriterPeer { public: - explicit GrpcProtoBufferWriterPeer(GrpcProtoBufferWriter* writer) - : writer_(writer) {} + explicit ProtoBufferWriterPeer(ProtoBufferWriter* writer) : writer_(writer) {} bool have_backup() const { return writer_->have_backup_; } const grpc_slice& backup_slice() const { return writer_->backup_slice_; } const grpc_slice& slice() const { return writer_->slice_; } private: - GrpcProtoBufferWriter* writer_; + ProtoBufferWriter* writer_; }; // Provide access to ByteBuffer internals. @@ -53,14 +52,14 @@ class GrpcByteBufferPeer { class ProtoUtilsTest : public ::testing::Test {}; // Regression test for a memory corruption bug where a series of -// GrpcProtoBufferWriter Next()/Backup() invocations could result in a dangling +// ProtoBufferWriter Next()/Backup() invocations could result in a dangling // pointer returned by Next() due to the interaction between grpc_slice inlining // and GRPC_SLICE_START_PTR. TEST_F(ProtoUtilsTest, TinyBackupThenNext) { ByteBuffer bp; const int block_size = 1024; - GrpcProtoBufferWriter writer(&bp, block_size, 8192); - GrpcProtoBufferWriterPeer peer(&writer); + ProtoBufferWriter writer(&bp, block_size, 8192); + ProtoBufferWriterPeer peer(&writer); void* data; int size; @@ -81,7 +80,7 @@ namespace { // Set backup_size to 0 to indicate no backup is needed. void BufferWriterTest(int block_size, int total_size, int backup_size) { ByteBuffer bb; - GrpcProtoBufferWriter writer(&bb, block_size, total_size); + ProtoBufferWriter writer(&bb, block_size, total_size); int written_size = 0; void* data; @@ -162,7 +161,7 @@ TEST(WriterTest, LargeBlockLargeBackup) { BufferWriterTest(4096, 8192, 4095); } } // namespace grpc int main(int argc, char** argv) { - // Ensure the GrpcProtoBufferWriter internals are initialized. + // Ensure the ProtoBufferWriter internals are initialized. grpc::internal::GrpcLibraryInitializer init; init.summon(); grpc::GrpcLibraryCodegen lib; diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc index 557845618e..7aab035e76 100644 --- a/test/cpp/end2end/grpclb_end2end_test.cc +++ b/test/cpp/end2end/grpclb_end2end_test.cc @@ -1139,7 +1139,7 @@ TEST_F(UpdatesTest, UpdateBalancersDeadUpdate) { EXPECT_EQ(0U, backend_servers_[1].service_->request_count()); WaitForBackend(1); - // This is serviced by the existing RR policy + // This is serviced by the updated RR policy backend_servers_[1].service_->ResetCounters(); gpr_log(GPR_INFO, "========= BEFORE THIRD BATCH =========="); CheckRpcSendOk(10); diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index ca8ee3de06..3eb155ef95 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -31,6 +31,8 @@ #include "test/cpp/interop/interop_client.h" #include "test/cpp/util/test_config.h" +DEFINE_bool(use_alts, false, + "Whether to use alts. Enable alts will disable tls."); DEFINE_bool(use_tls, false, "Whether to use tls."); DEFINE_string(custom_credentials_type, "", "User provided credentials type."); DEFINE_bool(use_test_ca, false, "False to use SSL roots for google"); diff --git a/test/cpp/interop/client_helper.cc b/test/cpp/interop/client_helper.cc index 4041f95abc..29b5a1ed6c 100644 --- a/test/cpp/interop/client_helper.cc +++ b/test/cpp/interop/client_helper.cc @@ -35,6 +35,7 @@ #include "test/cpp/util/create_test_channel.h" #include "test/cpp/util/test_credentials_provider.h" +DECLARE_bool(use_alts); DECLARE_bool(use_tls); DECLARE_string(custom_credentials_type); DECLARE_bool(use_test_ca); @@ -103,8 +104,10 @@ std::shared_ptr<Channel> CreateChannelForTestCase( GPR_ASSERT(creds); } if (FLAGS_custom_credentials_type.empty()) { + transport_security security_type = + FLAGS_use_alts ? ALTS : (FLAGS_use_tls ? TLS : INSECURE); return CreateTestChannel(host_port, FLAGS_server_host_override, - FLAGS_use_tls, !FLAGS_use_test_ca, creds); + security_type, !FLAGS_use_test_ca, creds); } else { return CreateTestChannel(host_port, FLAGS_custom_credentials_type, creds); } diff --git a/test/cpp/interop/http2_client.cc b/test/cpp/interop/http2_client.cc index 821815c6e8..543f159265 100644 --- a/test/cpp/interop/http2_client.cc +++ b/test/cpp/interop/http2_client.cc @@ -194,7 +194,7 @@ int main(int argc, char** argv) { snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(), FLAGS_server_port); std::shared_ptr<grpc::Channel> channel = - grpc::CreateTestChannel(host_port, false); + grpc::CreateTestChannel(host_port, grpc::testing::INSECURE); GPR_ASSERT(channel->WaitForConnected(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(300, GPR_TIMESPAN)))); grpc::testing::Http2Client client(channel); diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index 5fa1a336da..6526e0535b 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -38,6 +38,8 @@ #include "test/cpp/interop/server_helper.h" #include "test/cpp/util/test_config.h" +DEFINE_bool(use_alts, false, + "Whether to use alts. Enable alts will disable tls."); DEFINE_bool(use_tls, false, "Whether to use tls."); DEFINE_string(custom_credentials_type, "", "User provided credentials type."); DEFINE_int32(port, 0, "Server port."); diff --git a/test/cpp/interop/reconnect_interop_client.cc b/test/cpp/interop/reconnect_interop_client.cc index 9a451fa3f2..8a071d417e 100644 --- a/test/cpp/interop/reconnect_interop_client.cc +++ b/test/cpp/interop/reconnect_interop_client.cc @@ -44,9 +44,11 @@ using grpc::ClientContext; using grpc::CreateTestChannel; using grpc::Status; using grpc::testing::Empty; +using grpc::testing::INSECURE; using grpc::testing::ReconnectInfo; using grpc::testing::ReconnectParams; using grpc::testing::ReconnectService; +using grpc::testing::TLS; int main(int argc, char** argv) { grpc::testing::InitTest(&argc, &argv, true); @@ -57,7 +59,7 @@ int main(int argc, char** argv) { server_address << FLAGS_server_host << ':' << FLAGS_server_control_port; std::unique_ptr<ReconnectService::Stub> control_stub( ReconnectService::NewStub( - CreateTestChannel(server_address.str(), false))); + CreateTestChannel(server_address.str(), INSECURE))); ClientContext start_context; ReconnectParams reconnect_params; reconnect_params.set_max_reconnect_backoff_ms(FLAGS_max_reconnect_backoff_ms); @@ -75,7 +77,7 @@ int main(int argc, char** argv) { FLAGS_max_reconnect_backoff_ms); } std::shared_ptr<Channel> retry_channel = - CreateTestChannel(server_address.str(), "foo.test.google.fr", true, false, + CreateTestChannel(server_address.str(), "foo.test.google.fr", TLS, false, std::shared_ptr<CallCredentials>(), channel_args); // About 13 retries. diff --git a/test/cpp/interop/server_helper.cc b/test/cpp/interop/server_helper.cc index 93ffd52560..2194521998 100644 --- a/test/cpp/interop/server_helper.cc +++ b/test/cpp/interop/server_helper.cc @@ -26,6 +26,7 @@ #include "src/core/lib/surface/call_test_only.h" #include "test/cpp/util/test_credentials_provider.h" +DECLARE_bool(use_alts); DECLARE_bool(use_tls); DECLARE_string(custom_credentials_type); @@ -36,6 +37,8 @@ std::shared_ptr<ServerCredentials> CreateInteropServerCredentials() { if (!FLAGS_custom_credentials_type.empty()) { return GetCredentialsProvider()->GetServerCredentials( FLAGS_custom_credentials_type); + } else if (FLAGS_use_alts) { + return GetCredentialsProvider()->GetServerCredentials(kAltsCredentialsType); } else if (FLAGS_use_tls) { return GetCredentialsProvider()->GetServerCredentials(kTlsCredentialsType); } else { diff --git a/test/cpp/interop/stress_test.cc b/test/cpp/interop/stress_test.cc index 6e8134a83b..023e0c8f0b 100644 --- a/test/cpp/interop/stress_test.cc +++ b/test/cpp/interop/stress_test.cc @@ -99,18 +99,24 @@ DEFINE_bool(do_not_abort_on_transient_failures, true, // Options from client.cc (for compatibility with interop test). // TODO(sreek): Consolidate overlapping options +DEFINE_bool(use_alts, false, + "Whether to use alts. Enable alts will disable tls."); DEFINE_bool(use_tls, false, "Whether to use tls."); DEFINE_bool(use_test_ca, false, "False to use SSL roots for google"); DEFINE_string(server_host_override, "foo.test.google.fr", "Override the server host which is sent in HTTP header"); +using grpc::testing::ALTS; +using grpc::testing::INSECURE; using grpc::testing::MetricsService; using grpc::testing::MetricsServiceImpl; using grpc::testing::StressTestInteropClient; +using grpc::testing::TLS; using grpc::testing::TestCaseType; using grpc::testing::UNKNOWN_TEST; using grpc::testing::WeightedRandomTestSelector; using grpc::testing::kTestCaseList; +using grpc::testing::transport_security; static int log_level = GPR_LOG_SEVERITY_DEBUG; @@ -268,6 +274,8 @@ int main(int argc, char** argv) { int thread_idx = 0; int server_idx = -1; char buffer[256]; + transport_security security_type = + FLAGS_use_alts ? ALTS : (FLAGS_use_tls ? TLS : INSECURE); for (auto it = server_addresses.begin(); it != server_addresses.end(); it++) { ++server_idx; // Create channel(s) for each server @@ -276,7 +284,7 @@ int main(int argc, char** argv) { gpr_log(GPR_INFO, "Starting test with %s channel_idx=%d..", it->c_str(), channel_idx); std::shared_ptr<grpc::Channel> channel = grpc::CreateTestChannel( - *it, FLAGS_server_host_override, FLAGS_use_tls, !FLAGS_use_test_ca); + *it, FLAGS_server_host_override, security_type, !FLAGS_use_test_ca); // Create stub(s) for each channel for (int stub_idx = 0; stub_idx < FLAGS_num_stubs_per_channel; diff --git a/test/cpp/naming/address_sorting_test.cc b/test/cpp/naming/address_sorting_test.cc index df93ff6f8d..a423733caf 100644 --- a/test/cpp/naming/address_sorting_test.cc +++ b/test/cpp/naming/address_sorting_test.cc @@ -722,16 +722,24 @@ TEST(AddressSortingTest, TestStableSortV4CompatAndSiteLocalAddresses) { } int main(int argc, char** argv) { - const char* resolver = gpr_getenv("GRPC_DNS_RESOLVER"); + char* resolver = gpr_getenv("GRPC_DNS_RESOLVER"); if (resolver == nullptr || strlen(resolver) == 0) { gpr_setenv("GRPC_DNS_RESOLVER", "ares"); } else if (strcmp("ares", resolver)) { gpr_log(GPR_INFO, "GRPC_DNS_RESOLVER != ares: %s.", resolver); } + gpr_free(resolver); grpc_test_init(argc, argv); ::testing::InitGoogleTest(&argc, argv); grpc_init(); auto result = RUN_ALL_TESTS(); grpc_shutdown(); + // Test sequential and nested inits and shutdowns. + grpc_init(); + grpc_init(); + grpc_shutdown(); + grpc_shutdown(); + grpc_init(); + grpc_shutdown(); return result; } diff --git a/test/cpp/qps/BUILD b/test/cpp/qps/BUILD index f1abb19e64..a348b88079 100644 --- a/test/cpp/qps/BUILD +++ b/test/cpp/qps/BUILD @@ -47,9 +47,10 @@ grpc_cc_library( "//:grpc", "//:grpc++", "//:grpc++_core_stats", + "//src/proto/grpc/testing:benchmark_service_proto", "//src/proto/grpc/testing:control_proto", "//src/proto/grpc/testing:payloads_proto", - "//src/proto/grpc/testing:services_proto", + "//src/proto/grpc/testing:worker_service_proto", "//test/core/end2end:ssl_test_data", "//test/core/util:gpr_test_util", "//test/core/util:grpc_test_util", @@ -74,7 +75,8 @@ grpc_cc_library( "//:grpc++", "//src/proto/grpc/testing:control_proto", "//src/proto/grpc/testing:messages_proto", - "//src/proto/grpc/testing:services_proto", + "//src/proto/grpc/testing:report_qps_scenario_service_proto", + "//src/proto/grpc/testing:worker_service_proto", "//test/core/util:gpr_test_util", "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index 77743a1dee..31ae6ca1fb 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -31,8 +31,8 @@ #include <grpcpp/support/channel_arguments.h> #include <grpcpp/support/slice.h> +#include "src/proto/grpc/testing/benchmark_service.grpc.pb.h" #include "src/proto/grpc/testing/payloads.pb.h" -#include "src/proto/grpc/testing/services.grpc.pb.h" #include "src/cpp/util/core_stats.h" #include "test/cpp/qps/histogram.h" diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc index f9bef91da0..c79a10d1b4 100644 --- a/test/cpp/qps/client_async.cc +++ b/test/cpp/qps/client_async.cc @@ -35,7 +35,7 @@ #include <grpcpp/generic/generic_stub.h> #include "src/core/lib/surface/completion_queue.h" -#include "src/proto/grpc/testing/services.grpc.pb.h" +#include "src/proto/grpc/testing/benchmark_service.grpc.pb.h" #include "test/cpp/qps/client.h" #include "test/cpp/qps/usage_timer.h" #include "test/cpp/util/create_test_channel.h" diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc index 5185eef710..e65e3b43f3 100644 --- a/test/cpp/qps/client_sync.cc +++ b/test/cpp/qps/client_sync.cc @@ -35,7 +35,7 @@ #include "src/core/lib/gpr/host_port.h" #include "src/core/lib/profiling/timers.h" -#include "src/proto/grpc/testing/services.grpc.pb.h" +#include "src/proto/grpc/testing/benchmark_service.grpc.pb.h" #include "test/cpp/qps/client.h" #include "test/cpp/qps/interarrival.h" #include "test/cpp/qps/usage_timer.h" diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index 361ee4346f..34f1291576 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -33,6 +33,7 @@ #include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/host_port.h" #include "src/core/lib/profiling/timers.h" +#include "src/proto/grpc/testing/worker_service.grpc.pb.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" #include "test/cpp/qps/client.h" diff --git a/test/cpp/qps/qps_worker.cc b/test/cpp/qps/qps_worker.cc index aaffb1d93e..d3f0380474 100644 --- a/test/cpp/qps/qps_worker.cc +++ b/test/cpp/qps/qps_worker.cc @@ -35,7 +35,7 @@ #include <grpcpp/server_builder.h> #include "src/core/lib/gpr/host_port.h" -#include "src/proto/grpc/testing/services.pb.h" +#include "src/proto/grpc/testing/worker_service.grpc.pb.h" #include "test/core/util/grpc_profiler.h" #include "test/core/util/histogram.h" #include "test/cpp/qps/client.h" diff --git a/test/cpp/qps/report.cc b/test/cpp/qps/report.cc index 0a2565d463..607f4e579b 100644 --- a/test/cpp/qps/report.cc +++ b/test/cpp/qps/report.cc @@ -27,7 +27,7 @@ #include <grpcpp/client_context.h> #include "src/cpp/util/core_stats.h" -#include "src/proto/grpc/testing/services.grpc.pb.h" +#include "src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.h" namespace grpc { namespace testing { diff --git a/test/cpp/qps/report.h b/test/cpp/qps/report.h index c5dd138353..8e62f4f449 100644 --- a/test/cpp/qps/report.h +++ b/test/cpp/qps/report.h @@ -28,7 +28,7 @@ #include "test/cpp/qps/driver.h" #include <grpcpp/channel.h> -#include "src/proto/grpc/testing/services.grpc.pb.h" +#include "src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.h" namespace grpc { namespace testing { diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc index 9cb05cd1d1..1dfef6cfc1 100644 --- a/test/cpp/qps/server_async.cc +++ b/test/cpp/qps/server_async.cc @@ -36,7 +36,7 @@ #include "src/core/lib/gpr/host_port.h" #include "src/core/lib/surface/completion_queue.h" -#include "src/proto/grpc/testing/services.grpc.pb.h" +#include "src/proto/grpc/testing/benchmark_service.grpc.pb.h" #include "test/core/util/test_config.h" #include "test/cpp/qps/server.h" diff --git a/test/cpp/qps/server_sync.cc b/test/cpp/qps/server_sync.cc index 9dfd362055..82a9186989 100644 --- a/test/cpp/qps/server_sync.cc +++ b/test/cpp/qps/server_sync.cc @@ -26,7 +26,7 @@ #include <grpcpp/server_context.h> #include "src/core/lib/gpr/host_port.h" -#include "src/proto/grpc/testing/services.grpc.pb.h" +#include "src/proto/grpc/testing/benchmark_service.grpc.pb.h" #include "test/cpp/qps/server.h" #include "test/cpp/qps/usage_timer.h" diff --git a/test/cpp/util/create_test_channel.cc b/test/cpp/util/create_test_channel.cc index 1047d44627..0bcd4dbc84 100644 --- a/test/cpp/util/create_test_channel.cc +++ b/test/cpp/util/create_test_channel.cc @@ -107,37 +107,37 @@ 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, + testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds, const ChannelArguments& args) { - grpc::string type; - if (enable_ssl) { - type = testing::kTlsCredentialsType; - } - + grpc::string type = + security_type == testing::ALTS + ? testing::kAltsCredentialsType + : (security_type == testing::TLS ? testing::kTlsCredentialsType + : testing::kInsecureCredentialsType); return CreateTestChannel(server, type, override_hostname, use_prod_roots, creds, args); } std::shared_ptr<Channel> CreateTestChannel( const grpc::string& server, const grpc::string& override_hostname, - bool enable_ssl, bool use_prod_roots, + testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds) { - return CreateTestChannel(server, override_hostname, enable_ssl, + return CreateTestChannel(server, override_hostname, security_type, use_prod_roots, creds, ChannelArguments()); } 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, + testing::transport_security security_type, bool use_prod_roots) { + return CreateTestChannel(server, override_hostname, security_type, use_prod_roots, std::shared_ptr<CallCredentials>()); } // Shortcut for end2end and interop tests. -std::shared_ptr<Channel> CreateTestChannel(const grpc::string& server, - bool enable_ssl) { - return CreateTestChannel(server, "foo.test.google.fr", enable_ssl, false); +std::shared_ptr<Channel> CreateTestChannel( + const grpc::string& server, testing::transport_security security_type) { + return CreateTestChannel(server, "foo.test.google.fr", security_type, false); } std::shared_ptr<Channel> CreateTestChannel( diff --git a/test/cpp/util/create_test_channel.h b/test/cpp/util/create_test_channel.h index ddaa99f43e..c615fb7653 100644 --- a/test/cpp/util/create_test_channel.h +++ b/test/cpp/util/create_test_channel.h @@ -26,21 +26,27 @@ namespace grpc { class Channel; -std::shared_ptr<Channel> CreateTestChannel(const grpc::string& server, - bool enable_ssl); +namespace testing { + +typedef enum { INSECURE = 0, TLS, ALTS } transport_security; + +} // namespace testing + +std::shared_ptr<Channel> CreateTestChannel( + const grpc::string& server, testing::transport_security security_type); std::shared_ptr<Channel> CreateTestChannel( const grpc::string& server, const grpc::string& override_hostname, - bool enable_ssl, bool use_prod_roots); + testing::transport_security security_type, bool use_prod_roots); std::shared_ptr<Channel> CreateTestChannel( const grpc::string& server, const grpc::string& override_hostname, - bool enable_ssl, bool use_prod_roots, + testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds); std::shared_ptr<Channel> CreateTestChannel( const grpc::string& server, const grpc::string& override_hostname, - bool enable_ssl, bool use_prod_roots, + testing::transport_security security_type, bool use_prod_roots, const std::shared_ptr<CallCredentials>& creds, const ChannelArguments& args); diff --git a/test/cpp/util/test_credentials_provider.cc b/test/cpp/util/test_credentials_provider.cc index 76561007c4..c8b0ac73f4 100644 --- a/test/cpp/util/test_credentials_provider.cc +++ b/test/cpp/util/test_credentials_provider.cc @@ -56,6 +56,9 @@ class DefaultCredentialsProvider : public CredentialsProvider { const grpc::string& type, ChannelArguments* args) override { if (type == grpc::testing::kInsecureCredentialsType) { return InsecureChannelCredentials(); + } else if (type == grpc::testing::kAltsCredentialsType) { + grpc::experimental::AltsCredentialsOptions alts_opts; + return grpc::experimental::AltsCredentials(alts_opts); } else if (type == grpc::testing::kTlsCredentialsType) { SslCredentialsOptions ssl_opts = {test_root_cert, "", ""}; args->SetSslTargetNameOverride("foo.test.google.fr"); @@ -77,6 +80,9 @@ class DefaultCredentialsProvider : public CredentialsProvider { const grpc::string& type) override { if (type == grpc::testing::kInsecureCredentialsType) { return InsecureServerCredentials(); + } else if (type == grpc::testing::kAltsCredentialsType) { + grpc::experimental::AltsServerCredentialsOptions alts_opts; + return grpc::experimental::AltsServerCredentials(alts_opts); } else if (type == grpc::testing::kTlsCredentialsType) { SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key, test_server1_cert}; diff --git a/test/cpp/util/test_credentials_provider.h b/test/cpp/util/test_credentials_provider.h index f489a2c563..b1d69e893d 100644 --- a/test/cpp/util/test_credentials_provider.h +++ b/test/cpp/util/test_credentials_provider.h @@ -29,10 +29,10 @@ namespace grpc { namespace testing { const char kInsecureCredentialsType[] = "INSECURE_CREDENTIALS"; - // For real credentials, like tls/ssl, this name should match the AuthContext // property "transport_security_type". const char kTlsCredentialsType[] = "ssl"; +const char kAltsCredentialsType[] = "alts"; // Provide test credentials of a particular type. class CredentialTypeProvider { |