feat: add PendingFlag, PolicyApplyResult, Violation types

This commit is contained in:
michael
2026-04-26 20:47:06 -07:00
parent 4d40c1a8b9
commit 22aa37662a

View File

@@ -86,6 +86,29 @@ pub struct Policy {
pub firstrun: Firstrun, pub firstrun: Firstrun,
} }
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, zvariant::Type)]
pub struct PendingFlag {
pub required_methods: Vec<Method>,
pub created_unix: u64,
/// 0 = no deadline (matches the design doc's `deadline_hours = 0` convention).
/// D-Bus has no native option type, so the sentinel is the wire-friendly choice.
pub deadline_unix: u64,
pub re_enroll: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, zvariant::Type)]
pub struct Violation {
pub user: String,
pub stack: String,
pub reason: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, zvariant::Type)]
pub struct PolicyApplyResult {
pub applied: bool,
pub violations: Vec<Violation>,
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
@@ -125,6 +148,26 @@ mod tests {
assert_eq!(p, back); assert_eq!(p, back);
} }
#[test]
fn pending_flag_serde() {
let f = PendingFlag {
required_methods: vec![Method::Fido2],
created_unix: 1_700_000_000,
deadline_unix: 0,
re_enroll: false,
};
let json = serde_json::to_string(&f).unwrap();
let back: PendingFlag = serde_json::from_str(&json).unwrap();
assert_eq!(f, back);
}
#[test]
fn policy_apply_result_ok_no_violations() {
let r = PolicyApplyResult { applied: true, violations: vec![] };
assert!(r.applied);
assert!(r.violations.is_empty());
}
#[test] #[test]
fn credential_roundtrips_via_serde() { fn credential_roundtrips_via_serde() {
let c = Credential { let c = Credential {