Skip to content

Commit

Permalink
test(cksum): rework test for improperly formatted keeps processing
Browse files Browse the repository at this point in the history
  • Loading branch information
RenjiSann committed Nov 17, 2024
1 parent c9c7acd commit fc60028
Showing 1 changed file with 49 additions and 16 deletions.
65 changes: 49 additions & 16 deletions tests/by-util/test_cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1569,35 +1569,68 @@ fn test_check_mix_hex_base64() {
.stdout_only("foo1.dat: OK\nfoo2.dat: OK\n");
}

#[ignore = "not yet implemented"]
/// This test ensures that an improperly formatted base64 checksum in a file
/// does not interrupt the processing of next lines.
#[test]
fn test_check_incorrectly_formatted_checksum_does_not_stop_processing() {
// The first line contains an incorrectly formatted checksum that can't be
// correctly decoded. This must not prevent the program from looking at the
// rest of the file.
let lines = [
"BLAKE2b-56 (foo1) = GFYEQ7HhAw=", // Should be 2 '=' at the end
"BLAKE2b-56 (foo2) = 18560443b1e103", // OK
];
fn test_check_incorrectly_formatted_checksum_keeps_processing_b64() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch("f");

let good_ck = "MD5 (f) = 1B2M2Y8AsgTpgAmY7PhCfg=="; // OK
let bad_ck = "MD5 (f) = 1B2M2Y8AsgTpgAmY7PhCfg="; // Missing last '='

// Good then Bad
scene
.ucmd()
.arg("--check")
.pipe_in([good_ck, bad_ck].join("\n").as_bytes().to_vec())
.succeeds()
.stdout_contains("f: OK")
.stderr_contains("cksum: WARNING: 1 line is improperly formatted");

// Bad then Good
scene
.ucmd()
.arg("--check")
.pipe_in([bad_ck, good_ck].join("\n").as_bytes().to_vec())
.succeeds()
.stdout_contains("f: OK")
.stderr_contains("cksum: WARNING: 1 line is improperly formatted");
}

/// This test ensures that an improperly formatted hexadecimal checksum in a
/// file does not interrupt the processing of next lines.
#[test]
fn test_check_incorrectly_formatted_checksum_keeps_processing_hex() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch("f");

let good_ck = "MD5 (f) = d41d8cd98f00b204e9800998ecf8427e"; // OK
let bad_ck = "MD5 (f) = d41d8cd98f00b204e9800998ecf8427"; // Missing last

at.write("foo1", "foo");
at.write("foo2", "foo");
at.write("sum", &lines.join("\n"));
// Good then Bad
scene
.ucmd()
.arg("--check")
.pipe_in([good_ck, bad_ck].join("\n").as_bytes().to_vec())
.succeeds()
.stdout_contains("f: OK")
.stderr_contains("cksum: WARNING: 1 line is improperly formatted");

// Bad then Good
scene
.ucmd()
.arg("--check")
.arg(at.subdir.join("sum"))
.pipe_in([bad_ck, good_ck].join("\n").as_bytes().to_vec())
.succeeds()
.stderr_contains("1 line is improperly formatted")
.stdout_contains("foo2: OK");
.stdout_contains("f: OK")
.stderr_contains("cksum: WARNING: 1 line is improperly formatted");
}

/// This module reimplements the cksum-base64.pl GNU test.
mod cksum_base64 {
mod gnu_cksum_base64 {
use super::*;
use crate::common::util::log_info;

Expand Down

0 comments on commit fc60028

Please sign in to comment.