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

Function localhost_bypass_script

e2e/rust/tests/no_proxy.rs:8–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6use openshell_e2e::harness::sandbox::SandboxGuard;
7
8fn localhost_bypass_script() -> &'static str {
9 r#"
10import json
11import os
12import threading
13import urllib.request
14from http.server import BaseHTTPRequestHandler, HTTPServer
15
16expected_no_proxy = '127.0.0.1,localhost,::1'
17assert os.environ['HTTP_PROXY'].startswith('http://')
18assert os.environ['HTTPS_PROXY'].startswith('http://')
19assert os.environ['NO_PROXY'] == expected_no_proxy
20assert os.environ['no_proxy'] == expected_no_proxy
21
22class Handler(BaseHTTPRequestHandler):
23 def log_message(self, format, *args):
24 pass
25
26 def do_GET(self):
27 self.send_response(200)
28 self.send_header('Content-Type', 'application/json')
29 self.end_headers()
30 self.wfile.write(b'{"message":"hello"}')
31
32server = HTTPServer(('127.0.0.1', 0), Handler)
33thread = threading.Thread(target=server.serve_forever, daemon=True)
34thread.start()
35
36try:
37 with urllib.request.urlopen(f'http://127.0.0.1:{server.server_port}', timeout=10) as response:
38 print(json.dumps({
39 'no_proxy': os.environ['NO_PROXY'],
40 'payload': json.loads(response.read().decode()),
41 }), flush=True)
42finally:
43 server.shutdown()
44 thread.join(timeout=5)
45 server.server_close()
46"#
47}
48
49#[tokio::test]
50async fn sandbox_bypasses_proxy_for_localhost_http() {

Calls

no outgoing calls

Tested by

no test coverage detected