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

Function test_l4_non_connect_method_rejected

e2e/python/test_sandbox_policy.py:569–601  ·  view source on GitHub ↗

L4-6: Non-CONNECT HTTP method -> rejected with 403.

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

Source from the content-addressed store, hash-verified

567
568
569def test_l4_non_connect_method_rejected(
570 sandbox: Callable[..., Sandbox],
571) -> None:
572 """L4-6: Non-CONNECT HTTP method -> rejected with 403."""
573
574 def send_get_to_proxy() -> str:
575 import socket
576
577 conn = socket.create_connection(("10.200.0.1", 3128), timeout=10)
578 try:
579 conn.sendall(
580 b"GET http://example.com/ HTTP/1.1\r\nHost: example.com\r\n\r\n"
581 )
582 return conn.recv(256).decode("latin1")
583 finally:
584 conn.close()
585
586 policy = _base_policy(
587 network_policies={
588 "any": sandbox_pb2.NetworkPolicyRule(
589 name="any",
590 endpoints=[
591 sandbox_pb2.NetworkEndpoint(host="example.com", port=443),
592 ],
593 binaries=[sandbox_pb2.NetworkBinary(path="/**")],
594 ),
595 },
596 )
597 spec = datamodel_pb2.SandboxSpec(policy=policy)
598 with sandbox(spec=spec, delete_on_exit=True) as sb:
599 result = sb.exec_python(send_get_to_proxy)
600 assert result.exit_code == 0, result.stderr
601 assert "403" in result.stdout
602
603
604def test_l4_log_fields(

Callers

nothing calls this directly

Calls 3

_base_policyFunction · 0.85
sandboxFunction · 0.70
exec_pythonMethod · 0.45

Tested by

no test coverage detected