From 2f42183e9ef1d20606633422b8634b03c0b97985 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 02:46:35 +0000 Subject: [PATCH 1/4] test(browser): cover loopback denial when egress authority is missing Add a live test that navigates to a loopback address while the module is configured with an egress policy id that has no authority, asserting the navigation is rejected and the destination never receives a connection. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../browser_egress_live_tests.rs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs index b61c63cfa..91028bb35 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs @@ -270,3 +270,56 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch broker_task.abort(); Ok(()) } + +#[tokio::test] +async fn live_chromium_module_denies_loopback_when_egress_authority_is_missing() +-> tinybus::Result<()> { + let denied_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; + let port = denied_listener.local_addr()?.port(); + + let bus = MemoryBus::new(); + let broker = Broker::new(); + let broker_task = broker.spawn(bus.clone()); + let module_host = ModuleHost::new(broker); + let module = crate::linked_module().expect("linked module manifest is valid"); + module_host + .attach_linked_with_config( + module, + serde_json::json!({ + "browser": {"egress": {"policy_id": "missing-authority", "generation": 7}} + }), + ) + .expect("TinyComputer module loads through ModuleHost"); + let client = Connection::connect(bus.connect().await?).await?; + let proxy = client.proxy(names::INTERFACE, names::OBJECT_PATH, names::INTERFACE)?; + + let opened: DesktopResponse = proxy + .call( + browser_names::methods::OPEN_SESSION, + (serde_json::json!({}),), + ) + .await?; + let session = successful_data(&opened)["id"].clone(); + let url = format!("http://127.0.0.1:{port}/must-not-connect"); + let denied: DesktopResponse = proxy + .call( + browser_names::methods::NAVIGATE, + (serde_json::json!({"session": session, "url": url}),), + ) + .await?; + + assert!( + !denied.ok, + "navigation without an egress authority unexpectedly succeeded" + ); + assert!( + tokio::time::timeout(Duration::from_millis(500), denied_listener.accept()) + .await + .is_err(), + "loopback destination received a connection without an egress authority" + ); + + broker_task.abort(); + let _ = broker_task.await; + Ok(()) +} From 14a402db0f480011f4171547838c3041573d0251 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 02:47:32 +0000 Subject: [PATCH 2/4] test(browser_egress): cover stale egress generation denial Add a live Chromium test that navigates with a generation the host does not match, asserting the request is denied before any socket is dialed. The fixture host now accepts an optional grant generation so it can return a stale value, letting the test confirm the module asks for authorization but never reaches socket consumption. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../browser_egress_live_tests.rs | 88 ++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs index 91028bb35..7c736f988 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs @@ -22,6 +22,7 @@ use tinycomputer_bus::{ struct EgressHost { allowed: Arc, allowed_address: String, + grant_generation: Option, resolved_address: Arc>, observations: Arc>>, } @@ -50,7 +51,7 @@ impl EgressHost { self.resolved_address.lock().unwrap() )); Ok(BrowserEgressGrant { - generation: request.expected_generation, + generation: self.grant_generation.unwrap_or(request.expected_generation), authorization: if allow { "fixture-lease" } else { @@ -154,6 +155,7 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch EgressHost { allowed: allowed.clone(), allowed_address: allowed_address.clone(), + grant_generation: None, resolved_address: resolved_address.clone(), observations: observations.clone(), }, @@ -323,3 +325,87 @@ async fn live_chromium_module_denies_loopback_when_egress_authority_is_missing() let _ = broker_task.await; Ok(()) } + +#[tokio::test] +async fn live_chromium_module_denies_a_stale_egress_generation_before_dialing() +-> tinybus::Result<()> { + let denied_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; + let allowed_address = denied_listener.local_addr()?.to_string(); + let port = denied_listener.local_addr()?.port(); + + let bus = MemoryBus::new(); + let broker = Broker::new(); + let broker_task = broker.spawn(bus.clone()); + let host_connection = Connection::connect(bus.connect().await?).await?; + let observations = Arc::new(Mutex::new(Vec::new())); + host_connection + .serve_at( + browser_egress::OBJECT_PATH.try_into()?, + EgressHost { + allowed: Arc::new(AtomicBool::new(true)), + allowed_address: allowed_address.clone(), + grant_generation: Some(40), + resolved_address: Arc::new(Mutex::new(allowed_address.clone())), + observations: observations.clone(), + }, + ) + .await?; + host_connection + .request_name(browser_egress::INTERFACE) + .await?; + + let module_host = ModuleHost::new(broker); + let module = crate::linked_module().expect("linked module manifest is valid"); + module_host + .attach_linked_with_config( + module, + serde_json::json!({ + "browser": {"egress": {"policy_id": "stale-generation", "generation": 41}} + }), + ) + .expect("TinyComputer module loads through ModuleHost"); + let client = Connection::connect(bus.connect().await?).await?; + let proxy = client.proxy(names::INTERFACE, names::OBJECT_PATH, names::INTERFACE)?; + + let opened: DesktopResponse = proxy + .call( + browser_names::methods::OPEN_SESSION, + (serde_json::json!({}),), + ) + .await?; + let session = successful_data(&opened)["id"].clone(); + let url = format!("http://fixture.test:{port}/stale-generation"); + let denied: DesktopResponse = proxy + .call( + browser_names::methods::NAVIGATE, + (serde_json::json!({"session": session, "url": url}),), + ) + .await?; + + assert!( + !denied.ok, + "navigation with a stale egress generation unexpectedly succeeded" + ); + assert!( + tokio::time::timeout(Duration::from_millis(500), denied_listener.accept()) + .await + .is_err(), + "stale-generation socket received a connection" + ); + let calls = observations.lock().unwrap(); + assert!( + calls + .iter() + .any(|call| call.starts_with("authorize:stale-generation:41:fixture.test:")), + "the live module did not ask the host for an authorization: {calls:?}" + ); + assert!( + !calls.iter().any(|call| call.starts_with("consume:")), + "stale grant reached socket consumption: {calls:?}" + ); + drop(calls); + + broker_task.abort(); + let _ = broker_task.await; + Ok(()) +} From 2fdff68b1ac6d88e368a32771e9ef47ab11df33f Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 02:48:30 +0000 Subject: [PATCH 3/4] test(tinycomputer): yield in browser egress host handlers The live Chromium egress test's host handlers now yield to the runtime before touching shared state, so the broker can interleave calls the way it would in production. The doc comment was also updated to use code formatting for the module name, and the long test function is explicitly allowed to exceed the line-count lint. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../src/tinybus_module/browser_egress_live_tests.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs index 7c736f988..2400b85cc 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs @@ -1,4 +1,4 @@ -//! Opt-in real-Chromium coverage through the loaded TinyComputer module. +//! Opt-in real-Chromium coverage through the loaded `TinyComputer` module. #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] use std::sync::{ @@ -30,6 +30,7 @@ struct EgressHost { #[tinybus::interface(name = "ai.tinyhumans.tinycomputer.BrowserEgressHost")] impl EgressHost { async fn authorize(&self, request: BrowserEgressTarget) -> tinybus::Result { + tokio::task::yield_now().await; let allow = self.allowed.load(Ordering::SeqCst) && request.hostname == "fixture.test" && *self.resolved_address.lock().unwrap() == self.allowed_address @@ -70,6 +71,7 @@ impl EgressHost { &self, request: BrowserEgressConsumeRequest, ) -> tinybus::Result { + tokio::task::yield_now().await; self.observations .lock() .unwrap() @@ -83,6 +85,7 @@ impl EgressHost { &self, request: BrowserEgressValidateRequest, ) -> tinybus::Result { + tokio::task::yield_now().await; self.observations .lock() .unwrap() @@ -128,6 +131,7 @@ fn successful_data(reply: &DesktopResponse) -> &serde_json::Value { } #[tokio::test] +#[allow(clippy::too_many_lines)] 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?; @@ -267,6 +271,7 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch .any(|call| call == &format!("resolve:fixture.test:{port}:{rebound_address}")), "the controlled resolver did not provide the private rebound answer: {calls:?}" ); + drop(calls); allowed_server.abort(); let _ = allowed_server.await; broker_task.abort(); From a31d20a5844d7f3fc559501bda336d02155d8a70 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Fri, 23 Oct 2026 02:48:52 +0000 Subject: [PATCH 4/4] test(browser_egress): shut down servers before asserting on calls Move the abort and await of the allowed server and broker task ahead of the observation lock so the tasks are torn down before the assertions read the recorded calls. This avoids holding the mutex across the awaits and keeps the teardown ordering consistent between the two live tests. Auto-committed-on: cuttlefish Co-authored-by: Medulla --- .../tinybus_module/browser_egress_live_tests.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs index 2400b85cc..456bceeaf 100644 --- a/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/browser_egress_live_tests.rs @@ -243,6 +243,11 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch "denied rebound request reached the previously allowed socket" ); + allowed_server.abort(); + let _ = allowed_server.await; + broker_task.abort(); + let _ = broker_task.await; + let calls = observations.lock().unwrap(); assert!( calls @@ -271,10 +276,6 @@ async fn live_chromium_module_dials_only_the_host_returned_socket_and_rejects_ch .any(|call| call == &format!("resolve:fixture.test:{port}:{rebound_address}")), "the controlled resolver did not provide the private rebound answer: {calls:?}" ); - drop(calls); - allowed_server.abort(); - let _ = allowed_server.await; - broker_task.abort(); Ok(()) } @@ -397,6 +398,9 @@ async fn live_chromium_module_denies_a_stale_egress_generation_before_dialing() .is_err(), "stale-generation socket received a connection" ); + broker_task.abort(); + let _ = broker_task.await; + let calls = observations.lock().unwrap(); assert!( calls @@ -408,9 +412,5 @@ async fn live_chromium_module_denies_a_stale_egress_generation_before_dialing() !calls.iter().any(|call| call.starts_with("consume:")), "stale grant reached socket consumption: {calls:?}" ); - drop(calls); - - broker_task.abort(); - let _ = broker_task.await; Ok(()) }