-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decode http request bodies that contain x-www-form-urlencoded data (#…
…1860) Summary: Decode http request bodies that contain x-www-form-urlencoded data This change enhances the request body in a `http_events` protocol trace for services that accept HTML form submissions. Relevant Issues: N/A Type of change: /kind feature Test Plan: New unit tests and trace bpf test verify decoding works Changelog Message: Decode `x-www-form-urlencoded` payloads within HTTP requests --------- Signed-off-by: Alma Pixie <[email protected]>
- Loading branch information
1 parent
cf88e33
commit d9d4a49
Showing
9 changed files
with
206 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
#include "src/common/testing/testing.h" | ||
#include "src/stirling/core/data_table.h" | ||
#include "src/stirling/source_connectors/socket_tracer/socket_trace_connector.h" | ||
#include "src/stirling/source_connectors/socket_tracer/testing/container_images/curl_container.h" | ||
#include "src/stirling/source_connectors/socket_tracer/testing/socket_trace_bpf_test_fixture.h" | ||
#include "src/stirling/testing/demo_apps/go_http/go_http_fixture.h" | ||
|
||
|
@@ -150,6 +151,82 @@ TEST_F(GoHTTPTraceTest, LargePostMessage) { | |
131096); | ||
} | ||
|
||
class CurlHTTPTraceTest : public SocketTraceBPFTestFixture</* TClientSideTracing */ false> { | ||
protected: | ||
CurlHTTPTraceTest() : SocketTraceBPFTestFixture() {} | ||
|
||
void SetUp() override { | ||
SocketTraceBPFTestFixture::SetUp(); | ||
go_http_fixture_.LaunchServer(); | ||
} | ||
|
||
void TearDown() override { | ||
SocketTraceBPFTestFixture::TearDown(); | ||
go_http_fixture_.ShutDown(); | ||
} | ||
|
||
testing::GoHTTPFixture go_http_fixture_; | ||
|
||
DataTable data_table_{/*id*/ 0, kHTTPTable}; | ||
}; | ||
|
||
TEST_F(CurlHTTPTraceTest, XFormURLEncodedRequest) { | ||
StartTransferDataThread(); | ||
|
||
// Uncomment to enable tracing: | ||
// FLAGS_stirling_conn_trace_pid = go_http_fixture_.server_pid(); | ||
|
||
::px::stirling::testing::CurlContainer client; | ||
auto payload = R"( | ||
{ | ||
"commands": [ | ||
{ | ||
"server": "api.use-case.svc.cluster.local:5011", | ||
"action": "req2", | ||
"telemetry": "uninstrumented", | ||
"params": {} | ||
}, | ||
{ | ||
"server": "repo.use-case.svc.cluster.local:5012", | ||
"action": "add_user", | ||
"telemetry": "uninstrumented", | ||
"params": { | ||
"name": "John Doe", | ||
"email": "[email protected]" | ||
} | ||
} | ||
] | ||
} | ||
)"; | ||
|
||
auto uri = absl::Substitute("http://127.0.0.1:$0/post", go_http_fixture_.server_port()); | ||
auto body = absl::Substitute("'action=$0'", payload); | ||
ASSERT_OK(client.Run(std::chrono::seconds{60}, {"--network=host"}, | ||
{"-XPOST", "--data-urlencode", body, uri})); | ||
client.Wait(); | ||
|
||
StopTransferDataThread(); | ||
|
||
std::vector<TaggedRecordBatch> tablets = ConsumeRecords(kHTTPTableNum); | ||
ASSERT_NOT_EMPTY_AND_GET_RECORDS(const types::ColumnWrapperRecordBatch& record_batch, tablets); | ||
|
||
// We do expect to trace the server. | ||
const std::vector<size_t> target_record_indices = | ||
testing::FindRecordIdxMatchesPID(record_batch, kHTTPUPIDIdx, go_http_fixture_.server_pid()); | ||
ASSERT_THAT(target_record_indices, SizeIs(1)); | ||
|
||
const size_t target_record_idx = target_record_indices.front(); | ||
|
||
EXPECT_THAT( | ||
std::string(record_batch[kHTTPReqHeadersIdx]->Get<types::StringValue>(target_record_idx)), | ||
AllOf( | ||
HasSubstr(R"("Content-Type":"application/x-www-form-urlencoded")"), | ||
HasSubstr(absl::Substitute(R"(Host":"127.0.0.1:$0")", go_http_fixture_.server_port())))); | ||
|
||
EXPECT_THAT(record_batch[kHTTPReqBodyIdx]->Get<types::StringValue>(target_record_idx), | ||
StrEq(body)); | ||
} | ||
|
||
struct TraceRoleTestParam { | ||
endpoint_role_t role; | ||
size_t client_records_count; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters