Skip to content

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

Merge remote-tracking branch 'upstream/main' into saas-phase3

Steven Enamakela35bc08191a5
diff --cc tests/saas_mode_e2e.rs
index 62c4d2207d,d73cb5b96d..05eec16c3f
--- a/tests/saas_mode_e2e.rs
+++ b/tests/saas_mode_e2e.rs
@@@ -271,141 -271,13 +277,149 @@@ fn a_safe_deployment_serves_core_and_th
.exists(),
"a SaaS boot never activates a desktop user"
);
+ let desktop = d.tmp.path().join(".openhuman");
+ let leaked: Vec<_> = std::fs::read_dir(&desktop)
+ .map(|entries| entries.flatten().map(|e| e.file_name()).collect())
+ .unwrap_or_default();
+ assert!(
+ leaked.is_empty(),
+ "a SaaS boot writes nothing under ~/.openhuman (keyring included): {leaked:?}"
+ );
drop(server);
}
+
+fn now() -> u64 {
+ std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap()
+ .as_secs()
+}
+
+/// POST /rpc for gateway user `user`, signed unless `sig` overrides it.
+fn user_rpc(
+ client: &reqwest::blocking::Client,
+ base: &str,
+ bearer: &str,
+ user: &str,
+ sig: Option<&str>,
+ method: &str,
+) -> (u16, Value) {
+ use openhuman_core::user_agents::gateway::{sign, USER_HEADER, USER_SIG_HEADER};
+ let signature = sig
+ .map(str::to_owned)
+ .unwrap_or_else(|| sign(BEARER, user, now()));
+ let response = client
+ .post(format!("{base}/rpc"))
+ .bearer_auth(bearer)
+ .header(USER_HEADER, user)
+ .header(USER_SIG_HEADER, signature)
+ .json(&json!({ "jsonrpc": "2.0", "id": 1, "method": method, "params": {} }))
+ .send()
+ .expect("POST /rpc");
+ let status = response.status().as_u16();
+ (status, response.json().unwrap_or(Value::Null))
+}
+
+#[test]
+fn gateway_requests_run_under_the_named_users_agent() {
+ let d = deployment(true);
+ let (server, base, client) = start(&d);
+
+ // Provision alice and hand the core her credential; bob stays unknown.
+ let (_, body) = rpc_with(
+ &client,
+ &base,
+ Some(BEARER),
+ "openhuman.user_agents_provision",
+ json!({ "user_id": "alice" }),
+ );
+ let alice = openhuman_core::user_agents::UserAgentId::for_user("alice").unwrap();
+ assert!(body.to_string().contains(alice.as_str()), "{body}");
+ let (_, body) = rpc_with(
+ &client,
+ &base,
+ Some(BEARER),
+ "openhuman.user_agents_set_credential",
+ json!({ "agent_id": alice.as_str(), "kind": "session", "token": "alice-session-jwt" }),
+ );
+ assert!(body.get("result").is_some(), "{body}");
+ assert!(!body.to_string().contains("alice-session-jwt"), "{body}");
+ let (_, body) = rpc_with(
+ &client,
+ &base,
+ Some(BEARER),
+ "openhuman.user_agents_status",
+ json!({ "agent_id": alice.as_str() }),
+ );
+ assert!(
+ body.to_string().contains("\"has_credential\":true"),
+ "{body}"
+ );
+
+ // A signed request for alice runs under her agent.
+ let (status, body) = user_rpc(&client, &base, BEARER, "alice", None, "core.ping");
+ assert_eq!(status, 200, "{body}");
+ assert!(body.get("result").is_some(), "{body}");
+
+ // A user's scope cannot reach the operator plane.
+ let (_, body) = user_rpc(
+ &client,
+ &base,
+ BEARER,
+ "alice",
+ None,
+ "openhuman.user_agents_list",
+ );
+ assert!(
+ body.get("error").is_some(),
+ "operator methods are not a user's: {body}"
+ );
+
+ // Refusals: bad bearer first, then signatures, then provisioning.
+ let (status, body) = user_rpc(&client, &base, "wrong-bearer", "alice", None, "core.ping");
+ assert_eq!(status, 401, "{body}");
+ let (status, body) = user_rpc(&client, &base, "wrong-bearer", "bob", None, "core.ping");
+ assert_eq!(
+ status, 401,
+ "an unauthenticated caller cannot probe users: {body}"
+ );
+ let (status, body) = user_rpc(
+ &client,
+ &base,
+ BEARER,
+ "alice",
+ Some("t=1,v1=00"),
+ "core.ping",
+ );
+ assert_eq!(status, 401, "{body}");
+ let forged = openhuman_core::user_agents::gateway::sign(BEARER, "alice", now());
+ let (status, body) = user_rpc(&client, &base, BEARER, "bob", Some(&forged), "core.ping");
+ assert_eq!(status, 401, "alice's signature does not cover bob: {body}");
+ let (status, body) = user_rpc(&client, &base, BEARER, "bob", None, "core.ping");
+ assert_eq!(status, 403, "bob is not provisioned: {body}");
+
+ // Single-user surfaces are closed.
+ for path in ["/events", "/events/domain", "/v1/models", "/dev/connect"] {
+ let status = client
+ .get(format!("{base}{path}"))
+ .bearer_auth(BEARER)
+ .send()
+ .unwrap()
+ .status()
+ .as_u16();
+ assert_eq!(status, 404, "{path}");
+ }
+
+ // The credential lives in alice's own directory.
+ let agent_dir = d.root.join("agents").join(alice.as_str());
+ let stored: Vec<_> = std::fs::read_dir(&agent_dir)
+ .unwrap()
+ .flatten()
+ .map(|e| e.file_name().to_string_lossy().into_owned())
+ .collect();
+ assert!(
+ stored.iter().any(|name| name.contains("auth")),
+ "credential store beside alice's config: {stored:?}"
+ );
+ drop(server);
+}