Skip to content

Commit 1b67e4f

Browse files
committed
fix(e2e): update log assertions for OCSF shorthand format
The E2E tests asserted on the old tracing::fmt key=value format (action=allow, l7_decision=audit, FORWARD, L7_REQUEST, always-blocked). Update to match the new OCSF shorthand (ALLOWED/DENIED, HTTP:, NET:, engine:ssrf, policy:).
1 parent 1cc028c commit 1b67e4f

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

e2e/python/test_sandbox_policy.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,7 @@ def log_message(self, *args):
314314
{"connect_status": connect_resp.strip(), "http_status": 0}
315315
)
316316

317-
request = (
318-
f"{method} {path} HTTP/1.1\r\nHost: {target_host}\r\nConnection: close\r\n\r\n"
319-
)
317+
request = f"{method} {path} HTTP/1.1\r\nHost: {target_host}\r\nConnection: close\r\n\r\n"
320318
conn.sendall(request.encode())
321319

322320
data = b""
@@ -624,13 +622,13 @@ def test_l4_log_fields(
624622
assert log_result.exit_code == 0, log_result.stderr
625623
log = log_result.stdout
626624

627-
# Verify structured fields in allow line
628-
assert "action=allow" in log or 'action="allow"' in log or "action=allow" in log
629-
assert "dst_host=api.anthropic.com" in log or "dst_host" in log
630-
assert "engine=opa" in log or 'engine="opa"' in log
625+
# Verify OCSF shorthand fields in allow line
626+
assert "ALLOWED" in log, "Expected ALLOWED in OCSF shorthand"
627+
assert "api.anthropic.com" in log, "Expected destination host in log"
628+
assert "engine:opa" in log, "Expected engine:opa in log context"
631629

632630
# Verify deny line exists
633-
assert "action=deny" in log or 'action="deny"' in log
631+
assert "DENIED" in log, "Expected DENIED in OCSF shorthand"
634632

635633

636634
# =============================================================================
@@ -717,8 +715,9 @@ def test_ssrf_log_shows_blocked_address(
717715
log_result = sb.exec_python(_read_openshell_log())
718716
assert log_result.exit_code == 0, log_result.stderr
719717
log = log_result.stdout
720-
assert "always-blocked" in log.lower(), (
721-
f"Expected 'always-blocked' in proxy log, got:\n{log}"
718+
# OCSF shorthand uses "engine:ssrf" for SSRF blocks
719+
assert "engine:ssrf" in log.lower() or "ssrf" in log.lower(), (
720+
f"Expected SSRF block indicator in proxy log, got:\n{log}"
722721
)
723722

724723

@@ -1003,7 +1002,9 @@ def test_l7_tls_audit_mode_allows_but_logs(
10031002
log_result = sb.exec_python(_read_openshell_log())
10041003
assert log_result.exit_code == 0, log_result.stderr
10051004
log = log_result.stdout
1006-
assert "l7_decision=audit" in log or 'l7_decision="audit"' in log
1005+
# OCSF shorthand: audit decisions show as ALLOWED (audit mode allows through)
1006+
assert "HTTP:" in log, "Expected OCSF HTTP activity event in log"
1007+
assert "ALLOWED" in log, "Expected ALLOWED for audit-mode decision"
10071008

10081009

10091010
def test_l7_tls_explicit_path_rules(
@@ -1181,11 +1182,10 @@ def test_l7_tls_log_fields(
11811182
assert log_result.exit_code == 0, log_result.stderr
11821183
log = log_result.stdout
11831184

1184-
assert "L7_REQUEST" in log
1185-
assert "l7_protocol" in log
1186-
assert "l7_action" in log
1187-
assert "l7_target" in log
1188-
assert "l7_decision" in log
1185+
# OCSF shorthand: L7 requests show as HTTP:method events
1186+
assert "HTTP:" in log, "Expected OCSF HTTP activity event in log"
1187+
assert "ALLOWED" in log or "DENIED" in log, "Expected L7 decision in log"
1188+
assert "policy:" in log, "Expected policy context in log"
11891189

11901190

11911191
def test_l7_query_matchers_enforced(
@@ -1839,13 +1839,10 @@ def test_forward_proxy_log_fields(
18391839
assert result.exit_code == 0, result.stderr
18401840
log = result.stdout
18411841

1842-
assert "FORWARD" in log, "Expected FORWARD log lines"
1843-
# tracing key-value pairs quote string values: action="allow"
1844-
assert 'action="allow"' in log, "Expected allowed FORWARD in logs"
1845-
assert f"dst_host={_SANDBOX_IP}" in log, "Expected dst_host in FORWARD log"
1846-
assert f"dst_port={_FORWARD_PROXY_PORT}" in log, (
1847-
"Expected dst_port in FORWARD log"
1848-
)
1842+
# OCSF shorthand: FORWARD requests show as HTTP:method events
1843+
assert "HTTP:" in log, "Expected OCSF HTTP activity event for FORWARD request"
1844+
assert "ALLOWED" in log, "Expected ALLOWED for forward proxy allow"
1845+
assert f"{_SANDBOX_IP}" in log, "Expected destination IP in FORWARD log"
18491846

18501847

18511848
# =============================================================================

0 commit comments

Comments
 (0)