Skip to content

Commit a088fd3

Browse files
committed
test(dns): add regression test for DNS capture on connection abort
Adds a /CONNECTION_ABORT/ handler to the test server that sends headers then forcibly closes the connection, and a test proving DNS data is still captured. This guards against reverting from onHeadersReceived to onCompleted, which would miss aborted requests.
1 parent 5a9fba6 commit a088fd3

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

test/test_dns_instrument.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,24 @@ def test_name_resolution(default_params, task_manager_creator):
2525
# Each redirect hop should record the URL it was associated with
2626
redirect_urls = [r["redirect_url"] for r in results]
2727
assert all(url is not None for url in redirect_urls)
28+
29+
30+
def test_dns_captured_on_connection_abort(default_params, task_manager_creator):
31+
"""Regression test: DNS data must be captured even when the connection
32+
aborts before completion. This verifies that the extension uses
33+
onHeadersReceived (not onCompleted) to record DNS responses."""
34+
manager_params, browser_params = default_params
35+
for browser_param in browser_params:
36+
browser_param.dns_instrument = True
37+
38+
manager, db = task_manager_creator((manager_params, browser_params))
39+
manager.get("http://localhost:8000/CONNECTION_ABORT/")
40+
manager.close()
41+
42+
results = db_utils.query_db(db, "SELECT * FROM dns_responses")
43+
assert len(results) > 0, "No DNS responses captured for aborted connection"
44+
result = results[0]
45+
assert isinstance(result, Row)
46+
assert result["used_address"] is not None
47+
assert result["addresses"] is not None
48+
assert result["hostname"] == "localhost"

test/utilities.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ def do_GET(self, *args, **kwargs):
8383
self.end_headers()
8484
return
8585

86+
# 2. Abort connection after sending partial response.
87+
if self.path.startswith("/CONNECTION_ABORT/"):
88+
self.send_response(200)
89+
self.send_header("Content-Length", "99999")
90+
self.end_headers()
91+
self.wfile.write(b"partial")
92+
self.wfile.close()
93+
return
94+
8695
# Otherwise, return file from disk
8796
return SimpleHTTPRequestHandler.do_GET(self, *args, **kwargs)
8897

0 commit comments

Comments
 (0)