Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Add Local Addr & Port 3/3] Add simple test for capturing local IP #1809

Merged
merged 1 commit into from
Feb 2, 2024
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
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
Loading