Skip to content

Commit

Permalink
test(cksum): add test for hexa/base64 confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
RenjiSann committed Aug 26, 2024
1 parent 64f0ae4 commit 1d56096
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/by-util/test_cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,3 +1343,54 @@ fn test_check_blake_length_guess() {
.fails()
.stderr_contains("foo.sums: no properly formatted checksum lines found");
}

#[test]
fn test_check_confusing_base64() {
let cksum = "BLAKE2b-48 (foo.dat) = fc1f97C4";

let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

at.write("foo.dat", "esq");
at.write("foo.sums", cksum);

scene
.ucmd()
.arg("--check")
.arg(at.subdir.join("foo.sums"))
.succeeds()
.stdout_is("foo.dat: OK\n");
}

/// This test checks that when a file contains several checksum lines
/// with different encoding, the decoding still works.
#[test]
fn test_check_mix_hexa_base64() {
let b64 = "BLAKE2b-128 (foo1.dat) = BBNuJPhdRwRlw9tm5Y7VbA==";
let hex = "BLAKE2b-128 (foo2.dat) = 04136e24f85d470465c3db66e58ed56c";

let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

at.write("foo1.dat", "foo");
at.write("foo2.dat", "foo");

at.write("hex_b64", &format!("{}\n{}", hex, b64));
at.write("b64_hex", &format!("{}\n{}", b64, hex));

scene
.ucmd()
.arg("--check")
.arg(at.subdir.join("hex_b64"))
.succeeds()
.stdout_is("foo2.dat: OK\nfoo1.dat: OK\n")
.no_stderr();

scene
.ucmd()
.arg("--check")
.arg(at.subdir.join("b64_hex"))
.succeeds()
.stdout_is("foo1.dat: OK\nfoo2.dat: OK\n")
.no_stderr();
}

0 comments on commit 1d56096

Please sign in to comment.