Answer blocked host names like unreachable ones

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sanapachandClaude Opus 5.5 committed 2026-11-20 15:12:38 +02:00
1 parent 402ad0a03a
commit 62141c0840
6 files changed
+121 -20

No files matched your search

+45
View File
@@ -242,3 +242,48 @@ fn regular_checks_are_hourly_with_a_stable_spread() {
.collect();
assert!(spread.len() > 10);
}
/// A port on which nothing listens.
fn closed_port() -> u16 {
let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
listener.local_addr().unwrap().port()
}
#[tokio::test]
async fn internal_names_cannot_be_told_from_unreachable_ones() {
// A name that resolves to a private address, a name that does not
// resolve and a server that refuses the connection look the same to
// the user: otherwise "add RSS" would tell which names exist in the
// server's internal DNS. Only what the URL itself says (an IP literal,
// the port, the scheme) is refused as such.
let port = closed_port();
let lookup = ScriptedLookup::with(&[
("vault.internal.test", &[&["10.20.30.40"]]),
("closed.test", &[&["127.0.0.1"]]),
]);
let fetcher = fetcher(lookup);
let mut answers = Vec::new();
for text in [
format!("http://vault.internal.test:{port}/feed"),
format!("http://nowhere.internal.test:{port}/feed"),
format!("http://closed.test:{port}/feed"),
] {
let error = fetcher
.fetch(&feed_url(&text), &Validators::default())
.await
.unwrap_err();
assert!(!error.public_message().contains("internal"), "{text}");
answers.push((error.public_message(), error.kind));
}
assert_eq!(answers[0].1, FetchErrorKind::Transport, "{answers:?}");
assert!(
answers.iter().all(|answer| *answer == answers[0]),
"{answers:?}"
);
let literal = fetcher
.fetch(&feed_url("http://10.20.30.40/feed"), &Validators::default())
.await
.unwrap_err();
assert_eq!(literal.kind, FetchErrorKind::Refused);
assert_ne!(literal.public_message(), answers[0].0);
}