From 8d256e464bb4cfafd58318d21c3124a0795e9a39 Mon Sep 17 00:00:00 2001 From: Eureka Date: Tue, 17 Nov 2026 01:52:37 +0000 Subject: [PATCH] chat job tests: pin Trouble to stderr and the userinfo guard; a bracketed host must end the authority or take a port Co-Authored-By: Claude Sonnet 5.5 --- .../huginn-daemon/src/bin/huginn-sources.rs | 9 +++++-- crates/huginn-daemon/src/sources/job_tests.rs | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/crates/huginn-daemon/src/bin/huginn-sources.rs b/crates/huginn-daemon/src/bin/huginn-sources.rs index b87b847..e75e608 100644 --- a/crates/huginn-daemon/src/bin/huginn-sources.rs +++ b/crates/huginn-daemon/src/bin/huginn-sources.rs @@ -85,7 +85,12 @@ fn loopback_http(name: &str, value: String) -> Result { let value = http(name, value)?; let authority = value["http://".len()..].split(['/', '?', '#']).next().unwrap_or(""); let host = match authority.strip_prefix('[') { - Some(inner) => inner.split(']').next().unwrap_or(""), + // The bracket must end the authority or be followed by the port, so `[::1].evil.example` names no loopback. + Some(inner) => match inner.split_once(']') { + Some((host, "")) => host, + Some((host, port)) if port.starts_with(':') => host, + _ => "", + }, None => authority.split(':').next().unwrap_or(""), }; let loopback = !authority.contains('@') && (host.eq_ignore_ascii_case("localhost") || host.parse::().is_ok_and(|ip| ip.is_loopback())); @@ -314,7 +319,7 @@ mod tests { for good in ["http://localhost", "http://127.0.0.1:8008", "http://127.9.9.9/", "http://[::1]:8008", "http://LOCALHOST:1/x"] { assert!(parse(args(&with(good)), now()).is_ok(), "{good}"); } - for bad in ["http://matrix.example", "http://10.0.0.5:8008", "http://localhost@evil.example", "http://127.0.0.1.evil.example", "http://localhost.evil.example", "http://[::2]", "https://localhost"] { + for bad in ["http://matrix.example", "http://10.0.0.5:8008", "http://localhost@evil.example", "http://127.0.0.1.evil.example", "http://localhost.evil.example", "http://[::2]", "https://localhost", "http://127.0.0.1:pw@evil.example", "http://[::1].evil.example", "http://[::1]x"] { assert!(error(&with(bad)).contains("--matrix-url"), "{bad}"); } } diff --git a/crates/huginn-daemon/src/sources/job_tests.rs b/crates/huginn-daemon/src/sources/job_tests.rs index 644065f..7433dfa 100644 --- a/crates/huginn-daemon/src/sources/job_tests.rs +++ b/crates/huginn-daemon/src/sources/job_tests.rs @@ -260,3 +260,28 @@ fn chat_purge_makes_no_matrix_request() { purge(&mut rig.index, &request).unwrap(); assert_eq!(asked.seen().len(), made); } + +#[test] +fn a_retirement_failure_goes_to_the_complaint_stream() { + struct Left; + impl RoomHistory for Left { + fn joined_rooms(&mut self) -> Result> { + Ok(vec![]) + } + fn facts(&mut self, _room_id: &str) -> Result { + bail!("unreachable") + } + fn events_after(&mut self, _room_id: &str, _after: Option<&str>, _limit: u32) -> Result> { + bail!("unreachable") + } + } + let world = rooms(vec![("!swarm:s", vec![], vec![message("$m1", "@a:s", 1, "words")])]); + let (base, _) = synapse(&world); + let mut rig = Rig::new(); + rig.go(Some(&mut HttpMatrix::new(&base, TOKEN))); + rig.index.state.lock().unwrap().fail_chat_deletes = true; + let out = rig.go(Some(&mut Left)); + assert_eq!(out.status, 1); + assert!(out.complained.iter().any(|line| line.starts_with("huginn-sources: retiring !swarm:s failed")), "{:?}", out.complained); + assert!(!out.said.iter().any(|line| line.contains("retiring")), "{:?}", out.said); +}