Non-inference path on `inference.local` is denied with 403.
(
sandbox: Callable[..., Sandbox],
managed_openai_route: str,
)
| 237 | |
| 238 | |
| 239 | def 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 | |
| 271 | def test_unsupported_protocol_returns_400( |
nothing calls this directly
no test coverage detected