Skip to content

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

test(profiles): cover permissive decoding and credential parsing

Steven Enamakel617b0ce0835a
diff --git a/crates/openhuman-core/src/core/all_profiles_controller_tests.rs b/crates/openhuman-core/src/core/all_profiles_controller_tests.rs
index b9c2ff5c66..bd4280fa1a 100644
--- a/crates/openhuman-core/src/core/all_profiles_controller_tests.rs
+++ b/crates/openhuman-core/src/core/all_profiles_controller_tests.rs
@@ -45,3 +45,70 @@ fn raw_profiles_operator_registry_matches_its_independent_contract() {
verify_parameter_contracts(&entries, &contracts)
.expect("raw Profiles entries use their declared schemas and runtime decoders");
}
+
+fn raw_profiles_entries() -> Vec<ControllerEntry> {
+ registry()
+ .iter()
+ .filter(|row| row.controller.schema.namespace == "profiles")
+ .map(|row| row.controller.clone())
+ .collect()
+}
+
+#[test]
+fn bound_profile_decoders_keep_permissive_unknown_field_behavior() {
+ use serde_json::json;
+
+ let entries = raw_profiles_entries();
+ for (method, params) in [
+ ("profiles.provision", json!({"user_id":"u1", "extra":true})),
+ (
+ "profiles.deprovision",
+ json!({"profile_id":"p1", "extra":true}),
+ ),
+ ("profiles.list", json!({"entirely_ignored":{"extra":true}})),
+ ("profiles.status", json!({"profile_id":"p1", "extra":true})),
+ (
+ "profiles.set_credential",
+ json!({
+ "profile_id":"p1",
+ "kind":"api_key",
+ "token":"fixture-only-token",
+ "extra":true
+ }),
+ ),
+ (
+ "profiles.clear_credential",
+ json!({"profile_id":"p1", "extra":true}),
+ ),
+ ("profiles.release", json!({"profile_id":"p1", "extra":true})),
+ ] {
+ let params = params.as_object().expect("fixture object").clone();
+ entries
+ .iter()
+ .find(|entry| entry.schema.method_name() == method)
+ .unwrap_or_else(|| panic!("missing raw {method} entry"))
+ .decode_params(params)
+ .unwrap_or_else(|error| panic!("{method} decoder rejected permissive map: {error}"));
+ }
+}
+
+#[tokio::test]
+async fn bound_profile_controller_parses_before_the_saas_guard() {
+ let provision = raw_profiles_entries()
+ .into_iter()
+ .find(|entry| entry.schema.method_name() == "profiles.provision")
+ .expect("raw provision entry");
+ let parse_error = provision
+ .invoke(DispatchCtx::process_default(), Map::new())
+ .await
+ .expect_err("missing user id fails parsing");
+ assert!(parse_error.starts_with("invalid params:"), "{parse_error}");
+
+ let params = serde_json::from_value(serde_json::json!({"user_id":"user-1"}))
+ .expect("valid provision params");
+ let guard_error = provision
+ .invoke(DispatchCtx::process_default(), params)
+ .await
+ .expect_err("valid params reach the existing SaaS guard");
+ assert!(guard_error.contains("SaaS"), "{guard_error}");
+}
diff --git a/crates/openhuman-core/src/profiles/schemas.rs b/crates/openhuman-core/src/profiles/schemas.rs
index f0801f5610..9fe5cc0386 100644
--- a/crates/openhuman-core/src/profiles/schemas.rs
+++ b/crates/openhuman-core/src/profiles/schemas.rs
@@ -295,7 +295,7 @@ fn run_deprovision(_ctx: DispatchCtx, payload: ProfileParams) -> ControllerFutur
Box::pin(async move { to_json(super::ops::deprovision(&payload.profile_id).await?) })
}
-fn run_list(_ctx: DispatchCtx, (): ()) -> ControllerFuture {
+fn run_list(_ctx: DispatchCtx, _payload: ()) -> ControllerFuture {
Box::pin(async move { to_json(super::ops::list().await?) })
}
diff --git a/crates/openhuman-core/src/profiles/schemas_tests.rs b/crates/openhuman-core/src/profiles/schemas_tests.rs
index 260d43426d..87b9a29a00 100644
--- a/crates/openhuman-core/src/profiles/schemas_tests.rs
+++ b/crates/openhuman-core/src/profiles/schemas_tests.rs
@@ -89,6 +89,80 @@ pub(crate) fn profile_parameter_contracts() -> Vec<crate::core::all::ControllerP
]
}
+#[test]
+fn credential_schema_and_parser_keep_field_order_defaults_and_kinds() {
+ use crate::profiles::credentials::UserCredentialKind;
+ use serde_json::json;
+
+ let schema = profiles_schemas("set_credential");
+ assert_eq!(
+ schema
+ .inputs
+ .iter()
+ .map(|field| field.name)
+ .collect::<Vec<_>>(),
+ ["profile_id", "kind", "token", "expires_at"]
+ );
+
+ let absent = parse_credential(
+ json!({
+ "profile_id":"p1",
+ "kind":"api_key",
+ "token":"fixture-only-token"
+ })
+ .as_object()
+ .expect("object params")
+ .clone(),
+ )
+ .expect("api key with absent expiry");
+ assert_eq!(absent.kind, UserCredentialKind::ApiKey);
+ assert_eq!(absent.expires_at, None);
+
+ let null = parse_credential(
+ json!({
+ "profile_id":"p1",
+ "kind":"session",
+ "token":"fixture-only-token",
+ "expires_at":null
+ })
+ .as_object()
+ .expect("object params")
+ .clone(),
+ )
+ .expect("session with null expiry");
+ assert_eq!(null.kind, UserCredentialKind::Session);
+ assert_eq!(null.expires_at, None);
+
+ let string = parse_credential(
+ json!({
+ "profile_id":"p1",
+ "kind":"session",
+ "token":"fixture-only-token",
+ "expires_at":"not-normalized"
+ })
+ .as_object()
+ .expect("object params")
+ .clone(),
+ )
+ .expect("string expiry remains unchanged by the parser");
+ assert_eq!(string.expires_at.as_deref(), Some("not-normalized"));
+
+ for invalid in [json!("unknown"), json!(42), json!(null)] {
+ let params = json!({
+ "profile_id":"p1",
+ "kind":invalid,
+ "token":"fixture-only-token"
+ })
+ .as_object()
+ .expect("object params")
+ .clone();
+ assert!(parse_credential(params)
+ .err()
+ .expect("invalid credential kind")
+ .starts_with("invalid params:"));
+ }
+}
+
#[test]
fn the_operator_plane_is_its_own_domain_family() {
use crate::core::all::DomainGroup;