#[skuld::test]
fn ntfs_stream_names_splits_off_every_stream_then_trims_space_and_dot() {
for (probe, want) in [
("x.bat ", vec!["x.bat"]),
("x.bat.", vec!["x.bat"]),
("x.bat:s", vec!["x.bat", "s"]),
("x.bat. ", vec!["x.bat"]),
("x.bat::$DATA", vec!["x.bat", "", "$DATA"]),
("x.exe:payload.bat:", vec!["x.exe", "payload.bat", ""]),
("C:x.bat:s", vec!["x.bat", "s"]),
("c:x.bat", vec!["x.bat"]),
("ab:x.bat", vec!["ab", "x.bat"]),
(".:x.bat", vec!["x.bat"]),
("é:x.bat", vec!["x.bat"]),
("x.bat.:s", vec!["x.bat", "s"]),
("x.bat :s", vec!["x.bat", "s"]),
("x.bat. :s", vec!["x.bat", "s"]),
("x.bat\t", vec!["x.bat\t"]),
("..bat", vec!["..bat"]),
("x.exe", vec!["x.exe"]),
] {
assert_eq!(super::ntfs_stream_names(probe).collect::<Vec<_>>(), want, "{probe:?}");
}
}
#[skuld::test]
fn is_batch_by_shell_follows_the_last_dot_anywhere_in_the_name() {
for yes in [
".bat",
".cmd",
"x.bat",
"x.CMD",
"x.exe:payload.bat",
"tool:go.bat",
"a.b.c.bat",
] {
assert!(super::is_batch_by_shell(yes), "{yes:?} must read as a batch name");
}
for no in ["x.exe", "batch", "x.batch", "bat", "x.bat ", "x.bat:s", "x.bat."] {
assert!(
!super::is_batch_by_shell(no),
"{no:?} must not read as a batch name here"
);
}
}
#[skuld::test]
fn is_batch_program_on_windows_refuses_every_stream_piece() {
for probe in [
"x.bat ", "x.bat.", "x.cmd ", "x.bat. ", "x.bat.:s", "x.bat:s", "x.CMD:s",
] {
assert!(super::is_batch_program(probe), "{probe:?} trims to a batch file");
}
for probe in ["x.exe:payload.bat:", "x.exe:payload.bat:$DATA", "C:x.bat:s"] {
assert!(
super::is_batch_program(probe),
"{probe:?} hides the batch name in a later stream piece"
);
}
for probe in ["x.bat:", "x.bat:s", "x.bat::$DATA"] {
assert!(
super::is_batch_program(probe),
"{probe:?} hides the batch name in the first stream piece"
);
}
assert!(super::is_batch_program("a:x.bat:s"));
for probe in ["a:x.exe:x.bat:s", "x.exe:x.bat:s"] {
assert!(
super::is_batch_program(probe),
"{probe:?} hides the batch name in a middle piece"
);
}
for probe in ["x.exe:payload.bat", "notepad.exe:p.cmd", "tool:go.bat", "x.txt:a.bat"] {
assert!(
super::is_batch_program(probe),
"{probe:?} runs out of a batch-named stream"
);
}
for probe in [".bat", ".cmd"] {
assert!(super::is_batch_program(probe), "{probe:?} is a batch name");
}
assert!(super::is_batch_program("x.bat"));
assert!(!super::is_batch_program("x.exe"));
assert!(!super::is_batch_program("x.batch"));
assert!(!super::is_batch_program("batch"));
}