Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/config/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ std::string ConfigHelper::startTlsConfig() {
TestEnvironment::runfilesPath("test/config/integration/certs/serverkey.pem")));
}

std::string ConfigHelper::testInspectorFilter() {
return R"EOF(
name: "envoy.filters.listener.test"
typed_config:
"@type": type.googleapis.com/google.protobuf.Struct
)EOF";
}

std::string ConfigHelper::tlsInspectorFilter(bool enable_ja3_fingerprinting) {
if (!enable_ja3_fingerprinting) {
return R"EOF(
Expand Down
3 changes: 3 additions & 0 deletions test/config/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ class ConfigHelper {
// A string for a tls inspector listener filter which can be used with addListenerFilter()
static std::string tlsInspectorFilter(bool enable_ja3_fingerprinting = false);

// A string for the test inspector filter.
static std::string testInspectorFilter();

// A basic configuration for L4 proxying.
static std::string tcpProxyConfig();
// A basic configuration for L7 proxying.
Expand Down
2 changes: 1 addition & 1 deletion test/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1433,11 +1433,11 @@ envoy_cc_test(
":http_integration_lib",
":http_protocol_integration_lib",
"//source/extensions/filters/listener/tls_inspector:config",
"//source/extensions/filters/listener/tls_inspector:tls_inspector_lib",
"//source/extensions/filters/network/tcp_proxy:config",
"//source/extensions/transport_sockets/tls:config",
"//source/extensions/transport_sockets/tls:context_config_lib",
"//source/extensions/transport_sockets/tls:context_lib",
"//test/integration/filters:test_listener_filter_lib",
"//test/test_common:environment_lib",
"//test/test_common:utility_lib",
"@envoy_api//envoy/config/bootstrap/v3:pkg_cc_proto",
Expand Down
15 changes: 15 additions & 0 deletions test/integration/filters/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ envoy_proto_library(
srcs = ["add_body_filter.proto"],
)

envoy_cc_test_library(
name = "test_listener_filter_lib",
srcs = [
"test_listener_filter.cc",
],
hdrs = [
"test_listener_filter.h",
],
deps = [
"//envoy/network:filter_interface",
"//envoy/registry",
"//envoy/server:filter_config_interface",
],
)

envoy_cc_test_library(
name = "add_body_filter_config_lib",
srcs = [
Expand Down
34 changes: 34 additions & 0 deletions test/integration/filters/test_listener_filter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "test/integration/filters/test_listener_filter.h"

namespace Envoy {

/**
* Config registration for the test filter.
*/
class TestInspectorConfigFactory : public Server::Configuration::NamedListenerFilterConfigFactory {
public:
// NamedListenerFilterConfigFactory
Network::ListenerFilterFactoryCb createListenerFilterFactoryFromProto(
const Protobuf::Message& /*message*/,
const Network::ListenerFilterMatcherSharedPtr& listener_filter_matcher,
Server::Configuration::ListenerFactoryContext& /*context*/) override {
return [listener_filter_matcher](Network::ListenerFilterManager& filter_manager) -> void {
filter_manager.addAcceptFilter(listener_filter_matcher,
std::make_unique<TestListenerFilter>());
};
}

ProtobufTypes::MessagePtr createEmptyConfigProto() override {
return ProtobufTypes::MessagePtr{new Envoy::ProtobufWkt::Struct()};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given #20397 and upcoming #20049 , can we add a real protobuf for this test filter?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean it's not needed here, so would it make sense to add it as a follow up over in one of those PRs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh whoops, I was looking at the second and not the first. :-/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we have #20476 for general fix-ups.

}

std::string name() const override { return "envoy.filters.listener.test"; }
};

absl::Mutex TestListenerFilter::alpn_lock_;
Copy link
Copy Markdown
Member

@soulxu soulxu Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way is to set the alpn as a parameter for this filter config, then we can get per-instance alpn value. But yes, it needs more code probably.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that doesn't work as we want one filter which returns different alpn values for different connections. But anyway the goal is to just have those tests pass without a filter some folks don't want to include so I think simple (with crummy locks) is fine :-)

std::string TestListenerFilter::alpn_;

REGISTER_FACTORY(TestInspectorConfigFactory,
Server::Configuration::NamedListenerFilterConfigFactory){"envoy.listener.test"};

} // namespace Envoy
35 changes: 35 additions & 0 deletions test/integration/filters/test_listener_filter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "envoy/registry/registry.h"
#include "envoy/server/filter_config.h"

namespace Envoy {
/**
* Test listener filter which sets the ALPN to a manually configured string.
*/
class TestListenerFilter : public Network::ListenerFilter {
public:
TestListenerFilter() = default;

// Network::ListenerFilter
Network::FilterStatus onAccept(Network::ListenerFilterCallbacks& cb) override {
absl::MutexLock m(&alpn_lock_);
ASSERT(!alpn_.empty());
cb.socket().setRequestedApplicationProtocols({alpn_});
alpn_.clear();
return Network::FilterStatus::Continue;
}
Network::FilterStatus onData(Network::ListenerFilterBuffer&) override {
return Network::FilterStatus::Continue;
}
size_t maxReadBytes() const override { return 0; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We got a new method for ListenerFilter

virtual FilterStatus onData(Network::ListenerFilterBuffer& buffer) PURE;

Just need a empty implement of onData

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh thanks for the heads up - github hadn't picked up what would have broken CI :-)

static void setAlpn(std::string alpn) {
absl::MutexLock m(&alpn_lock_);
alpn_ = alpn;
}

private:
static absl::Mutex alpn_lock_;
static std::string alpn_;
};

} // namespace Envoy
9 changes: 5 additions & 4 deletions test/integration/xds_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "source/common/buffer/buffer_impl.h"

#include "test/integration/filters/test_listener_filter.h"
#include "test/integration/http_integration.h"
#include "test/integration/http_protocol_integration.h"
#include "test/integration/ssl_utility.h"
Expand Down Expand Up @@ -140,8 +141,7 @@ class LdsInplaceUpdateTcpProxyIntegrationTest

void initialize() override {
config_helper_.renameListener("tcp");
std::string tls_inspector_config = ConfigHelper::tlsInspectorFilter();
config_helper_.addListenerFilter(tls_inspector_config);
config_helper_.addListenerFilter(ConfigHelper::testInspectorFilter());

config_helper_.addSslConfig();
config_helper_.addConfigModifier([](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
Expand All @@ -168,6 +168,7 @@ class LdsInplaceUpdateTcpProxyIntegrationTest
const std::string& request,
std::string& response) {
Buffer::OwnedImpl buffer(request);
TestListenerFilter::setAlpn(alpn);
return std::make_unique<RawConnectionDriver>(
lookupPort("tcp"), buffer,
[&response](Network::ClientConnection&, const Buffer::Instance& data) -> void {
Expand Down Expand Up @@ -298,8 +299,7 @@ class LdsInplaceUpdateHttpIntegrationTest
setUpstreamCount(2);

config_helper_.renameListener("http");
std::string tls_inspector_config = ConfigHelper::tlsInspectorFilter();
config_helper_.addListenerFilter(tls_inspector_config);
config_helper_.addListenerFilter(ConfigHelper::testInspectorFilter());
config_helper_.addSslConfig();
config_helper_.addConfigModifier(
[&](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
Expand Down Expand Up @@ -361,6 +361,7 @@ class LdsInplaceUpdateHttpIntegrationTest
}

IntegrationCodecClientPtr createHttpCodec(const std::string& alpn) {
TestListenerFilter::setAlpn(alpn);
auto ssl_conn = dispatcher_->createClientConnection(
address_, Network::Address::InstanceConstSharedPtr(),
context_->createTransportSocket(std::make_shared<Network::TransportSocketOptionsImpl>(
Expand Down