Skip to content

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

test(devices): cover abandoning an unpersisted pairing

Steven Enamakel9ab8ca0cde9c
diff --git a/crates/openhuman-core/src/security/devices/bus.rs b/crates/openhuman-core/src/security/devices/bus.rs
index c2d9a6d954..ac0c3ffc72 100644
--- a/crates/openhuman-core/src/security/devices/bus.rs
+++ b/crates/openhuman-core/src/security/devices/bus.rs
@@ -428,7 +428,7 @@ async fn handle_tunnel_frame(channel_id: &str, payload_b64: &str) {
/// could not be persisted: with no row in the store, later frames would
/// otherwise keep being accepted for a device nothing records
/// (`super::owner` treats a missing row as the handshake persistence window).
-fn abandon_unpersisted_pairing(channel_id: &str) {
+pub(super) fn abandon_unpersisted_pairing(channel_id: &str) {
PENDING_SESSIONS.lock().unwrap().remove(channel_id);
ACTIVE_CIPHERS.lock().unwrap().remove(channel_id);
log::warn!("[devices/bus] pairing abandoned channel_id={channel_id}: device not persisted");
diff --git a/crates/openhuman-core/src/security/devices/owner_tests.rs b/crates/openhuman-core/src/security/devices/owner_tests.rs
index 383b779ee6..d41eb37aac 100644
--- a/crates/openhuman-core/src/security/devices/owner_tests.rs
+++ b/crates/openhuman-core/src/security/devices/owner_tests.rs
@@ -208,3 +208,26 @@ async fn a_leftover_pairing_session_does_not_outlive_a_revocation() {
.remove("owner-test-leftover");
assert!(owner.is_err(), "{owner:?}");
}
+
+/// A handshake whose device could not be persisted leaves neither its pairing
+/// session nor its cipher behind, so later frames are not accepted.
+#[test]
+fn an_unpersisted_pairing_is_abandoned() {
+ let id = "owner-test-abandon";
+ super::super::rpc::PENDING_SESSIONS
+ .lock()
+ .unwrap()
+ .insert(id.to_string(), session(None));
+ super::super::rpc::ACTIVE_CIPHERS.lock().unwrap().insert(
+ id.to_string(),
+ std::sync::Arc::new(std::sync::Mutex::new(
+ super::super::crypto::TunnelCipher::new(&[5u8; 32]),
+ )),
+ );
+ super::super::bus::abandon_unpersisted_pairing(id);
+ assert!(!super::super::rpc::PENDING_SESSIONS
+ .lock()
+ .unwrap()
+ .contains_key(id));
+ assert!(!has_active_cipher(id));
+}