Repository navigation
test(provider): pin the 2 MB response cap - #32
Conversation
read_json refuses a body over MAX_BODY_BYTES, either from an announced Content-Length or while streaming a body that has none, but nothing tested it. Add tests for both refusals and for a body exactly at the cap.
Tiny Sweeper reviewReviewed head: Verdict: Ready for maintainer review · Priority: low Diagnostics and supporting detailsFull summaryPull request purpose (title): test(provider): pin the 2 MB response cap. Tiny Sweeper completed its review; deterministic results follow. Review snapshot
Completeness: Complete What changedNo production behavior changes. The diff appends `#[cfg(test)] #[path = "http_tests.rs"] mod tests;` to `crates/tinysearch/src/provider/http.rs` and adds `crates/tinysearch/src/provider/http_tests.rs` (74 lines). The test file defines a `TestResult<T>` alias, a `cap()` helper that converts `MAX_BODY_BYTES` to `usize`, and helpers (`serve`, `read`) returning `TestResult` rather than unwrapping; `serve` binds a local `TcpListener` and writes one HTTP 200 reply. Three `#[tokio::test]` cases target the cap: a chunked body of `cap()? + 1` bytes with no `Content-Length` asserted to be refused with the exact `ProviderUnavailable("provider response too large")` error; a reply with a hard-coded `Content-Length: 2000001` and empty body asserted to be refused; and a body of exactly `MAX_BODY_BYTES` bytes, built as `{}` followed by spaces, asserted to parse to `serde_json::json!({})`. The description reports local runs as-is and with both cap comparisons deliberately disabled, but that is author-reported and not trusted check evidence. FeaturesNone identified with supported citations. TestsNo supported feature-to-test mapping was produced. Test execution is not inferred. FindingsNo active actionable findings. Before mergeNone. Agent review detailscritique
security
tests
commits
description
Evidence and run details
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Comment |
Return TestResult and use ? instead of unwrap, and convert the cap with usize::try_from instead of an as cast.
Summary
Provider responses are capped at 2 MB (
MAX_BODY_BYTES):read_jsonrefuses a response whoseContent-Lengthis over the cap before reading it, and stops a body with noContent-Length(chunked or read-to-close) as soon as the streamed bytes pass the cap. The code is correct, but nothing tested it, so a refactor could drop either check and a large or endless upstream response would be buffered in full. This adds tests only.Related issue
None.
API or behavior changes
None (tests only).
Validation
rustfmt --edition 2024 --checkon the touched filescargo clippy --all-targets --all-features -- -D warnings: left to CIcargo build --all-targets --all-features: left to CIcargo test --all-features: only the new tests ran locally (below); CI runs the suiteCARGO_INCREMENTAL=0 cargo test -p tinysearch --lib provider::http::testsok. 3 passed; 0 failed.FAILED. 1 passed; 2 failed. The two refusal tests fail and the at-the-cap test still passes.Tests
New
provider/http_tests.rs(sibling ofhttp.rs), against a raw local TCP server:a_streamed_body_past_the_cap_is_refused: a chunked 200 of 2,000,001 bytes with noContent-Lengthis refused with "provider response too large".an_announced_length_past_the_cap_is_refused_before_reading:Content-Length: 2000001is refused before any body is read.a_body_at_the_cap_is_read: a 2,000,000-byte body is read and parsed.Documentation
Not needed (tests only).
Checklist
#[allow(...)],#[ignore], or relaxed lints.envcontents in the diff or the descriptionInherited CI red
module-ci / supply-chainfails on this PR because of RustSec advisories against the existing dependency tree (cargo-deny reports RUSTSEC-2026-0346 through 0349, 0367 through 0369, 0381 and 0382), including RUSTSEC-2026-0346 (Debugimpls for client session values expose TLS secrets) and RUSTSEC-2026-0347 (buffered application data sent to the outer server after ECH rejection) inrustls. Both were published after main's last CI run, and this PR does not change dependencies. Fixing it needs arustlsbump on main.