Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Change-Id: Ic71b4df34e21a4939b4d0cca01812564e5e1c91a
Signed-off-by: Kuat Yessenov <[email protected]>
  • Loading branch information
kyessenov committed Feb 15, 2024
1 parent 9a03786 commit ce82ed3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/common/grpc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ envoy_cc_test(
":grpc_client_integration_test_harness_lib",
"//source/common/grpc:async_client_lib",
"//source/extensions/grpc_credentials/example:config",
"//test/test_common:test_runtime_lib",
] + envoy_select_google_grpc(["//source/common/grpc:google_async_client_lib"]),
)

Expand Down
24 changes: 24 additions & 0 deletions test/common/grpc/grpc_client_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "source/common/grpc/google_async_client_impl.h"

#include "test/test_common/test_runtime.h"

#endif

#include "test/common/grpc/grpc_client_integration_test_harness.h"
Expand Down Expand Up @@ -484,6 +486,8 @@ INSTANTIATE_TEST_SUITE_P(SslIpVersionsClientType, GrpcSslClientIntegrationTest,

// Validate that a simple request-reply unary RPC works with SSL.
TEST_P(GrpcSslClientIntegrationTest, BasicSslRequest) {
TestScopedRuntime scoped_runtime;
scoped_runtime.mergeValues({{"envoy.reloadable_features.google_grpc_disable_tls_13", "true"}});
initialize();
auto request = createRequest(empty_metadata_);
request->sendReply();
Expand All @@ -499,6 +503,26 @@ TEST_P(GrpcSslClientIntegrationTest, BasicSslRequestWithClientCert) {
dispatcher_helper_.runDispatcher();
}

// Validate TLS version mismatch between the client and the server.
TEST_P(GrpcSslClientIntegrationTest, BasicSslRequestHandshakeFailure) {
TestScopedRuntime scoped_runtime;
scoped_runtime.mergeValues({{"envoy.reloadable_features.google_grpc_disable_tls_13", "true"}});
use_client_tls_12_ = true;
use_server_tls_13_ = true;
initialize();
auto request = createRequest(empty_metadata_, false);
FakeRawConnectionPtr fake_connection;
ASSERT_TRUE(fake_upstream_->waitForRawConnection(fake_connection));
dispatcher_helper_.dispatcher_.run(Event::Dispatcher::RunType::NonBlock);
if (fake_connection->connected()) {
ASSERT_TRUE(fake_connection->waitForDisconnect());
}
EXPECT_CALL(*request->child_span_,
setTag(Eq(Tracing::Tags::get().Status), Eq(Tracing::Tags::get().Canceled)));
EXPECT_CALL(*request->child_span_, finishSpan());
request->grpc_request_->cancel();
}

#ifdef ENVOY_GOOGLE_GRPC
// AccessToken credential validation tests.
class GrpcAccessTokenClientIntegrationTest : public GrpcSslClientIntegrationTest {
Expand Down
27 changes: 26 additions & 1 deletion test/common/grpc/grpc_client_integration_test_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ class GrpcClientIntegrationTest : public GrpcClientIntegrationParamTest {

virtual void expectExtraHeaders(FakeStream&) {}

HelloworldRequestPtr createRequest(const TestMetadata& initial_metadata) {
HelloworldRequestPtr createRequest(const TestMetadata& initial_metadata,
bool expect_upstream_request = true) {
auto request = std::make_unique<HelloworldRequest>(dispatcher_helper_);
EXPECT_CALL(*request, onCreateInitialMetadata(_))
.WillOnce(Invoke([&initial_metadata](Http::HeaderMap& headers) {
Expand All @@ -417,15 +418,22 @@ class GrpcClientIntegrationTest : public GrpcClientIntegrationParamTest {
setTag(Eq(Tracing::Tags::get().Component), Eq(Tracing::Tags::get().Proxy)));
EXPECT_CALL(*request->child_span_, injectContext(_, _));

Http::AsyncClient::RequestOptions options;
options.setTimeout(std::chrono::milliseconds(1000));
request->grpc_request_ = grpc_client_->send(*method_descriptor_, request_msg, *request,
active_span, Http::AsyncClient::RequestOptions());
EXPECT_NE(request->grpc_request_, nullptr);

if (!expect_upstream_request) {
return request;
}

if (!fake_connection_) {
AssertionResult result =
fake_upstream_->waitForHttpConnection(*dispatcher_, fake_connection_);
RELEASE_ASSERT(result, result.message());
}

fake_streams_.emplace_back();
AssertionResult result = fake_connection_->waitForNewStream(*dispatcher_, fake_streams_.back());
RELEASE_ASSERT(result, result.message());
Expand Down Expand Up @@ -556,6 +564,14 @@ class GrpcSslClientIntegrationTest : public GrpcClientIntegrationTest {
tls_cert->mutable_private_key()->set_filename(
TestEnvironment::runfilesPath("test/config/integration/certs/clientkey.pem"));
}
if (use_client_tls_12_) {
auto* tls_params = common_tls_context->mutable_tls_params();
tls_params->set_tls_minimum_protocol_version(
envoy::extensions::transport_sockets::tls::v3::TlsParameters::TLSv1_2);
tls_params->set_tls_maximum_protocol_version(
envoy::extensions::transport_sockets::tls::v3::TlsParameters::TLSv1_2);
}

auto cfg = std::make_unique<Extensions::TransportSockets::Tls::ClientContextConfigImpl>(
tls_context, factory_context_);

Expand Down Expand Up @@ -587,6 +603,13 @@ class GrpcSslClientIntegrationTest : public GrpcClientIntegrationTest {
validation_context->mutable_trusted_ca()->set_filename(
TestEnvironment::runfilesPath("test/config/integration/certs/cacert.pem"));
}
if (use_server_tls_13_) {
auto* tls_params = common_tls_context->mutable_tls_params();
tls_params->set_tls_minimum_protocol_version(
envoy::extensions::transport_sockets::tls::v3::TlsParameters::TLSv1_3);
tls_params->set_tls_maximum_protocol_version(
envoy::extensions::transport_sockets::tls::v3::TlsParameters::TLSv1_3);
}

auto cfg = std::make_unique<Extensions::TransportSockets::Tls::ServerContextConfigImpl>(
tls_context, factory_context_);
Expand All @@ -598,6 +621,8 @@ class GrpcSslClientIntegrationTest : public GrpcClientIntegrationTest {
}

bool use_client_cert_{};
bool use_client_tls_12_{false};
bool use_server_tls_13_{false};
testing::NiceMock<Server::Configuration::MockTransportSocketFactoryContext> factory_context_;
};

Expand Down

0 comments on commit ce82ed3

Please sign in to comment.