leleka-inference: tests of the verification flags (the policy belongs to its command line, not to the process)

This commit is contained in:
Pavlo Ratushnyi
2026-11-23 12:19:39 +01:00
parent 82c306b49e
commit d4aba09cab
@@ -176,3 +176,33 @@ fn inherited_archive(
_ => None,
})
}
#[cfg(test)]
mod verification_flag_tests {
use super::*;
fn take(args: &[&str]) -> (Result<VerificationFlags, Failure>, Vec<String>) {
let mut args: Vec<String> = args.iter().map(|arg| (*arg).to_owned()).collect();
(take_verification_flags(&mut args), args)
}
#[test]
fn the_stamp_directory_and_the_attestation_are_the_policy_of_this_command_line_only() {
let (flags, rest) =
take(&["--verify-only", "--verify-stamps", "/stamps", "--verify-rehash", "--kar-attested-by-stamp", "--x"]);
let flags = flags.unwrap();
assert!(flags.verify_only && flags.policy.archive_attested());
assert_eq!(flags.policy.stamps().map(|stamps| stamps.dir().to_owned()), Some(PathBuf::from("/stamps")));
assert_eq!(rest, ["--x"]);
// another command line in the same process is not touched by the first one
let (plain, _) = take(&["--x"]);
let plain = plain.unwrap();
assert!(!plain.verify_only && !plain.policy.archive_attested() && plain.policy.stamps().is_none());
}
#[test]
fn a_rehash_without_a_stamp_directory_and_an_empty_directory_are_refused() {
assert!(take(&["--verify-rehash"]).0.is_err());
assert!(take(&["--verify-stamps", ""]).0.is_err());
}
}