Skip to content

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

test(caps_host): cover credential name trimming and fail-closed lookup

Steven Enamakelfa4831e88a81
diff --git a/crates/openhuman-core/src/flows/caps_host/ops_tests.rs b/crates/openhuman-core/src/flows/caps_host/ops_tests.rs
index bfea0d0a3a..5536e7b8ad 100644
--- a/crates/openhuman-core/src/flows/caps_host/ops_tests.rs
+++ b/crates/openhuman-core/src/flows/caps_host/ops_tests.rs
@@ -1,4 +1,7 @@
use super::*;
+use crate::config::Config;
+use crate::security::SecurityPolicy;
+use crate::security::credentials::{HttpCredential, HttpCredentialsStore};
fn http_cred_store() -> (tempfile::TempDir, HttpCredentialsStore) {
let dir = tempfile::tempdir().expect("tempdir");
diff --git a/crates/openhuman-core/src/flows/caps_host/ops_tool_results_and_credentials_tests.rs b/crates/openhuman-core/src/flows/caps_host/ops_tool_results_and_credentials_tests.rs
index 2e9b087b9a..15025f3446 100644
--- a/crates/openhuman-core/src/flows/caps_host/ops_tool_results_and_credentials_tests.rs
+++ b/crates/openhuman-core/src/flows/caps_host/ops_tool_results_and_credentials_tests.rs
@@ -1,136 +1,30 @@
use super::*;
-/// A `http_cred:<name>` ref resolves to the stored bearer credential and
-/// injects `Authorization: Bearer <token>` onto the outbound request.
+/// The host applies its historic credential-id trimming after the module
+/// returns the parser's exact name.
#[test]
-fn http_cred_resolves_and_injects_bearer_header() {
+fn http_credential_lookup_trims_the_module_parsed_name() {
let (_dir, store) = http_cred_store();
store
- .upsert(&HttpCredential::bearer("stripe", "sk_live_secret"))
+ .upsert(&HttpCredential::bearer("payments", "sk_live_secret"))
.unwrap();
- let cred = resolve_http_credential(&store, Some("http_cred:stripe"))
- .expect("resolve ok")
- .expect("credential present");
-
- let mut request = json!({ "method": "GET", "url": "https://api.example.com" });
- let header = inject_http_credential(&mut request, &cred).unwrap();
- assert_eq!(header, "Authorization");
- assert_eq!(
- request["headers"]["Authorization"],
- json!("Bearer sk_live_secret")
- );
-}
-
-/// A custom-header credential injects under its own header name while
-/// preserving any headers the flow author already set.
-#[test]
-fn http_cred_injection_preserves_existing_headers() {
- let (_dir, store) = http_cred_store();
- store
- .upsert(&HttpCredential::header("apikey", "X-API-Key", "topsecret"))
- .unwrap();
- let cred = resolve_http_credential(&store, Some("http_cred:apikey"))
- .unwrap()
- .unwrap();
-
- let mut request = json!({
- "method": "POST",
- "url": "https://api.example.com",
- "headers": { "Content-Type": "application/json" }
- });
- inject_http_credential(&mut request, &cred).unwrap();
- assert_eq!(
- request["headers"]["Content-Type"],
- json!("application/json")
- );
- assert_eq!(request["headers"]["X-API-Key"], json!("topsecret"));
-}
-
-/// A basic credential injects `Authorization: Basic ...` even when the flow
-/// author set no `headers` object at all.
-#[test]
-fn http_cred_injects_basic_into_absent_headers() {
- let (_dir, store) = http_cred_store();
- store
- .upsert(&HttpCredential::basic("acme", "alice", "pw"))
- .unwrap();
- let cred = resolve_http_credential(&store, Some("http_cred:acme"))
- .unwrap()
- .unwrap();
-
- let mut request = json!({ "method": "GET", "url": "https://x.example.com" });
- inject_http_credential(&mut request, &cred).unwrap();
- let value = request["headers"]["Authorization"]
- .as_str()
- .expect("Authorization header injected");
- assert!(
- value.starts_with("Basic "),
- "unexpected basic header: {value}"
- );
-}
-
-/// A `http_cred:<name>` naming a credential that does not exist FAILS the
-/// request closed — it must never proceed silently unauthenticated.
-#[test]
-fn unknown_http_cred_fails_closed() {
- let (_dir, store) = http_cred_store();
- let result = resolve_http_credential(&store, Some("http_cred:ghost"));
- assert!(result.is_err(), "unknown http_cred must fail closed");
+ let credential = resolve_http_credential(&store, Some(" payments "))
+ .expect("lookup succeeds")
+ .expect("the normalized credential exists");
+ assert_eq!(credential.name, "payments");
+ assert_eq!(credential.to_header().unwrap().1, "Bearer sk_live_secret");
}
-/// A malformed `http_cred:` ref (empty or whitespace-only name) must fail
-/// closed the same as an unknown credential name — it must never be
-/// treated as "no connection_ref" and silently sent unauthenticated
-/// (Codex P2 finding).
#[test]
-fn malformed_http_cred_name_fails_closed() {
+fn unknown_parsed_credential_name_fails_closed() {
let (_dir, store) = http_cred_store();
- assert!(
- resolve_http_credential(&store, Some("http_cred:")).is_err(),
- "an empty http_cred name must fail closed, not fall through as no-op"
- );
- assert!(
- resolve_http_credential(&store, Some("http_cred: ")).is_err(),
- "a whitespace-only http_cred name must fail closed, not fall through as no-op"
- );
+ assert!(resolve_http_credential(&store, Some("ghost")).is_err());
}
-/// No `connection_ref`, or a non-`http_cred:` prefix, injects nothing and
-/// is not an error.
#[test]
-fn no_http_cred_ref_injects_nothing() {
+fn absent_and_empty_parsed_names_do_not_select_a_credential() {
let (_dir, store) = http_cred_store();
assert!(resolve_http_credential(&store, None).unwrap().is_none());
- assert!(
- resolve_http_credential(&store, Some("composio:gmail:conn_1"))
- .unwrap()
- .is_none()
- );
-}
-
-/// The secret is server-side-only: the approval-gate redaction (computed on
-/// the pre-injection request) never contains it, and after injection it
-/// lives ONLY in the outbound `Authorization` header.
-#[test]
-fn injected_secret_never_reaches_the_audit_redaction() {
- let (_dir, store) = http_cred_store();
- let secret = "sk_live_never_log_me";
- store
- .upsert(&HttpCredential::bearer("stripe", secret))
- .unwrap();
- let cred = resolve_http_credential(&store, Some("http_cred:stripe"))
- .unwrap()
- .unwrap();
-
- let mut request = json!({ "method": "GET", "url": "https://api.example.com" });
- // Pre-injection redaction — what the approval UI / audit trail sees.
- let redacted = crate::security::approval::redact_args(&request);
- assert!(!serde_json::to_string(&redacted).unwrap().contains(secret));
-
- inject_http_credential(&mut request, &cred).unwrap();
- assert_eq!(
- request["headers"]["Authorization"],
- json!(format!("Bearer {secret}"))
- );
+ assert!(resolve_http_credential(&store, Some(" ")).is_err());
}