Skip to content

Commit 1a84c5a

Browse files
committed
Add simple tests for local address in http
Signed-off-by: Benjamin Kilimnik <bkilimnik@pixielabs.ai>
1 parent fdce3fd commit 1a84c5a

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/stirling/source_connectors/socket_tracer/http_trace_bpf_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ TEST_F(GoHTTPTraceTest, RequestAndResponse) {
9393
std::string(record_batch[kHTTPRemoteAddrIdx]->Get<types::StringValue>(target_record_idx)),
9494
// On IPv6 host, localhost is resolved to ::1.
9595
AnyOf(HasSubstr("127.0.0.1"), HasSubstr("::1")));
96+
EXPECT_THAT(
97+
std::string(record_batch[kHTTPLocalAddrIdx]->Get<types::StringValue>(target_record_idx)),
98+
// Due to loopback, the local address is the same as the remote address.
99+
AnyOf(HasSubstr("127.0.0.1"), HasSubstr("::1")));
96100
EXPECT_THAT(record_batch[kHTTPRespBodyIdx]->Get<types::StringValue>(target_record_idx),
97101
StrEq(absl::StrCat(R"({"greeter":"Hello PixieLabs!"})", "\n")));
98102
// This test currently performs client-side tracing because of the cluster CIDR in

src/stirling/source_connectors/socket_tracer/openssl_trace_bpf_test.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class Python310ContainerWrapper : public ::px::stirling::testing::Python310Conta
9595
struct TraceRecords {
9696
std::vector<http::Record> http_records;
9797
std::vector<std::string> remote_address;
98+
std::vector<std::string> local_address;
9899
};
99100

100101
template <typename TServerContainer>
@@ -126,7 +127,9 @@ class OpenSSLTraceTest : public SocketTraceBPFTestFixture</* TClientSideTracing
126127
ToRecordVector<http::Record>(record_batch, server_record_indices);
127128
std::vector<std::string> remote_addresses =
128129
testing::GetRemoteAddrs(record_batch, server_record_indices);
129-
return {std::move(http_records), std::move(remote_addresses)};
130+
std::vector<std::string> local_address =
131+
testing::GetLocalAddrs(record_batch, server_record_indices);
132+
return {std::move(http_records), std::move(remote_addresses), std::move(local_address)};
130133
}
131134

132135
TServerContainer server_;
@@ -200,6 +203,8 @@ TYPED_TEST(OpenSSLTraceTest, ssl_capture_curl_client) {
200203

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

205210
TYPED_TEST(OpenSSLTraceTest, ssl_capture_ruby_client) {

src/stirling/source_connectors/socket_tracer/testing/protocol_checkers.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ inline std::vector<std::string> GetRemoteAddrs(const types::ColumnWrapperRecordB
117117
return addrs;
118118
}
119119

120+
inline std::vector<std::string> GetLocalAddrs(const types::ColumnWrapperRecordBatch& rb,
121+
const std::vector<size_t>& indices) {
122+
std::vector<std::string> addrs;
123+
for (size_t idx : indices) {
124+
addrs.push_back(rb[kHTTPLocalAddrIdx]->Get<types::StringValue>(idx));
125+
}
126+
return addrs;
127+
}
128+
120129
inline std::vector<int64_t> GetRemotePorts(const types::ColumnWrapperRecordBatch& rb,
121130
const std::vector<size_t>& indices) {
122131
std::vector<int64_t> addrs;

0 commit comments

Comments
 (0)