Skip to content

Commit

Permalink
Add simple tests for local address in http
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Kilimnik <[email protected]>
  • Loading branch information
benkilimnik committed Jan 25, 2024
1 parent fdce3fd commit 1a84c5a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ TEST_F(GoHTTPTraceTest, RequestAndResponse) {
std::string(record_batch[kHTTPRemoteAddrIdx]->Get<types::StringValue>(target_record_idx)),
// On IPv6 host, localhost is resolved to ::1.
AnyOf(HasSubstr("127.0.0.1"), HasSubstr("::1")));
EXPECT_THAT(
std::string(record_batch[kHTTPLocalAddrIdx]->Get<types::StringValue>(target_record_idx)),
// Due to loopback, the local address is the same as the remote address.
AnyOf(HasSubstr("127.0.0.1"), HasSubstr("::1")));
EXPECT_THAT(record_batch[kHTTPRespBodyIdx]->Get<types::StringValue>(target_record_idx),
StrEq(absl::StrCat(R"({"greeter":"Hello PixieLabs!"})", "\n")));
// This test currently performs client-side tracing because of the cluster CIDR in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class Python310ContainerWrapper : public ::px::stirling::testing::Python310Conta
struct TraceRecords {
std::vector<http::Record> http_records;
std::vector<std::string> remote_address;
std::vector<std::string> local_address;
};

template <typename TServerContainer>
Expand Down Expand Up @@ -126,7 +127,9 @@ class OpenSSLTraceTest : public SocketTraceBPFTestFixture</* TClientSideTracing
ToRecordVector<http::Record>(record_batch, server_record_indices);
std::vector<std::string> remote_addresses =
testing::GetRemoteAddrs(record_batch, server_record_indices);
return {std::move(http_records), std::move(remote_addresses)};
std::vector<std::string> local_address =
testing::GetLocalAddrs(record_batch, server_record_indices);
return {std::move(http_records), std::move(remote_addresses), std::move(local_address)};
}

TServerContainer server_;
Expand Down Expand Up @@ -200,6 +203,8 @@ TYPED_TEST(OpenSSLTraceTest, ssl_capture_curl_client) {

EXPECT_THAT(records.http_records, UnorderedElementsAre(EqHTTPRecord(expected_record)));
EXPECT_THAT(records.remote_address, UnorderedElementsAre(StrEq("127.0.0.1")));
// Due to loopback, the local address is the same as the remote address.
EXPECT_THAT(records.local_address, UnorderedElementsAre(StrEq("127.0.0.1")));
}

TYPED_TEST(OpenSSLTraceTest, ssl_capture_ruby_client) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ inline std::vector<std::string> GetRemoteAddrs(const types::ColumnWrapperRecordB
return addrs;
}

inline std::vector<std::string> GetLocalAddrs(const types::ColumnWrapperRecordBatch& rb,
const std::vector<size_t>& indices) {
std::vector<std::string> addrs;
for (size_t idx : indices) {
addrs.push_back(rb[kHTTPLocalAddrIdx]->Get<types::StringValue>(idx));
}
return addrs;
}

inline std::vector<int64_t> GetRemotePorts(const types::ColumnWrapperRecordBatch& rb,
const std::vector<size_t>& indices) {
std::vector<int64_t> addrs;
Expand Down

0 comments on commit 1a84c5a

Please sign in to comment.