Files
craft-anything/crates/analysis/tests/regression_har_encoded_keys.rs
BFlatandAfloat 82856a30b2 Redact HAR reports more thoroughly and count their bodies correctly (#648)
Replays #602–#605. HAR reports redact percent-encoded credential names and declared secrets in every kept field, count decoded body bytes, and template only real dates in API paths; the stand-in backend matches older recordings with the current query rules.

Co-authored-by: Afloat <132809511+Afloat16@users.noreply.github.com>
2026-11-03 20:25:48 +07:00

18 lines
864 B
Rust

use craft_anything_analysis::web_har::{HarOptions, inspect_har};
use serde_json::json;
#[test]
fn encoded_credential_names_are_redacted_in_the_report() {
let bytes = serde_json::to_vec(&json!({"log": {"entries": [{
"request": {"method": "GET", "url": "https://example.test/?%74oken=TOP_SECRET&a%70i_key=KEY_SECRET&ACCESS%5fTOKEN=OTHER_SECRET&name=public&broken%7=ok&description=safe"},
"response": {"status": 200}
}]}})).unwrap();
let report = inspect_har(&bytes, &HarOptions { limit: 10, max_entries: 10, ..Default::default() }).unwrap();
let url = report["entries"][0]["url"].as_str().unwrap();
assert!(!report.to_string().contains("SECRET"));
assert_eq!(url.matches("[redacted]").count(), 3);
for public in ["name=public", "broken%7=ok", "description=safe"] {
assert!(url.contains(public), "{url}");
}
}