diff --git a/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs index 2a6d9d219..f6283f00f 100644 --- a/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs +++ b/crates/tinycomputer-browser/src/linked/linked_tests/live_tests.rs @@ -69,7 +69,7 @@ async fn live_chromium_loopback_navigation_uses_the_authenticated_session_proxy( #[tokio::test] #[cfg(live_browser_tests)] async fn live_chromium_dials_only_the_exact_host_authorized_socket() { - let allowed = TcpListener::bind("127.0.0.2:0").await.unwrap(); + let allowed = TcpListener::bind("[::1]:0").await.unwrap(); let allowed_address = allowed.local_addr().unwrap(); let denied = std::net::TcpListener::bind(("127.0.0.1", allowed_address.port())).unwrap(); denied.set_nonblocking(true).unwrap(); @@ -630,19 +630,25 @@ impl EgressAuthorizer for RebindingAuthorizer { &self, target: BrowserDialTarget, ) -> std::pin::Pin> + Send>> { - let attempt = self.authorizations.fetch_add(1, Ordering::SeqCst); + let controlled_target = + target.hostname == "fixture.test" && target.port == self.allowed_address.port(); + let attempt = if controlled_target { + self.authorizations.fetch_add(1, Ordering::SeqCst) + } else { + usize::MAX + }; let resolved_address = if attempt == 0 { self.allowed_address } else { self.private_address }; - self.observed_addresses - .lock() - .unwrap() - .push(resolved_address); - let allowed = attempt == 0 - && target.hostname == "fixture.test" - && target.port == self.allowed_address.port(); + if controlled_target { + self.observed_addresses + .lock() + .unwrap() + .push(resolved_address); + } + let allowed = controlled_target && attempt == 0; if !allowed { self.denied_targets .lock() diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs index 7be104ba9..683c8db77 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/mod.rs @@ -285,9 +285,11 @@ async fn start_browser_with_fixture_hosts_for_policy( #[tokio::test] async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_changed_policy() -> tinybus::Result<()> { - let allowed_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; + // Use the two loopback families to model distinct sockets on the same + // port. Unlike 127.0.0.2, ::1 is assigned consistently across platforms. + let allowed_listener = tokio::net::TcpListener::bind("[::1]:0").await?; let port = allowed_listener.local_addr()?.port(); - let denied_listener = tokio::net::TcpListener::bind(("127.0.0.2", port)).await?; + let denied_listener = tokio::net::TcpListener::bind(("127.0.0.1", port)).await?; let allowed_address = allowed_listener.local_addr()?.to_string(); let extra_allowed_connections = Arc::new(AtomicUsize::new(0)); let (served_tx, served_rx) = tokio::sync::oneshot::channel(); diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/worker.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/worker.rs index 4d77c63e1..2d2779a0d 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/worker.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests/worker.rs @@ -5,12 +5,14 @@ async fn live_chromium_module_routes_worker_egress_through_host_authorization() -> tinybus::Result<()> { let allowed_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; let page_port = allowed_listener.local_addr()?.port(); - let denied_listener = tokio::net::TcpListener::bind("127.0.0.2:0").await?; + // A different port on assigned loopback keeps this denied socket local + // without relying on an unconfigured 127.0.0.2 alias. + let denied_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; let denied_port = denied_listener.local_addr()?.port(); let html = format!( "" ) .into_bytes(); @@ -30,7 +32,7 @@ async fn live_chromium_module_routes_worker_egress_through_host_authorization() start_browser_with_fixture_host(allowed_address, page_port, "/worker-fixture", served_rx) .await?; - let worker_authorization = format!("authorize:fixture-policy:41:127.0.0.2:{denied_port}"); + let worker_authorization = format!("authorize:fixture-policy:41:127.0.0.1:{denied_port}"); let worker_authorized = tokio::time::timeout(Duration::from_secs(10), async { loop { if browser