Skip to content

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

test(user_agents): cover credential kind replacement

Steven Enamakel578570e8e5bb
diff --git a/crates/openhuman-core/src/user_agents/credentials_tests.rs b/crates/openhuman-core/src/user_agents/credentials_tests.rs
index 54086994ea..8d135199eb 100644
--- a/crates/openhuman-core/src/user_agents/credentials_tests.rs
+++ b/crates/openhuman-core/src/user_agents/credentials_tests.rs
@@ -66,3 +66,22 @@ fn bad_input_is_refused() {
assert!(store(&alice, UserCredentialKind::Session, "t", Some("tomorrow")).is_err());
assert!(!has(&alice));
}
+
+#[test]
+fn installing_one_kind_replaces_the_other() {
+ let tmp = tempfile::tempdir().unwrap();
+ let alice = agent(&tmp, "alice-rotates");
+ store(&alice, UserCredentialKind::ApiKey, "old-key", None).unwrap();
+ store(&alice, UserCredentialKind::Session, "new-jwt", None).unwrap();
+ assert_eq!(
+ resolve_backend_credential(&alice).unwrap(),
+ BackendCredential::Session("new-jwt".into()),
+ "the old API key no longer wins"
+ );
+ store(&alice, UserCredentialKind::ApiKey, "newer-key", None).unwrap();
+ assert_eq!(
+ resolve_backend_credential(&alice).unwrap(),
+ BackendCredential::ApiKey("newer-key".into())
+ );
+ assert!(clear(&alice).unwrap());
+}