Secure, Fast, and Extensible Sandbox runtime for AI agents.
test(egress): close remaining reply-before-read races in resolver stub and smoke nft checks
高然ec18af5b52da
diff --git a/components/egress/tests/resolver/resolver.py b/components/egress/tests/resolver/resolver.pyindex 689e4ac6f..73cff6f5a 100644--- a/components/egress/tests/resolver/resolver.py+++ b/components/egress/tests/resolver/resolver.py@@ -259,15 +259,13 @@ class _Handler(http.server.BaseHTTPRequestHandler):return Falsedef _json_body(self) -> dict[str, Any]:+ # Consume the body per its declared length before rejecting the+ # request: replying and closing with the body unread races the+ # client's send on Unix sockets (immediate EPIPE).if self.headers.get_all("Transfer-Encoding", []):raise _BadRequest- types = self.headers.get_all("Content-Type", [])lengths = self.headers.get_all("Content-Length", [])- if (- types != ["application/json"]- or len(lengths) != 1- or not lengths[0].isdigit()- ):+ if len(lengths) != 1 or not lengths[0].isdigit():raise _BadRequestlength = int(lengths[0])if length > MAX_REQUEST_BYTES:@@ -276,6 +274,8 @@ class _Handler(http.server.BaseHTTPRequestHandler):raw = self.rfile.read(length)if len(raw) != length:raise _BadRequest+ if self.headers.get_all("Content-Type", []) != ["application/json"]:+ raise _BadRequesttry:value = json.loads(raw,diff --git a/components/egress/tests/smoke-fast-sandbox.sh b/components/egress/tests/smoke-fast-sandbox.shindex 5dfca3bed..c34e70456 100755--- a/components/egress/tests/smoke-fast-sandbox.sh+++ b/components/egress/tests/smoke-fast-sandbox.sh@@ -405,8 +405,8 @@ pass "DoH-443 blocking installed (doh_block_v4 set + element + drop rule)"info "Test 1: SET_BINDING registers deny-first (fail closed before any policy)"set_binding a 10.10.0.5 1 runtime-a att-a '{"defaultAction":"deny"}'wait_for 15 "subject a deny-first installed" nft_has 'subj_s_a'-nft_has 'ip saddr 10.10.0.5 jump subj_s_a' || fail "dispatch rule missing"-nft_has 'subj_s_a_allow_v4 {' || fail "subject a static sets missing"+wait_for 10 "subject a dispatch rule" nft_has 'ip saddr 10.10.0.5 jump subj_s_a'+wait_for 10 "subject a static sets" nft_has 'subj_s_a_allow_v4 {'expect_rcode osb-sandbox-a allow.test 3pass "deny-first registered (nft + NXDOMAIN, policy pending)"@@ -423,7 +423,7 @@ expect_answers osb-sandbox-a other.test 1.1.1.2expect_rcode osb-sandbox-a nope.test 3pass "DNS per-subject policy (allow *.test, deny others)"-nft_has '10.99.0.2' || fail "static allow element missing from nft"+wait_for 10 "static allow element" nft_has '10.99.0.2'wait_for 10 "dns-learned dynamic allow" nft_has '1.1.1.1'pass "nft static allow + DNS-learned dynamic lease"