F: tighten the redirect, cap and oversize assertions

The redirect test waited on a fixed sleep and a status that starts false;
it now waits for the health loop's own http_302 verdict before asserting
the Location target saw no connection. The peer cap asserts the message
rather than the bare number, and a chunked response (no Content-Length to
precheck) proves the byte count refuses an oversize body end to end.
This commit is contained in:
ari committed 2026-10-20 15:04:09 -04:00
1 parent a3b3958add
commit dab2f1ad4f
1 file changed
+37 -5
+37 -5
View File
@@ -604,10 +604,13 @@ async fn a_redirect_is_reported_and_never_followed() {
assert_eq!(code, 503, "{body}");
assert!(body.contains("http_302"), "{body}");
assert!(head.contains("x-slinuxm-peer: beta"), "{head}");
// Let the health loop probe as well, then check the Location was never
// acted on.
tokio::time::sleep(Duration::from_millis(500)).await;
consolidator.wait_status("beta", |s| !s.api.up).await;
// The health loop probes on its own interval; waiting for its verdict is
// what proves the loop refused the redirect too.
consolidator
.wait_status("beta", |s| {
!s.api.up && s.api.last_error.as_deref() == Some("http_302")
})
.await;
assert!(source.hits() > 0);
assert_eq!(target.hits(), 0, "the redirect was followed");
consolidator.stop().await;
@@ -652,6 +655,35 @@ async fn a_silent_peer_times_out_within_the_request_timeout() {
consolidator.stop().await;
}
/// No Content-Length to precheck: only the counting of chunk bytes can refuse
/// this body.
#[tokio::test]
async fn a_chunked_body_over_the_cap_is_refused() {
let dir = TempDir::new("chunked");
let chunk = vec![b'x'; 64];
let mut raw =
b"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nTransfer-Encoding: chunked\r\n\r\n"
.to_vec();
for _ in 0..2 {
raw.extend(format!("{:x}\r\n", chunk.len()).into_bytes());
raw.extend_from_slice(&chunk);
raw.extend(b"\r\n");
}
raw.extend(b"0\r\n\r\n");
let source = Listener::start(move || Some(Answer::Reply(raw.clone()))).await;
let token = dir.token("peer-token", "chunked-token\n");
let mut cfg = one_peer("beta", source.url("http"), None, &token);
cfg.max_response_bytes = 64;
let consolidator = Consolidator::start(cfg).await;
let (code, _, body) = consolidator
.get("/api/v1/peers/beta/systemd/units", None)
.await;
assert_eq!(code, 503, "{body}");
assert!(body.contains("oversize"), "{body}");
consolidator.stop().await;
}
/// Slow loris: the peer answers the headers at once and then drips the body, so
/// only the request deadline can end the call.
#[tokio::test]
@@ -708,7 +740,7 @@ fn at_most_64_peers_may_be_configured() {
config.peers.peer.push(peer(64));
let err = config.validate().unwrap_err().to_string();
assert!(err.contains("64"), "{err}");
assert!(err.contains("at most 64 peers"), "{err}");
}
/// The peer answers any path with SSE headers and then holds the socket, so