mcookie: fix and add tests

This commit is contained in:
Alexandra
2025-04-08 20:12:48 +02:00
parent a402b5e3a5
commit 1a5896c3be

View File

@@ -79,7 +79,7 @@ fn test_char_device_input() {
.arg("/dev/zero") .arg("/dev/zero")
.succeeds(); .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 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(); let stdout_verbose = res_verbose.stdout_str().trim_end();
@@ -177,3 +177,36 @@ fn test_not_existing_file() {
file2.path().to_str().unwrap() 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()
));
}