|
7 | 7 | //! The servers run on the test host. The sandbox can't learn the host's |
8 | 8 | //! address, since policy DNS answers it with a synthetic one, so the test |
9 | 9 | //! reaches a server by `host.openshell.internal` first and takes the address |
10 | | -//! the server saw the request arrive at. Not conformance, because |
| 10 | +//! the server saw the request arrive at. A supervisor on the host network |
| 11 | +//! (Docker's and Podman's default) arrives on loopback, which an IP literal |
| 12 | +//! can't reach, so the test uses the host's outbound address instead; that |
| 13 | +//! supervisor shares it. Not conformance, because |
11 | 14 | //! that address must be one the supervisor lets an IP literal reach: rootless |
12 | 15 | //! Podman's is link-local, which is always blocked. |
13 | 16 | //! |
14 | 17 | //! Ported from the `proxy_egress_pipeline` e2e test of IP literals, which |
15 | 18 | //! used two support containers on the e2e network instead. |
16 | 19 |
|
| 20 | +use std::net::{IpAddr, Ipv4Addr, UdpSocket}; |
| 21 | + |
17 | 22 | use host_server_support::{HttpRecorder, TEST_HOST}; |
18 | 23 | use sandbox_clients_support::{Request, http}; |
19 | 24 | use testkit::policy; |
@@ -52,17 +57,17 @@ async fn ip_literal_endpoints_reach_the_host(cx: &mut Context) -> testkit::Resul |
52 | 57 | "request to {TEST_HOST}:{} failed: {reply:?}", |
53 | 58 | explicit.port |
54 | 59 | ); |
55 | | - let host_ip = explicit |
| 60 | + let arrived_on = explicit |
56 | 61 | .requests() |
57 | 62 | .first() |
58 | 63 | .and_then(|request| request.local_addr) |
59 | 64 | .ok_or_else(|| testkit::Error::msg("the host server didn't record its address"))? |
60 | 65 | .ip(); |
61 | | - // Docker Desktop relays the host gateway through a host-side proxy. |
62 | | - testkit::ensure!( |
63 | | - !host_ip.is_loopback(), |
64 | | - "requests to {TEST_HOST} arrive at the host on {host_ip}, which a sandbox can't reach" |
65 | | - ); |
| 66 | + let host_ip = if arrived_on.is_loopback() { |
| 67 | + outbound_address()? |
| 68 | + } else { |
| 69 | + arrived_on |
| 70 | + }; |
66 | 71 | let ip = host_ip.to_string(); |
67 | 72 | let prefix = if host_ip.is_ipv4() { 32 } else { 128 }; |
68 | 73 |
|
@@ -96,3 +101,16 @@ async fn ip_literal_endpoints_reach_the_host(cx: &mut Context) -> testkit::Resul |
96 | 101 | } |
97 | 102 | Ok(()) |
98 | 103 | } |
| 104 | + |
| 105 | +/// The test host's address on its default route. Connecting a UDP socket |
| 106 | +/// sends nothing; it only picks the route. |
| 107 | +fn outbound_address() -> testkit::Result<IpAddr> { |
| 108 | + let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0))?; |
| 109 | + socket.connect((Ipv4Addr::new(192, 0, 2, 1), 9))?; |
| 110 | + let address = socket.local_addr()?.ip(); |
| 111 | + testkit::ensure!( |
| 112 | + !address.is_loopback() && !address.is_unspecified(), |
| 113 | + "the test host has no outbound address, only {address}" |
| 114 | + ); |
| 115 | + Ok(address) |
| 116 | +} |
0 commit comments