Skip to content

Commit 06bc9ad

Browse files
RenjiSanncakebaker
authored andcommitted
test(cksum): add error case checks for blake2b
1 parent 7fb2bf0 commit 06bc9ad

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

tests/by-util/test_cksum.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ fn test_dev_null() {
968968

969969
#[cfg(unix)]
970970
#[test]
971-
fn test_blake2b_512() {
971+
fn test_blake2b_default_length() {
972972
let scene = TestScenario::new(util_name!());
973973
let at = &scene.fixtures;
974974

@@ -2055,6 +2055,28 @@ fn test_check_blake_length_guess() {
20552055
.arg(at.subdir.join("foo.sums"))
20562056
.fails()
20572057
.stderr_contains("foo.sums: no properly formatted checksum lines found");
2058+
2059+
// This is incorrect because the length hint provided doesn't match the
2060+
// checksum length.
2061+
let length_mismatch = "BLAKE2b-8 (foo.dat) = 171cdfdf84ed";
2062+
at.write("foo.sums", length_mismatch);
2063+
scene
2064+
.ucmd()
2065+
.arg("--check")
2066+
.arg(at.subdir.join("foo.sums"))
2067+
.fails()
2068+
.stderr_contains("foo.sums: no properly formatted checksum lines found");
2069+
2070+
// In this case, validation should fail because even though the checksum
2071+
// length matches the hint, it is above BLAKE2b's max (512).
2072+
let too_long = "BLAKE2b-520 (/dev/null) = 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
2073+
at.write("foo.sums", too_long);
2074+
scene
2075+
.ucmd()
2076+
.arg("--check")
2077+
.arg(at.subdir.join("foo.sums"))
2078+
.fails()
2079+
.stderr_contains("foo.sums: no properly formatted checksum lines found");
20582080
}
20592081

20602082
#[test]

0 commit comments

Comments
 (0)