use keyhog_scanner::unicode_hardening::{
detect_unicode_attacks, normalize_homoglyphs, EvasionKind,
};
#[test]
fn nbsp_split_credential_rejoins_after_normalization() {
let text = "ghp_abcdefghijklmnopqrstuvwx\u{00A0}yzABCDEFGHIJ0123";
let normalized = normalize_homoglyphs(text);
assert_eq!(
normalized.as_ref(),
"ghp_abcdefghijklmnopqrstuvwxyzABCDEFGHIJ0123",
"NO-BREAK SPACE (U+00A0) must be stripped, rejoining the split PAT; got: {normalized:?}"
);
assert!(!normalized.contains('\u{00A0}'));
}
#[test]
fn narrow_nbsp_stripped_from_credential() {
let text = "sk_live_abc\u{202F}def123456789";
let normalized = normalize_homoglyphs(text);
assert_eq!(
normalized.as_ref(),
"sk_live_abcdef123456789",
"NARROW NO-BREAK SPACE (U+202F) must be stripped; got: {normalized:?}"
);
assert!(!normalized.contains('\u{202F}'));
}
#[test]
fn nel_stripped_from_credential() {
let text = "token=abc\u{0085}def0123456789";
let normalized = normalize_homoglyphs(text);
assert_eq!(
normalized.as_ref(),
"token=abcdef0123456789",
"NEL (U+0085) must be stripped; got: {normalized:?}"
);
assert!(!normalized.contains('\u{0085}'));
}
#[test]
fn detect_reports_nbsp_separator_as_suspicious() {
let text = "ghp_abc\u{00A0}def";
let attacks = detect_unicode_attacks(text);
assert!(
attacks
.iter()
.any(|a| a.char == '\u{00A0}' && a.kind == EvasionKind::Suspicious),
"U+00A0 must be reported as a Suspicious separator; attacks={attacks:?}"
);
}