[vault] Standing approvals: a rule's use count saturates instead of overflowing (a stored count at its end made the next standing signature panic in debug builds); v0.16.1

This commit is contained in:
2026-11-11 16:19:35 +01:00
parent 95613f4ed0
commit 2c2d56b856
4 changed files with 39 additions and 14 deletions
+25
View File
@@ -788,6 +788,31 @@ mod tests {
assert_eq!(back.standing_rules()[0].uses, 1);
}
#[test]
fn a_rule_whose_count_is_at_its_end_still_signs() {
use crate::signing::{Approval, Context, Request, SignKind, Via};
let v = vault_with_a_standing_approval();
let json = body_json(&v).replace(r#""uses":1"#, r#""uses":18446744073709551615"#);
let mut full = Vault::open(&with_body(&v, &json), &SecretString::from("pw")).unwrap();
let r = Request {
key: "domi-release".into(),
kind: SignKind::Minisign,
digest: vec![1; 64],
manifest: None,
approval: None,
run: Some("r-43".into()),
context: Context {
repo: "Arca".into(),
pipeline: "release".into(),
file: "a.exe".into(),
..Default::default()
},
via: Via::Local,
};
full.signing_sign(&r, Approval::Standing, NOW + 9).expect("signed, not a panic");
assert_eq!(full.standing_rules()[0].uses, u64::MAX);
}
#[test]
fn a_broken_standing_approval_makes_the_vault_refuse_to_open() {
let v = vault_with_a_standing_approval();
+1 -1
View File
@@ -865,7 +865,7 @@ impl Vault {
if let (Approval::Standing, Some(id)) = (approval, rule)
&& let Some(r) = self.signing.standing.iter_mut().find(|r| r.id == id)
{
r.uses += 1;
r.uses = r.uses.saturating_add(1);
r.last_used = Some(now);
}
Ok(Signed { bytes, sha256 })