L4-7: CONNECT log contains structured fields for allow and deny.
(
sandbox: Callable[..., Sandbox],
)
| 602 | |
| 603 | |
| 604 | def test_l4_log_fields( |
| 605 | sandbox: Callable[..., Sandbox], |
| 606 | ) -> None: |
| 607 | """L4-7: CONNECT log contains structured fields for allow and deny.""" |
| 608 | policy = _base_policy( |
| 609 | network_policies={ |
| 610 | "anthropic": sandbox_pb2.NetworkPolicyRule( |
| 611 | name="anthropic", |
| 612 | endpoints=[ |
| 613 | sandbox_pb2.NetworkEndpoint(host="api.anthropic.com", port=443), |
| 614 | ], |
| 615 | binaries=[sandbox_pb2.NetworkBinary(path="/**")], |
| 616 | ), |
| 617 | }, |
| 618 | ) |
| 619 | spec = datamodel_pb2.SandboxSpec(policy=policy) |
| 620 | with sandbox(spec=spec, delete_on_exit=True) as sb: |
| 621 | # Generate an allow |
| 622 | sb.exec_python(_proxy_connect(), args=("api.anthropic.com", 443)) |
| 623 | # Generate a deny |
| 624 | sb.exec_python(_proxy_connect(), args=("example.com", 443)) |
| 625 | |
| 626 | log_result = sb.exec_python(_read_openshell_log()) |
| 627 | assert log_result.exit_code == 0, log_result.stderr |
| 628 | log = log_result.stdout |
| 629 | |
| 630 | # Verify OCSF shorthand fields in allow line |
| 631 | assert "ALLOWED" in log, "Expected ALLOWED in OCSF shorthand" |
| 632 | assert "api.anthropic.com" in log, "Expected destination host in log" |
| 633 | assert "engine:opa" in log, "Expected engine:opa in log context" |
| 634 | |
| 635 | # Verify deny line exists |
| 636 | assert "DENIED" in log, "Expected DENIED in OCSF shorthand" |
| 637 | |
| 638 | |
| 639 | # ============================================================================= |
nothing calls this directly
no test coverage detected