Skip to content

Commit

Permalink
usm: http2: tests: Add coverage for the bug
Browse files Browse the repository at this point in the history
Added 2 tests, the first to check we are able to consume correctly frame that is split
to many packets.

The second to check an unsupported scenario (headers frame that its payload split on multiple packets)
does not prevent us from continue capturing valid requests on the connection
  • Loading branch information
guyarb committed Dec 26, 2024
1 parent 252116e commit 65f180a
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pkg/network/usm/usm_http2_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,61 @@ func (s *usmHTTP2Suite) TestRawTraffic() {
}: 1,
},
},
{
name: "interesting frame split into multiple packets",
// Testing a scenario where an interesting frame is split into multiple packets.
// First, headers is split to frame-header and then frame-payload.
// Second, data is split to frame-header, portion of the frame-payload, and the rest of the frame-payload.
messageBuilder: func() [][]byte {
data := []byte("123456789")
headersFrame := newFramer().
writeHeaders(t, 1, usmhttp2.HeadersFrameOptions{Headers: generateTestHeaderFields(headersGenerationOptions{overrideContentLength: len(data)})})
headersLength := headersFrame.buf.Len()
frame := headersFrame.writeData(t, 1, true, data).bytes()
return [][]byte{
frame[:9],
frame[9:headersLength],
frame[headersLength : headersLength+9],
frame[headersLength+9 : headersLength+12],
frame[headersLength+12:],
}
},
expectedEndpoints: map[usmhttp.Key]int{
{
Path: usmhttp.Path{Content: usmhttp.Interner.GetString(http2DefaultTestPath)},
Method: usmhttp.MethodPost,
}: 1,
},
},
{
name: "headers frame split into multiple packets unevenly",
// Testing a scenario where a headers frame is split into multiple packets in a way that the first packet
// contains the frame header and a couple of bytes from the frame payload, and the second packet contains
// the rest of the frame payload.
// This scenario is not supported, as we don't have the ability to reassemble the frame payload, and then
// to parse it.
// We check the unsupported scenario does not prevent us from capturing the next valid request.
messageBuilder: func() [][]byte {
data := []byte("123456789")
message := newFramer().
writeHeaders(t, 1, usmhttp2.HeadersFrameOptions{Headers: generateTestHeaderFields(headersGenerationOptions{overrideContentLength: len(data)})})
headersLength := message.buf.Len()
frame := message.writeData(t, 1, true, data).
writeHeaders(t, 3, usmhttp2.HeadersFrameOptions{Headers: headersWithGivenEndpoint("/bbb")}).
writeData(t, 3, true, emptyBody).bytes()
return [][]byte{
frame[:10],
frame[10:headersLength],
frame[headersLength:],
}
},
expectedEndpoints: map[usmhttp.Key]int{
{
Path: usmhttp.Path{Content: usmhttp.Interner.GetString("/bbb")},
Method: usmhttp.MethodPost,
}: 1,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 65f180a

Please sign in to comment.