MP-3: Old-style single port field still works.
(
sandbox: Callable[..., Sandbox],
)
| 1809 | |
| 1810 | |
| 1811 | def 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 | # ============================================================================= |
nothing calls this directly
no test coverage detected