F: dedupe test setup
This commit is contained in:
1 parent
f82b78bad5
commit
4f388ccc92
1 file changed
+17
-20
+17
-20
@@ -401,6 +401,21 @@ fn response(status: &str, extra: &str, body: &[u8]) -> Vec<u8> {
|
||||
out
|
||||
}
|
||||
|
||||
/// Asserts that a reply over `max_response_bytes` is refused before its body
|
||||
/// is read.
|
||||
async fn assert_oversize_refused(source: &Listener, token: &Path) {
|
||||
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;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_plain_peer_reports_up_and_auth_ok() {
|
||||
let dir = TempDir::new("plain");
|
||||
@@ -605,16 +620,7 @@ async fn an_oversize_body_is_refused() {
|
||||
let source =
|
||||
Listener::start(|| Some(Answer::Reply(response("200 OK", "", &[b'x'; 4096])))).await;
|
||||
let token = dir.write("peer-token", "big-token\n".as_bytes(), 0o600);
|
||||
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;
|
||||
assert_oversize_refused(&source, &token).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -655,16 +661,7 @@ async fn a_chunked_body_over_the_cap_is_refused() {
|
||||
raw.extend(b"0\r\n\r\n");
|
||||
let source = Listener::start(move || Some(Answer::Reply(raw.clone()))).await;
|
||||
let token = dir.write("peer-token", "chunked-token\n".as_bytes(), 0o600);
|
||||
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;
|
||||
assert_oversize_refused(&source, &token).await;
|
||||
}
|
||||
|
||||
/// Slow loris: the peer answers the headers at once and then drips the body, so
|
||||
|
||||
Reference in new issue
Block a user