-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Packetbeat: System tests for HTTP unmatched requests
Added tests for the HTTP unmatched requests and responses. - test_unmatched_response: Checks that a response received out of order inside a stream is reported as an Error. - test_unmatched_request: Tests that a single stream containing only one request is reported after the stream times out. This tests can't be run with packetbeat's -t flag as it needs to wait 10s for the stream to expire. This timeout is currently not configurable.
- Loading branch information
Showing
5 changed files
with
66 additions
and
2 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
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from packetbeat import BaseTest | ||
|
||
|
||
def check_event(event, expected): | ||
for key in expected: | ||
assert key in event, "key '{0}' not found in event".format(key) | ||
assert event[key] == expected[key],\ | ||
"key '{0}' has value '{1}', expected '{2}'".format(key, | ||
event[key], | ||
expected[key]) | ||
|
||
|
||
class Test(BaseTest): | ||
|
||
def test_unmatched_response(self): | ||
""" | ||
Unmatched response in stream | ||
""" | ||
|
||
self.render_config_template( | ||
http_ports=[8080], | ||
) | ||
self.run_packetbeat(pcap="http_unmatched.pcap", | ||
debug_selectors=["http", "httpdetailed"]) | ||
objs = self.read_output() | ||
|
||
assert len(objs) == 2 | ||
|
||
check_event(objs[0], { | ||
"type": "http", | ||
"status": "Error", | ||
"http.response.code": 404, | ||
"notes": ["Unmatched response"]}) | ||
|
||
check_event(objs[1], { | ||
"type": "http", | ||
"http.response.code": 200, | ||
"http.request.headers": {"content-length": 0}, | ||
"status": "OK"}) | ||
|
||
def test_unmatched_request(self): | ||
""" | ||
Unmatched request due to timeout (15s) | ||
""" | ||
|
||
self.render_config_template( | ||
http_ports=[8080], | ||
http_transaction_timeout="1s", | ||
) | ||
self.run_packetbeat(pcap="http_unmatched_timeout.pcap", | ||
debug_selectors=["http", "httpdetailed"], | ||
real_time=True) | ||
objs = self.read_output() | ||
print objs | ||
assert len(objs) == 1 | ||
check_event(objs[0], { | ||
"type": "http", | ||
"status": "Error", | ||
"query": "GET /something", | ||
"notes": ["Unmatched request"]}) |