mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
hashsum: improve the file verification algo.
We have 3 different kinds of input: * "algo (filename) = checksum" example: `BLAKE2 (a) = bedfbb90d858c2d67b7ee8f7523be3d3b54004ef9e4f02f2ad79a1d05bfdfe49b81e3c92ebf99b504102b6bf003fa342587f5b3124c205f55204e8c4b4ce7d7c` * "checksum filename" example: `60b725f10c9c85c70d97880dfe8191b3 a` * "checksum filename" example: `60b725f10c9c85c70d97880dfe8191b3 a` These algo/regexp are tricky as files can be called "a, " b", " ", or "*c". We look at the first time to analyze the kind of input and reuse the same regexp then.
This commit is contained in:
parent
6acc8e695f
commit
2c83b28d18
2 changed files with 254 additions and 43 deletions
|
@ -365,26 +365,28 @@ fn test_check_md5sum() {
|
|||
}
|
||||
}
|
||||
|
||||
// GNU also supports one line sep
|
||||
#[test]
|
||||
fn test_check_md5sum_not_enough_space() {
|
||||
fn test_check_md5sum_only_one_space() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
for f in ["a", "b"] {
|
||||
for f in ["a", " b", "c"] {
|
||||
at.write(f, &format!("{f}\n"));
|
||||
}
|
||||
at.write(
|
||||
"check.md5sum",
|
||||
"60b725f10c9c85c70d97880dfe8191b3 a\n\
|
||||
bf35d7536c785cf06730d5a40301eba2 b\n",
|
||||
bf35d7536c785cf06730d5a40301eba2 b\n\
|
||||
2cd6ee2c70b0bde53fbe6cac3c8b8bb1 *c\n",
|
||||
);
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("--strict")
|
||||
.arg("-c")
|
||||
.arg("check.md5sum")
|
||||
.fails()
|
||||
.stderr_only("md5sum: check.md5sum: no properly formatted checksum lines found\nmd5sum: WARNING: 2 lines are improperly formatted\n");
|
||||
.ccmd("md5sum")
|
||||
.arg("--strict")
|
||||
.arg("-c")
|
||||
.arg("check.md5sum")
|
||||
.succeeds()
|
||||
.stdout_only("a: OK\n b: OK\nc: OK\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -684,6 +686,87 @@ fn test_sha1_with_md5sum_should_fail() {
|
|||
.stderr_does_not_contain("WARNING: 1 line is improperly formatted");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_one_two_space_star() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.touch("empty");
|
||||
|
||||
// with one space, the "*" is removed
|
||||
at.write("in.md5", "d41d8cd98f00b204e9800998ecf8427e *empty\n");
|
||||
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("--check")
|
||||
.arg(at.subdir.join("in.md5"))
|
||||
.succeeds()
|
||||
.stdout_is("empty: OK\n");
|
||||
|
||||
// with two spaces, the "*" is not removed
|
||||
at.write("in.md5", "d41d8cd98f00b204e9800998ecf8427e *empty\n");
|
||||
// First should fail as *empty doesn't exit
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("--check")
|
||||
.arg(at.subdir.join("in.md5"))
|
||||
.fails()
|
||||
.stdout_is("*empty: FAILED open or read\n");
|
||||
|
||||
at.touch("*empty");
|
||||
// Should pass as we have the file
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("--check")
|
||||
.arg(at.subdir.join("in.md5"))
|
||||
.succeeds()
|
||||
.stdout_is("*empty: OK\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_one_two_space_star_start_without_star() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.touch("empty");
|
||||
at.touch("f");
|
||||
|
||||
// with one space, the "*" is removed
|
||||
at.write(
|
||||
"in.md5",
|
||||
"d41d8cd98f00b204e9800998ecf8427e f\nd41d8cd98f00b204e9800998ecf8427e *empty\n",
|
||||
);
|
||||
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("--check")
|
||||
.arg(at.subdir.join("in.md5"))
|
||||
.succeeds()
|
||||
.stdout_is("f: OK\nempty: OK\n");
|
||||
|
||||
// with two spaces, the "*" is not removed
|
||||
at.write(
|
||||
"in.md5",
|
||||
"d41d8cd98f00b204e9800998ecf8427e f\nd41d8cd98f00b204e9800998ecf8427e *empty\n",
|
||||
);
|
||||
// First should fail as *empty doesn't exit
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("--check")
|
||||
.arg(at.subdir.join("in.md5"))
|
||||
.fails()
|
||||
.stdout_is("f: OK\n*empty: FAILED open or read\n");
|
||||
|
||||
at.touch("*empty");
|
||||
// Should pass as we have the file
|
||||
scene
|
||||
.ccmd("md5sum")
|
||||
.arg("--check")
|
||||
.arg(at.subdir.join("in.md5"))
|
||||
.succeeds()
|
||||
.stdout_is("f: OK\n*empty: OK\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_no_backslash_no_space() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue