Skip to content

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

test(runtime): cover token, sandbox and saas mode edge cases

Steven Enamakel4b72a0d7054c
diff --git a/crates/openhuman-core/src/core/runtime/boot_guard_tests.rs b/crates/openhuman-core/src/core/runtime/boot_guard_tests.rs
index 1b6d1fa4e1..e443394372 100644
--- a/crates/openhuman-core/src/core/runtime/boot_guard_tests.rs
+++ b/crates/openhuman-core/src/core/runtime/boot_guard_tests.rs
@@ -250,7 +250,24 @@ fn service_token_file_rules() {
let bearer = "b".repeat(MIN_SERVICE_TOKEN_LEN + 4);
std::fs::write(&path, format!("{bearer}\n")).unwrap();
- assert_eq!(ServiceToken::read(&path), ServiceToken::Valid(bearer));
+ assert_eq!(
+ ServiceToken::read(&path),
+ ServiceToken::Valid(bearer.clone())
+ );
+
+ // A token no client could send as a bearer header is refused.
+ for bad in [
+ format!("{bearer}\n{bearer}\n"),
+ format!("{bearer} {bearer}"),
+ format!("{bearer}\u{7}"),
+ format!("{bearer}é"),
+ ] {
+ std::fs::write(&path, bad).unwrap();
+ assert!(
+ matches!(ServiceToken::read(&path), ServiceToken::Invalid(why) if why.contains("visible ASCII"))
+ );
+ }
+ std::fs::write(&path, format!("{bearer}\n")).unwrap();
#[cfg(unix)]
{
@@ -261,3 +278,40 @@ fn service_token_file_rules() {
);
}
}
+
+#[test]
+fn sandbox_none_counts_as_switched_off() {
+ let f = fixture();
+ let vars = env(&[("OPENHUMAN_SANDBOX", "none")]);
+ assert!(matches!(
+ violations(&inputs(&f, &vars))[..],
+ [Violation::Env { .. }]
+ ));
+}
+
+#[cfg(unix)]
+#[test]
+fn a_root_aliasing_the_desktop_install_is_refused() {
+ let f = fixture();
+ let home = f.config.root.parent().unwrap().to_path_buf();
+ let desktop = home.join(".openhuman").join("saas");
+ std::fs::create_dir_all(&desktop).unwrap();
+ // Through a symlink, and through `..`.
+ let link = home.join("alias");
+ std::os::unix::fs::symlink(&desktop, &link).unwrap();
+ let dotted = home.join("saas").join("..").join(".openhuman").join("saas");
+ for root in [link, dotted] {
+ let config = SaasConfig::new(root.clone());
+ let mut i = inputs(&f, &[]);
+ i.config = &config;
+ i.home = Some(home.clone());
+ let found = violations(&i);
+ assert!(
+ found
+ .iter()
+ .any(|v| matches!(v, Violation::Root(why) if why.contains(".openhuman"))),
+ "{}: {found:?}",
+ root.display()
+ );
+ }
+}
diff --git a/crates/openhuman-core/src/core/runtime/mode_tests.rs b/crates/openhuman-core/src/core/runtime/mode_tests.rs
index 421d0e1ae7..9792857305 100644
--- a/crates/openhuman-core/src/core/runtime/mode_tests.rs
+++ b/crates/openhuman-core/src/core/runtime/mode_tests.rs
@@ -33,3 +33,17 @@ fn relocking_the_same_mode_is_fine_but_switching_fails() {
assert!(err.contains("saas"), "{err}");
assert_eq!(slot.get(), Some(&Mode::Saas));
}
+
+#[test]
+fn saas_requests_are_spotted_before_parsing() {
+ let args = |a: &[&str]| a.iter().map(|s| s.to_string()).collect::<Vec<_>>();
+ assert!(requested_in(&args(&["run", "--mode", "saas"]), None));
+ assert!(requested_in(&args(&["run", "--mode=saas"]), None));
+ assert!(requested_in(&args(&["run"]), Some("saas")));
+ assert!(!requested_in(
+ &args(&["run", "--mode", "single-user"]),
+ None
+ ));
+ assert!(!requested_in(&args(&["run"]), None));
+ assert!(!requested_in(&args(&["run", "saas"]), Some("")));
+}
diff --git a/crates/openhuman-rpc/src/server/dev_connect.rs b/crates/openhuman-rpc/src/server/dev_connect.rs
index 4c25014c87..6564b2a3a9 100644
--- a/crates/openhuman-rpc/src/server/dev_connect.rs
+++ b/crates/openhuman-rpc/src/server/dev_connect.rs
@@ -44,9 +44,9 @@ pub fn dev_connect_enabled() -> bool {
// Never on a SaaS core: the route is auth-exempt and hands out the bearer.
!openhuman_core::core::runtime::is_saas()
&& dev_connect_enabled_with(
- cfg!(debug_assertions),
- std::env::var(DEV_CONNECT_ENV).ok().as_deref(),
- )
+ cfg!(debug_assertions),
+ std::env::var(DEV_CONNECT_ENV).ok().as_deref(),
+ )
}
pub(crate) fn dev_connect_enabled_with(debug_build: bool, env: Option<&str>) -> bool {