Skip to content

Commit

Permalink
add test to ensure async client uses correct scheme header
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Meier <[email protected]>
  • Loading branch information
meierfra-ergon committed Jan 6, 2025
1 parent 2d1e5bb commit 1b964b6
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/common/http/async_client_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "test/mocks/http/mocks.h"
#include "test/mocks/router/mocks.h"
#include "test/mocks/server/server_factory_context.h"
#include "test/mocks/ssl/mocks.h"
#include "test/mocks/stats/mocks.h"
#include "test/mocks/upstream/cluster_manager.h"
#include "test/test_common/printers.h"
Expand Down Expand Up @@ -55,6 +56,8 @@ class AsyncClientImplTest : public testing::Test {
message_->headers().setPath("/");
ON_CALL(*cm_.thread_local_cluster_.conn_pool_.host_, locality())
.WillByDefault(ReturnRef(envoy::config::core::v3::Locality().default_instance()));
ON_CALL(*cm_.thread_local_cluster_.conn_pool_.host_, transportSocketFactory())
.WillByDefault(ReturnRef(socket_factory_));
cm_.initializeThreadLocalClusters({"fake_cluster"});
HttpTestUtility::addDefaultHeaders(headers_);
}
Expand Down Expand Up @@ -94,6 +97,7 @@ class AsyncClientImplTest : public testing::Test {
Router::ContextImpl router_context_;
AsyncClientImpl client_;
NiceMock<StreamInfo::MockStreamInfo> stream_info_;
testing::NiceMock<Network::MockTransportSocketFactory> socket_factory_;
};

class AsyncClientImplTracingTest : public AsyncClientImplTest {
Expand Down Expand Up @@ -2387,5 +2391,34 @@ TEST_F(AsyncClientImplUnitTest, NullVirtualHost) {
EXPECT_EQ(std::numeric_limits<uint32_t>::max(), vhost_.retryShadowBufferLimit());
}

TEST_F(AsyncClientImplTest, UpstreamTlsScheme) {
message_->body().add("test body");
Buffer::Instance& data = message_->body();

Envoy::Ssl::ClientContextSharedPtr sslCtx{new Envoy::Ssl::MockClientContext()};
EXPECT_CALL(socket_factory_, sslCtx()).WillRepeatedly(Return(sslCtx));

EXPECT_CALL(cm_.thread_local_cluster_.conn_pool_, newStream(_, _, _))
.WillOnce(Invoke(
[&](ResponseDecoder& decoder, ConnectionPool::Callbacks& callbacks,
const ConnectionPool::Instance::StreamOptions&) -> ConnectionPool::Cancellable* {
callbacks.onPoolReady(stream_encoder_, cm_.thread_local_cluster_.conn_pool_.host_,
stream_info_, {});
response_decoder_ = &decoder;
return nullptr;
}));

TestRequestHeaderMapImpl copy(message_->headers());
copy.addCopy("x-envoy-internal", "true");
copy.addCopy("x-forwarded-for", "127.0.0.1");
copy.addCopy(":scheme", "https");

EXPECT_CALL(stream_encoder_, encodeHeaders(HeaderMapEqualRef(&copy), false));
EXPECT_CALL(stream_encoder_, encodeData(BufferEqual(&data), true));

auto* request = client_.send(std::move(message_), callbacks_, AsyncClient::RequestOptions());
EXPECT_NE(request, nullptr);
}

} // namespace Http
} // namespace Envoy

0 comments on commit 1b964b6

Please sign in to comment.