test: cover the trusted_proxy X-Forwarded-For rate-limit gate

Two integration tests pinning both sides of the gate: trusted_proxy=true gives
each forwarded IP its own bucket; trusted_proxy=false ignores spoofed XFF and
shares the global bucket. Closes audit gap M7. Test-only, no behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
MechaCat02
2026-07-13 21:13:37 +02:00
parent b5f7467c47
commit f2c9cfe162
2 changed files with 88 additions and 0 deletions

View File

@@ -148,6 +148,27 @@ pub fn harness_with_auth_rate_limit(
harness_with_auth_config(pool, storage, storage_dir, auth)
}
/// Like [`harness_with_auth_rate_limit`] but also sets whether the backend
/// trusts `X-Forwarded-For` (`AUTH_TRUSTED_PROXY`). Used to prove the per-IP
/// rate-limit gate: with `trusted_proxy` on, distinct XFF hops get independent
/// buckets; with it off, XFF is ignored and everything shares the global bucket.
pub fn harness_with_auth_rate_limit_proxy(
pool: PgPool,
per_sec: u32,
burst: u32,
trusted_proxy: bool,
) -> Harness {
let storage_dir = tempfile::tempdir().expect("tempdir");
let storage = Arc::new(LocalStorage::new(storage_dir.path()));
let auth = AuthConfig {
cookie_secure: false,
trusted_proxy,
rate_limit: mangalord::auth::rate_limit::RateLimitConfig { per_sec, burst },
..AuthConfig::default()
};
harness_with_auth_config(pool, storage, storage_dir, auth)
}
/// Like [`harness`] but slots a caller-supplied [`ResyncService`] stub
/// into `AppState.resync`. Used by the admin resync tests so the
/// endpoint path is exercised without standing up a real Chromium.