Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(fleet): drive the tenant-isolation test against a local mock core

M3gA-Mindd91d335ab75d
diff --git a/crates/openhuman-cli/src/bin/fleet_tests.rs b/crates/openhuman-cli/src/bin/fleet_tests.rs
index 66b9ed0682..0089f6b0ea 100644
--- a/crates/openhuman-cli/src/bin/fleet_tests.rs
+++ b/crates/openhuman-cli/src/bin/fleet_tests.rs
@@ -228,15 +228,39 @@ fn fleet_cors_headers_echo_allowed_origin_only() {
.is_none());
}
-/// Tenant isolation at the edge: alice's token on `/bob/rpc` is refused before
-/// anything is dialed. The tenants' cores sit on an unbound port, so a request
-/// that reached the upstream would come back as a gateway failure instead.
+/// Tenant isolation at the edge: alice's token on `/bob/rpc` is refused and
+/// never reaches bob's core, while bob's own token is forwarded to it with bob's
+/// core bearer. Bob's core is a local mock bound to the port the fleet assigns
+/// him, so the test needs no outside network and owns every port it dials.
#[tokio::test]
async fn rpc_proxy_refuses_one_tenants_token_on_another_tenants_core() {
- let root = PathBuf::from("/tmp/ws");
- let users = vec!["alice".to_string(), "bob".to_string()];
- // Port 1 is privileged and unbound: dialing it fails.
- let (instances, edge_auth, minted) = provision(&users, &root, 1).unwrap();
+ use std::sync::Mutex;
+ let seen: Arc<Mutex<Vec<Option<String>>>> = Arc::default();
+ let seen_by_upstream = seen.clone();
+ let upstream = axum::Router::new().route(
+ "/rpc",
+ post(move |headers: HeaderMap| {
+ let seen = seen_by_upstream.clone();
+ async move {
+ seen.lock().unwrap().push(
+ headers
+ .get(header::AUTHORIZATION)
+ .and_then(|value| value.to_str().ok())
+ .map(str::to_owned),
+ );
+ (StatusCode::OK, r#"{"jsonrpc":"2.0","id":1,"result":"bob"}"#)
+ }
+ }),
+ );
+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
+ let bob_port = listener.local_addr().unwrap().port();
+ tokio::spawn(async move { axum::serve(listener, upstream).await.unwrap() });
+
+ // Bob is provisioned first, so his core gets the mock's port.
+ let users = vec!["bob".to_string(), "alice".to_string()];
+ let (instances, edge_auth, minted) =
+ provision(&users, &PathBuf::from("/tmp/ws"), bob_port).unwrap();
+ let bob_core_bearer = instances["bob"].core_bearer.as_str().to_owned();
let token = |user: &str| {
minted
.iter()
@@ -270,8 +294,18 @@ async fn rpc_proxy_refuses_one_tenants_token_on_another_tenants_core() {
StatusCode::FORBIDDEN
);
assert_eq!(call(None, "bob").await.status(), StatusCode::UNAUTHORIZED);
- // Bob's own token passes the edge and reaches the (dead) upstream.
- let own = call(Some(token("bob")), "bob").await.status();
- assert_ne!(own, StatusCode::FORBIDDEN);
- assert_ne!(own, StatusCode::UNAUTHORIZED);
+ assert!(
+ seen.lock().unwrap().is_empty(),
+ "a refused request must never reach bob's core"
+ );
+
+ assert_eq!(
+ call(Some(token("bob")), "bob").await.status(),
+ StatusCode::OK
+ );
+ assert_eq!(
+ *seen.lock().unwrap(),
+ vec![Some(format!("Bearer {bob_core_bearer}"))],
+ "bob's request reaches his core with his core bearer, not the edge token"
+ );
}