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

Function test_single_port_backwards_compat

e2e/python/test_sandbox_policy.py:1811–1836  ·  view source on GitHub ↗

MP-3: Old-style single port field still works.

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

Source from the content-addressed store, hash-verified

1809
1810
1811def test_single_port_backwards_compat(
1812 sandbox: Callable[..., Sandbox],
1813) -> None:
1814 """MP-3: Old-style single port field still works."""
1815 policy = _base_policy(
1816 network_policies={
1817 "compat": sandbox_pb2.NetworkPolicyRule(
1818 name="compat",
1819 endpoints=[
1820 sandbox_pb2.NetworkEndpoint(host="api.anthropic.com", port=443),
1821 ],
1822 binaries=[sandbox_pb2.NetworkBinary(path="/**")],
1823 ),
1824 },
1825 )
1826 spec = datamodel_pb2.SandboxSpec(policy=policy)
1827 with sandbox(spec=spec, delete_on_exit=True) as sb:
1828 # Port 443 -> allowed
1829 result = sb.exec_python(_proxy_connect(), args=("api.anthropic.com", 443))
1830 assert result.exit_code == 0, result.stderr
1831 assert "200" in result.stdout, f"Single port should still work: {result.stdout}"
1832
1833 # Port 80 -> denied
1834 result = sb.exec_python(_proxy_connect(), args=("api.anthropic.com", 80))
1835 assert result.exit_code == 0, result.stderr
1836 assert "403" in result.stdout
1837
1838
1839# =============================================================================

Callers

nothing calls this directly

Calls 4

_base_policyFunction · 0.85
_proxy_connectFunction · 0.85
sandboxFunction · 0.70
exec_pythonMethod · 0.45

Tested by

no test coverage detected