From d4aba09cab72dddb1798891b08392893b635b7ce Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Mon, 23 Nov 2026 12:19:39 +0100 Subject: [PATCH] leleka-inference: tests of the verification flags (the policy belongs to its command line, not to the process) --- .../src/bin/leleka-inference/startup.rs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/desktop-core/src/bin/leleka-inference/startup.rs b/desktop-core/src/bin/leleka-inference/startup.rs index b4c7ed35..e767cf9e 100644 --- a/desktop-core/src/bin/leleka-inference/startup.rs +++ b/desktop-core/src/bin/leleka-inference/startup.rs @@ -176,3 +176,33 @@ fn inherited_archive( _ => None, }) } + +#[cfg(test)] +mod verification_flag_tests { + use super::*; + + fn take(args: &[&str]) -> (Result, Vec) { + let mut args: Vec = 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()); + } +}