L7-T6: L7 deny response is valid JSON with expected fields.
(
sandbox: Callable[..., Sandbox],
)
| 1123 | |
| 1124 | |
| 1125 | def test_l7_tls_deny_response_format( |
| 1126 | sandbox: Callable[..., Sandbox], |
| 1127 | ) -> None: |
| 1128 | """L7-T6: L7 deny response is valid JSON with expected fields.""" |
| 1129 | policy = _base_policy( |
| 1130 | network_policies={ |
| 1131 | "anthropic": sandbox_pb2.NetworkPolicyRule( |
| 1132 | name="anthropic", |
| 1133 | endpoints=[ |
| 1134 | sandbox_pb2.NetworkEndpoint( |
| 1135 | host="api.anthropic.com", |
| 1136 | port=443, |
| 1137 | protocol="rest", |
| 1138 | tls="terminate", |
| 1139 | enforcement="enforce", |
| 1140 | access="read-only", |
| 1141 | ), |
| 1142 | ], |
| 1143 | binaries=[sandbox_pb2.NetworkBinary(path="/**")], |
| 1144 | ), |
| 1145 | }, |
| 1146 | ) |
| 1147 | spec = datamodel_pb2.SandboxSpec(policy=policy) |
| 1148 | with sandbox(spec=spec, delete_on_exit=True) as sb: |
| 1149 | result = sb.exec_python( |
| 1150 | _proxy_connect_then_http(), |
| 1151 | args=("api.anthropic.com", 443, "DELETE", "/v1/anything"), |
| 1152 | ) |
| 1153 | assert result.exit_code == 0, result.stderr |
| 1154 | resp = json.loads(result.stdout) |
| 1155 | assert resp["http_status"] == 403 |
| 1156 | |
| 1157 | # Verify response headers |
| 1158 | assert "X-OpenShell-Policy" in resp["headers"] |
| 1159 | assert "application/json" in resp["headers"] |
| 1160 | |
| 1161 | # Verify JSON body structure |
| 1162 | body = json.loads(resp["body"]) |
| 1163 | assert body["error"] == "policy_denied" |
| 1164 | assert "policy" in body |
| 1165 | assert "rule" in body |
| 1166 | assert "detail" in body |
| 1167 | |
| 1168 | |
| 1169 | def test_l7_tls_log_fields( |
nothing calls this directly
no test coverage detected