[relay] Wake-up: a push endpoint per mailbox, and a constant wake to it when a blob arrives
ci / check (pull_request) Has been cancelled

This commit is contained in:
2026-11-20 12:04:55 +01:00
parent f075fae0e3
commit f852b1a6d1
21 changed files with 1606 additions and 40 deletions
+80
View File
@@ -184,3 +184,83 @@ proptest! {
prop_assert_eq!(back.bytes(), &bytes[..]);
}
}
// Wake-up (`.agents/features/wake-up.md` §2.1): the push endpoint a mailbox may hold.
#[test]
fn a_push_endpoint_is_https_or_loopback_http_and_nothing_else() {
for good in [
"https://ntfy.sh/upAbCdEf0123456789?up=1",
"https://push.example.cz:8443/x",
"https://[2001:db8::1]/up",
"https://ntfy.sh",
] {
let e = PushEndpoint::parse(good).unwrap_or_else(|_| panic!("{good}"));
assert_eq!(e.as_str(), good);
assert!(!e.is_loopback_http());
}
assert_eq!(
PushEndpoint::parse("https://NTFY.sh/a").map(|e| e.host().to_string()),
Ok("ntfy.sh".into())
);
for loopback in [
"http://127.0.0.1:9000/up",
"http://[::1]:9000/up",
"http://localhost/up",
] {
assert!(PushEndpoint::parse(loopback)
.expect("loopback")
.is_loopback_http());
}
for bad in [
"",
"ntfy.sh/up",
"ftp://ntfy.sh/up",
"http://ntfy.sh/up",
"http://10.0.0.1/up",
"https:///up",
"https://user:pw@ntfy.sh/up",
"https://user@ntfy.sh/up",
"https://ntfy.sh/up#frag",
"https://ntfy.sh/a b",
"https://ntfy.sh/\u{e9}",
"https://ntfy.sh:0/up",
"https://ntfy.sh:65536/up",
"https://ntfy.sh:08/up",
"https://ntfy.sh:/up",
"https://[::1/up",
"https://ntfy]sh/up",
] {
assert!(PushEndpoint::parse(bad).is_err(), "{bad}");
}
let long = format!("https://ntfy.sh/{}", "a".repeat(MAX_PUSH_ENDPOINT_BYTES));
assert_eq!(
PushEndpoint::parse(&long),
Err(ParseError::TooLarge {
max: MAX_PUSH_ENDPOINT_BYTES
})
);
}
#[test]
fn set_push_refuses_unknown_fields_and_bad_endpoints_and_debug_hides_the_path() {
let ok: SetPush =
serde_json::from_str(r#"{"endpoint":"https://ntfy.sh/upSecret"}"#).expect("json");
assert_eq!(ok.endpoint.as_str(), "https://ntfy.sh/upSecret");
assert!(!format!("{ok:?}").contains("upSecret"));
assert!(serde_json::from_str::<SetPush>(r#"{"endpoint":"http://ntfy.sh/x"}"#).is_err());
assert!(
serde_json::from_str::<SetPush>(r#"{"endpoint":"https://ntfy.sh/x","extra":1}"#).is_err()
);
assert_eq!(
serde_json::to_string(&ok).expect("json"),
r#"{"endpoint":"https://ntfy.sh/upSecret"}"#
);
}
proptest! {
#[test]
fn a_push_endpoint_parser_never_panics(text in "\\PC{0,64}") {
let _ = PushEndpoint::parse(&text);
let _ = PushEndpoint::parse(&format!("https://{text}"));
}
}