mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
test(cksum): add tests for non-utf-8 handling in checksum files
This commit is contained in:
parent
99cddd16f1
commit
6030ad9bc9
1 changed files with 77 additions and 0 deletions
|
@ -1425,3 +1425,80 @@ fn test_check_trailing_space_fails() {
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_contains("CHECKSUM: no properly formatted checksum lines found");
|
.stderr_contains("CHECKSUM: no properly formatted checksum lines found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Regroup tests related to the handling of non-utf-8 content
|
||||||
|
/// in checksum files.
|
||||||
|
/// These tests are excluded from Windows because it does not provide any safe
|
||||||
|
/// conversion between `OsString` and byte sequences for non-utf-8 strings.
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
mod check_utf8 {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_check_non_utf8_comment() {
|
||||||
|
let hashes =
|
||||||
|
b"MD5 (empty) = 1B2M2Y8AsgTpgAmY7PhCfg==\n\
|
||||||
|
# Comment with a non utf8 char: >>\xff<<\n\
|
||||||
|
SHA256 (empty) = 47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=\n\
|
||||||
|
BLAKE2b (empty) = eGoC90IBWQPGxv2FJVLScpEvR0DhWEdhiobiF/cfVBnSXhAxr+5YUxOJZESTTrBLkDpoWxRIt1XVb3Aa/pvizg==\n"
|
||||||
|
;
|
||||||
|
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
|
at.touch("empty");
|
||||||
|
at.write_bytes("check", hashes);
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("--check")
|
||||||
|
.arg(at.subdir.join("check"))
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is("empty: OK\nempty: OK\nempty: OK\n")
|
||||||
|
.no_stderr();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
#[test]
|
||||||
|
fn test_check_non_utf8_filename() {
|
||||||
|
use std::{ffi::OsString, os::unix::ffi::OsStringExt};
|
||||||
|
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
let filename: OsString = OsStringExt::from_vec(b"funky\xffname".to_vec());
|
||||||
|
at.touch(&filename);
|
||||||
|
|
||||||
|
// Checksum match
|
||||||
|
at.write_bytes("check",
|
||||||
|
b"SHA256 (funky\xffname) = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n");
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("--check")
|
||||||
|
.arg(at.subdir.join("check"))
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is_bytes(b"funky\xffname: OK\n")
|
||||||
|
.no_stderr();
|
||||||
|
|
||||||
|
// Checksum mismatch
|
||||||
|
at.write_bytes("check",
|
||||||
|
b"SHA256 (funky\xffname) = ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\n");
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("--check")
|
||||||
|
.arg(at.subdir.join("check"))
|
||||||
|
.fails()
|
||||||
|
.stdout_is_bytes(b"funky\xffname: FAILED\n")
|
||||||
|
.stderr_contains("1 computed checksum did NOT match");
|
||||||
|
|
||||||
|
// file not found
|
||||||
|
at.write_bytes("check",
|
||||||
|
b"SHA256 (flakey\xffname) = ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\n");
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("--check")
|
||||||
|
.arg(at.subdir.join("check"))
|
||||||
|
.fails()
|
||||||
|
.stdout_is_bytes(b"flakey\xffname: FAILED open or read\n")
|
||||||
|
.stderr_contains("1 listed file could not be read");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue