Skip to content

Commit

Permalink
bpf_metadata: add unit-test for proxylib l7 proto
Browse files Browse the repository at this point in the history
[ upstream commit 585ba14 ]

This commit adds an unit test that verifies that the proxylib
l7 protocol has been correctly set to the request application
protocols of the network socket.

Signed-off-by: Marco Hofstetter <[email protected]>
  • Loading branch information
mhofstetter authored and jrajahalme committed Jan 21, 2025
1 parent e91ca2f commit 690b822
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/metadata_config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cstdint>
#include <list>
#include <memory>
#include <string>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -481,6 +482,40 @@ TEST_F(MetadataConfigTest, EastWestL7LbMetadataNoOriginalSource) {
(cilium_mark_socket_option->mark_ >> 16) == 8);
}

TEST_F(MetadataConfigTest, ProxyLibNotConfigured) {
::cilium::BpfMetadata config{};

EXPECT_NO_THROW(initialize(config));

auto socket_metadata = config_->extractSocketMetadata(socket_);
EXPECT_TRUE(socket_metadata);

EXPECT_CALL(socket_, setRequestedApplicationProtocols(_)).Times(0);

socket_metadata->configureProxyLibApplicationProtocol(socket_);
}

TEST_F(MetadataConfigTest, ProxyLibConfigured) {
::cilium::BpfMetadata config{};

EXPECT_NO_THROW(initialize(config));

auto socket_metadata = config_->extractSocketMetadata(socket_);
EXPECT_TRUE(socket_metadata);

// set proxylib proto manually
socket_metadata->proxylib_l7_proto_ = "r2d2";

std::vector<std::string> protocols = {"h2c"};
EXPECT_CALL(socket_, requestedApplicationProtocols).WillOnce(testing::ReturnRef(protocols));

// proxylib protocol should be appended to the list of existing requested application protocols
const auto protos = std::vector<absl::string_view>{"h2c", "r2d2"};
EXPECT_CALL(socket_, setRequestedApplicationProtocols(protos));

socket_metadata->configureProxyLibApplicationProtocol(socket_);
}

} // namespace
} // namespace Cilium
} // namespace Envoy

0 comments on commit 690b822

Please sign in to comment.