S048: farms with differing validators: byte proof, no If-Range, stored flag; testserver farm and liar modes

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-26 13:58:03 -06:00
commit ed2f7c67e5
3 changed files with 199 additions and 42 deletions

View file

@ -40,6 +40,11 @@ pub struct Faults {
pub expire_status: Option<u16>,
/// More open connections than this from one client get 429.
pub max_conns: Option<usize>,
/// Served by this many "nodes" in turn (request number modulo N): the same bytes, but each its own Last-Modified and
/// nginx-style weak ETag `W/"<size hex>-<date hex>"`, and If-Range is checked against the node's own.
pub farm: Option<u32>,
/// On a farm, odd nodes serve other bytes of the same size.
pub liar: bool,
}
impl Faults {
@ -83,6 +88,8 @@ impl Faults {
"expire_requests" => num!(expire_requests),
"expire_status" => num!(expire_status),
"max_conns" => num!(max_conns),
"farm" => num!(farm),
"liar" => self.liar = v == "1",
_ => {}
}
Some(())
@ -95,12 +102,13 @@ impl Faults {
$($f: other.$f.clone().or_else(|| self.$f.clone()),)*
ignore_range: self.ignore_range || other.ignore_range,
gzip: self.gzip || other.gzip,
liar: self.liar || other.liar,
} };
}
pick!(
throttle_conn, throttle_total, latency_ms, stall_after, stall_ms, cut_after, reset_after, status,
retry_after, status_count, wrong_length, change_after, version_after_requests, expire_secs,
expire_requests, expire_status, max_conns
expire_requests, expire_status, max_conns, farm
)
}
}

View file

@ -537,13 +537,17 @@ where
reply = reply.with("Retry-After", r.to_string());
}
let src = reply.source.versioned(version);
let node = f.farm.filter(|n| *n > 1).map(|n| req_no % n);
let lies = f.liar && node.is_some_and(|k| k % 2 == 1);
let src = reply.source.versioned(version + u32::from(lies) * 1000);
let total = src.len();
let head_only = req.method == "HEAD";
let mut status = reply.status;
let mut headers = std::mem::take(&mut reply.headers);
let etag = format!("{}\"{}-v{version}\"", if reply.weak { "W/" } else { "" }, reply.id);
let modified = http_date(version);
let (etag, modified) = match node {
Some(k) => (format!("W/\"{total:x}-{:x}\"", 0x1982ea51dc7u64 + u64::from(version * 100 + k)), http_date(version * 7 + k + 1)),
None => (format!("{}\"{}-v{version}\"", if reply.weak { "W/" } else { "" }, reply.id), http_date(version)),
};
let mut range = None;
let ranges_on = reply.file && !f.ignore_range && !reply.chunked && !reply.no_length;
if reply.file && status == 200 {

View file

@ -3,7 +3,8 @@
//! `TestServer::start().await` binds 127.0.0.1 on a free port. Routes (all GET/HEAD):
//! - `/data/<seed>/<len>[/<name>]` deterministic file (`len` accepts k, m, g, t; 100g is fine).
//! Query: `disp=attachment|bare|star|both|inline|evil|dotfile`, `chunked=1`, `nolen=1`, `etag=0`,
//! `lm=0`, `weak=1`, plus any fault by name (see [`Faults`]).
//! `lm=0`, `weak=1`, plus any fault by name (see [`Faults`]). `farm=N` serves it from N nodes in turn that differ in
//! Last-Modified and nginx-style ETag only; `liar=1` with it gives the odd nodes other bytes of the same size.
//! - `/redirect/<n>?to=<path>&code=<30x>`, `/redirect/loop`, `/status/<code>`
//! - `/basic/<user>/<pass>/…`, `/digest/<user>/<pass>/…`, `/cookie/<token>/login` then `/cookie/<token>/…`,
//! `/referrer/<needle>/…`: the rest of the path is served after the check.