From 1a5896c3be4fe2d3aed815ea3ccd7aac67e69da1 Mon Sep 17 00:00:00 2001 From: Alexandra Date: Tue, 8 Apr 2025 20:12:48 +0200 Subject: [PATCH] mcookie: fix and add tests --- tests/by-util/test_mcookie.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/by-util/test_mcookie.rs b/tests/by-util/test_mcookie.rs index 5260340..a84e73f 100644 --- a/tests/by-util/test_mcookie.rs +++ b/tests/by-util/test_mcookie.rs @@ -79,7 +79,7 @@ fn test_char_device_input() { .arg("/dev/zero") .succeeds(); - res_verbose.stderr_contains("Got 1024 bytes from /dev/zero"); + res_verbose.stderr_contains("Got 4096 bytes from /dev/zero"); res_verbose.stderr_contains("Got 128 bytes from randomness source"); // Ensure internal randomness is still added let stdout_verbose = res_verbose.stdout_str().trim_end(); @@ -177,3 +177,36 @@ fn test_not_existing_file() { file2.path().to_str().unwrap() )); } + +#[test] +fn test_max_size_limits() { + let mut file = NamedTempFile::new().unwrap(); + const CONTENT: [u8; 5500] = [1; 5500]; + file.write_all(&CONTENT).unwrap(); + + let res_default = new_ucmd!() + .arg("--verbose") + .arg("-f") + .arg(file.path()) + .succeeds(); + + // Ensure we only read up to 4096 bytes + res_default.stderr_contains(format!( + "Got 4096 bytes from {}", + file.path().to_str().unwrap() + )); + + let res_zero = new_ucmd!() + .arg("--verbose") + .arg("-f") + .arg(file.path()) + .arg("-m") + .arg("0") + .succeeds(); + + // Ensure we read up 4096 bytes + res_zero.stderr_contains(format!( + "Got 4096 bytes from {}", + file.path().to_str().unwrap() + )); +}