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

Function test_non_inference_request_denied

e2e/python/test_inference_routing.py:239–268  ·  view source on GitHub ↗

Non-inference path on `inference.local` is denied with 403.

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

Source from the content-addressed store, hash-verified

237
238
239def test_non_inference_request_denied(
240 sandbox: Callable[..., Sandbox],
241 managed_openai_route: str,
242) -> None:
243 """Non-inference path on `inference.local` is denied with 403."""
244 _ = managed_openai_route
245 spec = datamodel_pb2.SandboxSpec(policy=_baseline_policy())
246
247 def make_non_inference_request() -> str:
248 import ssl
249 import urllib.error
250 import urllib.request
251
252 ctx = ssl.create_default_context()
253 ctx.check_hostname = False
254 ctx.verify_mode = ssl.CERT_NONE
255
256 try:
257 req = urllib.request.Request("https://inference.local/v1/not-inference")
258 urllib.request.urlopen(req, timeout=10, context=ctx)
259 return "unexpected_success"
260 except urllib.error.HTTPError as e:
261 return f"http_error_{e.code}"
262 except Exception as e:
263 return f"error: {e}"
264
265 with sandbox(spec=spec, delete_on_exit=True) as sb:
266 result = sb.exec_python(make_non_inference_request, timeout_seconds=30)
267 assert result.exit_code == 0, f"stderr: {result.stderr}"
268 assert result.stdout.strip() == "http_error_403"
269
270
271def test_unsupported_protocol_returns_400(

Callers

nothing calls this directly

Calls 3

_baseline_policyFunction · 0.85
sandboxFunction · 0.70
exec_pythonMethod · 0.45

Tested by

no test coverage detected