MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / test_forward_proxy_log_fields

Function test_forward_proxy_log_fields

e2e/python/test_sandbox_policy.py:1563–1606  ·  view source on GitHub ↗

FWD-6: Forward proxy requests produce structured FORWARD log lines.

(
    sandbox: Callable[..., Sandbox],
)

Source from the content-addressed store, hash-verified

1561
1562
1563def test_forward_proxy_log_fields(
1564 sandbox: Callable[..., Sandbox],
1565) -> None:
1566 """FWD-6: Forward proxy requests produce structured FORWARD log lines."""
1567 policy = _base_policy(
1568 network_policies={
1569 "internal_http": sandbox_pb2.NetworkPolicyRule(
1570 name="internal_http",
1571 endpoints=[
1572 sandbox_pb2.NetworkEndpoint(
1573 host=_SANDBOX_IP,
1574 port=_FORWARD_PROXY_PORT,
1575 allowed_ips=["10.200.0.0/24"],
1576 ),
1577 ],
1578 binaries=[sandbox_pb2.NetworkBinary(path="/**")],
1579 ),
1580 },
1581 )
1582 spec = datamodel_pb2.SandboxSpec(policy=policy)
1583 with sandbox(spec=spec, delete_on_exit=True) as sb:
1584 # Trigger an allowed forward proxy request (with server)
1585 sb.exec_python(
1586 _forward_proxy_with_server(),
1587 args=(_PROXY_HOST, _PROXY_PORT, _SANDBOX_IP, _FORWARD_PROXY_PORT),
1588 )
1589 # Trigger a denied forward proxy request (no allowed_ips match)
1590 sb.exec_python(
1591 _forward_proxy_raw(),
1592 args=(
1593 _PROXY_HOST,
1594 _PROXY_PORT,
1595 "http://example.com/",
1596 ),
1597 )
1598 # Read the log
1599 result = sb.exec_python(_read_openshell_log())
1600 assert result.exit_code == 0, result.stderr
1601 log = result.stdout
1602
1603 # OCSF shorthand: FORWARD requests show as HTTP:method events
1604 assert "HTTP:" in log, "Expected OCSF HTTP activity event for FORWARD request"
1605 assert "ALLOWED" in log, "Expected ALLOWED for forward proxy allow"
1606 assert f"{_SANDBOX_IP}" in log, "Expected destination IP in FORWARD log"
1607
1608
1609# =============================================================================

Callers

nothing calls this directly

Calls 6

_base_policyFunction · 0.85
_forward_proxy_rawFunction · 0.85
_read_openshell_logFunction · 0.85
sandboxFunction · 0.70
exec_pythonMethod · 0.45

Tested by

no test coverage detected