Keep shutdown diagnostics readable without exposing portable PINs

This commit is contained in:
Дмитрий committed 2026-10-19 13:50:10 +05:00
1 parent d0d7639026
commit 86f5bcc007
2 files changed
+26 -1

No files matched your search

+19 -1
View File
@@ -392,7 +392,14 @@ pub fn redact(text: &str) -> String {
let mut out = Vec::new();
for line in text.lines() {
let l = line.to_lowercase();
let sensitive = SENSITIVE.iter().any(|k| l.contains(k));
let sensitive = SENSITIVE.iter().any(|k| {
if *k == "pin" {
l.match_indices("pin")
.any(|(at, _)| at == 0 || !l.as_bytes()[at - 1].is_ascii_alphanumeric())
} else {
l.contains(k)
}
});
out.push(if sensitive {
"[line removed: may contain a secret]".to_string()
} else {
@@ -1034,6 +1041,17 @@ real error
assert!(!t.contains("PASS") && !t.contains("abc"));
}
#[test]
fn stop_diagnostics_survive_while_portable_pins_remain_hidden() {
let ordinary = "MySQL is still stopping; wait before copying the repack.";
assert_eq!(redact(ordinary), ordinary);
for secret in ["PIN: 123456", "pin=123456", "transfer_pin=123456", "PIN123456"] {
let output = redact(&format!("{ordinary}\n{secret}"));
assert!(output.contains(ordinary));
assert!(!output.contains("123456"));
}
}
#[test]
fn json_redaction_keeps_the_file_valid_and_hides_the_secrets() {
let t = redact_json(