diff --git a/src/core/ext/filters/client_channel/xds/xds_api.cc b/src/core/ext/filters/client_channel/xds/xds_api.cc index 8a19d2b7dae..13d5b0bd4d2 100644 --- a/src/core/ext/filters/client_channel/xds/xds_api.cc +++ b/src/core/ext/filters/client_channel/xds/xds_api.cc @@ -1046,6 +1046,10 @@ grpc_error* RouteConfigParse( } rds_route.service = std::string(path_elements[0]); rds_route.method = std::string(path_elements[1]); + } else { + // TODO(donnadionne): We may change this behavior once we decide how to + // handle unsupported fields. + continue; } if (!envoy_api_v2_route_Route_has_route(route)) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING( diff --git a/test/cpp/end2end/test_service_impl.h b/test/cpp/end2end/test_service_impl.h index 905f2cbea89..1fed3e55d61 100644 --- a/test/cpp/end2end/test_service_impl.h +++ b/test/cpp/end2end/test_service_impl.h @@ -57,92 +57,6 @@ typedef enum { CANCEL_AFTER_PROCESSING } ServerTryCancelRequestPhase; -namespace { - -// When echo_deadline is requested, deadline seen in the ServerContext is set in -// the response in seconds. -void MaybeEchoDeadline(experimental::ServerContextBase* context, - const EchoRequest* request, EchoResponse* response) { - if (request->has_param() && request->param().echo_deadline()) { - gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_REALTIME); - if (context->deadline() != system_clock::time_point::max()) { - Timepoint2Timespec(context->deadline(), &deadline); - } - response->mutable_param()->set_request_deadline(deadline.tv_sec); - } -} - -void CheckServerAuthContext( - const experimental::ServerContextBase* context, - const grpc::string& expected_transport_security_type, - const grpc::string& expected_client_identity) { - std::shared_ptr auth_ctx = context->auth_context(); - std::vector tst = - auth_ctx->FindPropertyValues("transport_security_type"); - EXPECT_EQ(1u, tst.size()); - EXPECT_EQ(expected_transport_security_type, ToString(tst[0])); - if (expected_client_identity.empty()) { - EXPECT_TRUE(auth_ctx->GetPeerIdentityPropertyName().empty()); - EXPECT_TRUE(auth_ctx->GetPeerIdentity().empty()); - EXPECT_FALSE(auth_ctx->IsPeerAuthenticated()); - } else { - auto identity = auth_ctx->GetPeerIdentity(); - EXPECT_TRUE(auth_ctx->IsPeerAuthenticated()); - EXPECT_EQ(1u, identity.size()); - EXPECT_EQ(expected_client_identity, identity[0]); - } -} - -// Returns the number of pairs in metadata that exactly match the given -// key-value pair. Returns -1 if the pair wasn't found. -int MetadataMatchCount( - const std::multimap& metadata, - const grpc::string& key, const grpc::string& value) { - int count = 0; - for (const auto& metadatum : metadata) { - if (ToString(metadatum.first) == key && - ToString(metadatum.second) == value) { - count++; - } - } - return count; -} -} // namespace - -namespace { -int GetIntValueFromMetadataHelper( - const char* key, - const std::multimap& metadata, - int default_value) { - if (metadata.find(key) != metadata.end()) { - std::istringstream iss(ToString(metadata.find(key)->second)); - iss >> default_value; - gpr_log(GPR_INFO, "%s : %d", key, default_value); - } - - return default_value; -} - -int GetIntValueFromMetadata( - const char* key, - const std::multimap& metadata, - int default_value) { - return GetIntValueFromMetadataHelper(key, metadata, default_value); -} - -void ServerTryCancel(ServerContext* context) { - EXPECT_FALSE(context->IsCancelled()); - context->TryCancel(); - gpr_log(GPR_INFO, "Server called TryCancel() to cancel the request"); - // Now wait until it's really canceled - while (!context->IsCancelled()) { - gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_micros(1000, GPR_TIMESPAN))); - } -} - -} // namespace - class TestServiceSignaller { public: void ClientWaitUntilRpcStarted() { @@ -179,6 +93,87 @@ class TestMultipleServiceImpl : public RpcService { explicit TestMultipleServiceImpl(const grpc::string& host) : signal_client_(false), host_(new grpc::string(host)) {} + // When echo_deadline is requested, deadline seen in the ServerContext is set + // in the response in seconds. + void static MaybeEchoDeadline(experimental::ServerContextBase* context, + const EchoRequest* request, + EchoResponse* response) { + if (request->has_param() && request->param().echo_deadline()) { + gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_REALTIME); + if (context->deadline() != system_clock::time_point::max()) { + Timepoint2Timespec(context->deadline(), &deadline); + } + response->mutable_param()->set_request_deadline(deadline.tv_sec); + } + } + + void static CheckServerAuthContext( + const experimental::ServerContextBase* context, + const grpc::string& expected_transport_security_type, + const grpc::string& expected_client_identity) { + std::shared_ptr auth_ctx = context->auth_context(); + std::vector tst = + auth_ctx->FindPropertyValues("transport_security_type"); + EXPECT_EQ(1u, tst.size()); + EXPECT_EQ(expected_transport_security_type, ToString(tst[0])); + if (expected_client_identity.empty()) { + EXPECT_TRUE(auth_ctx->GetPeerIdentityPropertyName().empty()); + EXPECT_TRUE(auth_ctx->GetPeerIdentity().empty()); + EXPECT_FALSE(auth_ctx->IsPeerAuthenticated()); + } else { + auto identity = auth_ctx->GetPeerIdentity(); + EXPECT_TRUE(auth_ctx->IsPeerAuthenticated()); + EXPECT_EQ(1u, identity.size()); + EXPECT_EQ(expected_client_identity, identity[0]); + } + } + + // Returns the number of pairs in metadata that exactly match the given + // key-value pair. Returns -1 if the pair wasn't found. + int static MetadataMatchCount( + const std::multimap& metadata, + const grpc::string& key, const grpc::string& value) { + int count = 0; + for (const auto& metadatum : metadata) { + if (ToString(metadatum.first) == key && + ToString(metadatum.second) == value) { + count++; + } + } + return count; + } + + int static GetIntValueFromMetadataHelper( + const char* key, + const std::multimap& metadata, + int default_value) { + if (metadata.find(key) != metadata.end()) { + std::istringstream iss(ToString(metadata.find(key)->second)); + iss >> default_value; + gpr_log(GPR_INFO, "%s : %d", key, default_value); + } + + return default_value; + } + + int static GetIntValueFromMetadata( + const char* key, + const std::multimap& metadata, + int default_value) { + return GetIntValueFromMetadataHelper(key, metadata, default_value); + } + + void static ServerTryCancel(ServerContext* context) { + EXPECT_FALSE(context->IsCancelled()); + context->TryCancel(); + gpr_log(GPR_INFO, "Server called TryCancel() to cancel the request"); + // Now wait until it's really canceled + while (!context->IsCancelled()) { + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(1000, GPR_TIMESPAN))); + } + } + Status Echo(ServerContext* context, const EchoRequest* request, EchoResponse* response) { if (request->has_param() && @@ -311,6 +306,7 @@ class TestMultipleServiceImpl : public RpcService { } // Unimplemented is left unimplemented to test the returned error. + Status RequestStream(ServerContext* context, ServerReader* reader, EchoResponse* response) { diff --git a/test/cpp/end2end/xds_end2end_test.cc b/test/cpp/end2end/xds_end2end_test.cc index f08702f623e..0b1a474d265 100644 --- a/test/cpp/end2end/xds_end2end_test.cc +++ b/test/cpp/end2end/xds_end2end_test.cc @@ -264,12 +264,12 @@ class BackendServiceImpl Status Echo1(ServerContext* context, const EchoRequest* request, EchoResponse* response) override { - return (Echo(context, request, response)); + return Echo(context, request, response); } Status Echo2(ServerContext* context, const EchoRequest* request, EchoResponse* response) override { - return (Echo(context, request, response)); + return Echo(context, request, response); } void Start() {} @@ -2197,10 +2197,10 @@ TEST_P(LdsTest, RouteMatchHasNonemptyPrefix) { TEST_P(LdsTest, RouteMatchHasEmptyPath) { RouteConfiguration route_config = balancers_[0]->ads_service()->default_route_config(); - route_config.mutable_virtual_hosts(0) - ->mutable_routes(0) - ->mutable_match() - ->set_path(""); + auto* route1 = route_config.mutable_virtual_hosts(0)->mutable_routes(0); + route1->mutable_match()->set_path(""); + auto* default_route = route_config.mutable_virtual_hosts(0)->add_routes(); + default_route->mutable_match()->set_prefix(""); balancers_[0]->ads_service()->SetLdsResource( AdsServiceImpl::BuildListener(route_config), kDefaultResourceName); SetNextResolution({}); @@ -2291,20 +2291,15 @@ TEST_P(LdsTest, XdsRoutingPathMatching) { Cluster new_cluster2 = balancers_[0]->ads_service()->default_cluster(); new_cluster2.set_name(kNewCluster2Name); balancers_[0]->ads_service()->SetCdsResource(new_cluster2, kNewCluster2Name); - // Change RDS resource to set up prefix matching to direct traffic to the - // second new cluster. + // Populating Route Configurations for LDS. RouteConfiguration new_route_config = balancers_[0]->ads_service()->default_route_config(); - auto* mismatched_route1 = - new_route_config.mutable_virtual_hosts(0)->mutable_routes(0); - mismatched_route1->mutable_match()->set_path( - "/grpc.testing.EchoTest1Service/Echo1"); - mismatched_route1->mutable_route()->set_cluster(kNewCluster1Name); - auto* mismatched_route2 = - new_route_config.mutable_virtual_hosts(0)->add_routes(); - mismatched_route2->mutable_match()->set_path( - "/grpc.testing.EchoTest2Service/Echo2"); - mismatched_route2->mutable_route()->set_cluster(kNewCluster2Name); + auto* route1 = new_route_config.mutable_virtual_hosts(0)->mutable_routes(0); + route1->mutable_match()->set_path("/grpc.testing.EchoTest1Service/Echo1"); + route1->mutable_route()->set_cluster(kNewCluster1Name); + auto* route2 = new_route_config.mutable_virtual_hosts(0)->add_routes(); + route2->mutable_match()->set_path("/grpc.testing.EchoTest2Service/Echo2"); + route2->mutable_route()->set_cluster(kNewCluster2Name); auto* default_route = new_route_config.mutable_virtual_hosts(0)->add_routes(); default_route->mutable_match()->set_prefix(""); default_route->mutable_route()->set_cluster(kDefaultResourceName); @@ -2367,18 +2362,15 @@ TEST_P(LdsTest, XdsRoutingPrefixMatching) { Cluster new_cluster2 = balancers_[0]->ads_service()->default_cluster(); new_cluster2.set_name(kNewCluster2Name); balancers_[0]->ads_service()->SetCdsResource(new_cluster2, kNewCluster2Name); - // Change RDS resource to set up prefix matching to direct traffic to the - // second new cluster. + // Populating Route Configurations for LDS. RouteConfiguration new_route_config = balancers_[0]->ads_service()->default_route_config(); - auto* mismatched_route = - new_route_config.mutable_virtual_hosts(0)->mutable_routes(0); - mismatched_route->mutable_match()->set_prefix( - "/grpc.testing.EchoTest1Service"); - mismatched_route->mutable_route()->set_cluster(kNewCluster1Name); - auto* matched_route = new_route_config.mutable_virtual_hosts(0)->add_routes(); - matched_route->mutable_match()->set_prefix("/grpc.testing.EchoTest2Service"); - matched_route->mutable_route()->set_cluster(kNewCluster2Name); + auto* route1 = new_route_config.mutable_virtual_hosts(0)->mutable_routes(0); + route1->mutable_match()->set_prefix("/grpc.testing.EchoTest1Service"); + route1->mutable_route()->set_cluster(kNewCluster1Name); + auto* route2 = new_route_config.mutable_virtual_hosts(0)->add_routes(); + route2->mutable_match()->set_prefix("/grpc.testing.EchoTest2Service"); + route2->mutable_route()->set_cluster(kNewCluster2Name); auto* default_route = new_route_config.mutable_virtual_hosts(0)->add_routes(); default_route->mutable_match()->set_prefix(""); default_route->mutable_route()->set_cluster(kDefaultResourceName); diff --git a/test/cpp/util/grpc_tool_test.cc b/test/cpp/util/grpc_tool_test.cc index d8ce3304560..b353033f874 100644 --- a/test/cpp/util/grpc_tool_test.cc +++ b/test/cpp/util/grpc_tool_test.cc @@ -1107,9 +1107,10 @@ TEST_F(GrpcToolTest, CallCommandWithMetadata) { ShutdownServer(); } -/*TEST_F(GrpcToolTest, CallCommandWithBadMetadata) { +TEST_F(GrpcToolTest, CallCommandWithBadMetadata) { // Test input "grpc_cli call localhost:10000 Echo "message: 'Hello'" - const char* argv[] = {"grpc_cli", "call", "localhost:10000", "Echo", + const char* argv[] = {"grpc_cli", "call", "localhost:10000", + "grpc.testing.EchoTestService.Echo", "message: 'Hello'"}; FLAGS_protofiles = "src/proto/grpc/testing/echo.proto"; char* test_srcdir = gpr_getenv("TEST_SRCDIR"); @@ -1143,7 +1144,7 @@ TEST_F(GrpcToolTest, CallCommandWithMetadata) { FLAGS_protofiles = ""; gpr_free(test_srcdir); -}*/ +} TEST_F(GrpcToolTest, ListCommand_OverrideSslHostName) { const grpc::string server_address = SetUpServer(true);