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 <noreply@anthropic.com>
This commit is contained in:
parent
a4b625c116
commit
8d256e464b
2 changed files with 32 additions and 2 deletions
|
|
@ -85,7 +85,12 @@ fn loopback_http(name: &str, value: String) -> Result<String> {
|
|||
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::<std::net::IpAddr>().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}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Vec<String>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn facts(&mut self, _room_id: &str) -> Result<super::room_scope::RoomFacts> {
|
||||
bail!("unreachable")
|
||||
}
|
||||
fn events_after(&mut self, _room_id: &str, _after: Option<&str>, _limit: u32) -> Result<Option<super::chat::EventPage>> {
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue