feat(common): PendingStatus wire type + Default impl on PendingFlag
PendingStatus carries an explicit 'present' bool next to a PendingFlag because zvariant doesn't support Option<T>. Two new serde tests. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -36,7 +36,7 @@ pub struct Credential {
|
|||||||
pub created_unix: u64,
|
pub created_unix: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, zvariant::Type)]
|
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, zvariant::Type)]
|
||||||
pub struct PendingFlag {
|
pub struct PendingFlag {
|
||||||
pub required_methods: Vec<Method>,
|
pub required_methods: Vec<Method>,
|
||||||
pub created_unix: u64,
|
pub created_unix: u64,
|
||||||
@@ -46,6 +46,13 @@ pub struct PendingFlag {
|
|||||||
pub re_enroll: bool,
|
pub re_enroll: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, zvariant::Type)]
|
||||||
|
pub struct PendingStatus {
|
||||||
|
pub present: bool,
|
||||||
|
/// Contents are the default when `!present`; consumer must check `present` first.
|
||||||
|
pub flag: PendingFlag,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, zvariant::Type)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, zvariant::Type)]
|
||||||
pub struct Violation {
|
pub struct Violation {
|
||||||
pub user: String,
|
pub user: String,
|
||||||
@@ -119,4 +126,30 @@ mod tests {
|
|||||||
let back: Credential = serde_json::from_str(&json).unwrap();
|
let back: Credential = serde_json::from_str(&json).unwrap();
|
||||||
assert_eq!(c, back);
|
assert_eq!(c, back);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pending_status_serde() {
|
||||||
|
let s = PendingStatus {
|
||||||
|
present: true,
|
||||||
|
flag: PendingFlag {
|
||||||
|
required_methods: vec![Method::Fido2],
|
||||||
|
created_unix: 1_700_000_000,
|
||||||
|
deadline_unix: 0,
|
||||||
|
re_enroll: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
let bytes = serde_json::to_vec(&s).unwrap();
|
||||||
|
let back: PendingStatus = serde_json::from_slice(&bytes).unwrap();
|
||||||
|
assert_eq!(s, back);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pending_status_default_when_absent() {
|
||||||
|
let s = PendingStatus {
|
||||||
|
present: false,
|
||||||
|
flag: PendingFlag::default(),
|
||||||
|
};
|
||||||
|
assert!(!s.present);
|
||||||
|
assert!(s.flag.required_methods.is_empty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user