use super::*;
#[test]
fn a_boundary_holds_back_only_what_could_begin_a_secret() {
let mut redactor = StreamRedactor::new(["sk-0123456789".to_owned()]);
let mut written = redactor.push("Reading the file then sk-0123");
written.push_str(&redactor.release());
assert!(!written.contains("sk-"), "{written}");
written.push_str(" | tool | ");
written.push_str(&redactor.push("456789 done"));
written.push_str(&redactor.flush());
assert_eq!(written, "Reading the file then | tool | [REDACTED] done");
let mut plain = StreamRedactor::new(["sk-0123456789".to_owned()]);
let mut shown = plain.push("Nothing secret here.");
shown.push_str(&plain.release());
assert_eq!(shown, "Nothing secret here.");
}
#[test]
fn stream_redactor_preserves_lines_and_catches_cross_chunk_secrets() {
let mut redactor = StreamRedactor::new(["super-secret-token-123".to_owned()]);
let mut output = String::new();
for chunk in ["line1\nkey=super-", "secret-", "token-123\nline3"] {
output.push_str(&redactor.push(chunk));
}
output.push_str(&redactor.flush());
assert_eq!(output, "line1\nkey=[REDACTED]\nline3");
}
#[test]
fn prefix_overlapping_secrets_do_not_leak_suffix_across_chunk_boundary() {
let mut redactor = StreamRedactor::new(["sk-short".to_owned(), "sk-short-extended".to_owned()]);
let mut output = redactor.push("val=sk-short");
assert!(!output.contains("sk-short"), "{output}");
output.push_str(&redactor.push("-extended ok"));
output.push_str(&redactor.flush());
assert_eq!(output, "val=[REDACTED] ok");
}