[vault] Provision: display offers (store display, outcome confirmed; display stores nothing, confirmed only for a display offer)
This commit is contained in:
@@ -27,6 +27,8 @@ pub enum Store {
|
|||||||
Claude,
|
Claude,
|
||||||
/// The cloud Claude Code store.
|
/// The cloud Claude Code store.
|
||||||
Cloud,
|
Cloud,
|
||||||
|
/// Shown once on the card and stored nowhere: a display offer (core 0.12.0).
|
||||||
|
Display,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
@@ -46,6 +48,8 @@ pub enum Outcome {
|
|||||||
Invalid,
|
Invalid,
|
||||||
/// Nobody answered within five minutes.
|
/// Nobody answered within five minutes.
|
||||||
Expired,
|
Expired,
|
||||||
|
/// A display offer: Mark typed the code the phone shows, Custos checked it and sent it (core 0.12.0).
|
||||||
|
Confirmed,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// One audit entry. Append-only: nothing edits or removes one.
|
/// One audit entry. Append-only: nothing edits or removes one.
|
||||||
@@ -133,6 +137,17 @@ impl ProvisionEntry {
|
|||||||
if self.code.len() != 6 || !self.code.bytes().all(|c| c.is_ascii_digit()) {
|
if self.code.len() != 6 || !self.code.bytes().all(|c| c.is_ascii_digit()) {
|
||||||
return Err(Error::Provision("the match code is not six digits"));
|
return Err(Error::Provision("the match code is not six digits"));
|
||||||
}
|
}
|
||||||
|
// A display offer stores nothing; `confirmed` is its outcome and nobody else's.
|
||||||
|
if self.store == Store::Display {
|
||||||
|
if self.direction != Direction::Offer {
|
||||||
|
return Err(Error::Provision("a display is an offer"));
|
||||||
|
}
|
||||||
|
if matches!(self.outcome, Outcome::Accepted | Outcome::Approved | Outcome::Generated) || self.replaced {
|
||||||
|
return Err(Error::Provision("a display offer stores nothing"));
|
||||||
|
}
|
||||||
|
} else if self.outcome == Outcome::Confirmed {
|
||||||
|
return Err(Error::Provision("only a display offer is confirmed"));
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,3 +156,55 @@ fn an_entry_has_no_member_that_could_hold_a_secret() {
|
|||||||
let s = serde_json::to_string(&e).unwrap();
|
let s = serde_json::to_string(&e).unwrap();
|
||||||
assert!(!s.contains("\"run\"") && !s.contains("\"kind\"") && s.contains("\"out-of-scope\""), "{s}");
|
assert!(!s.contains("\"run\"") && !s.contains("\"kind\"") && s.contains("\"out-of-scope\""), "{s}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- display offers (core 0.12.0) ----
|
||||||
|
|
||||||
|
fn display(i: i64, outcome: Outcome) -> ProvisionEntry {
|
||||||
|
ProvisionEntry {
|
||||||
|
item: "arca/authelia-mark".into(),
|
||||||
|
store: Store::Display,
|
||||||
|
kind: Some("totp".into()),
|
||||||
|
run: None,
|
||||||
|
..entry(i, outcome)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_display_offer_is_recorded_as_confirmed_and_survives_a_reopen() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let path = dir.path().join("v.custos");
|
||||||
|
let mut v = Vault::create(&SecretString::from("pw"), FAST).unwrap();
|
||||||
|
for (i, o) in [Outcome::Confirmed, Outcome::Refused, Outcome::Expired, Outcome::Invalid, Outcome::OutOfScope]
|
||||||
|
.into_iter()
|
||||||
|
.enumerate()
|
||||||
|
{
|
||||||
|
v.provision_record(display(i as i64, o)).unwrap();
|
||||||
|
}
|
||||||
|
let s = serde_json::to_string(&v.provision_audit()[0]).unwrap();
|
||||||
|
assert!(s.contains(r#""store":"display""#) && s.contains(r#""outcome":"confirmed""#), "{s}");
|
||||||
|
v.save(&path).unwrap();
|
||||||
|
let back = Vault::open_file(&path, &SecretString::from("pw")).unwrap();
|
||||||
|
assert_eq!(back.provision_audit(), v.provision_audit());
|
||||||
|
assert_eq!(back.provision_audit()[0].outcome, Outcome::Confirmed);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn display_and_confirmed_go_only_together_and_store_nothing() {
|
||||||
|
let mut v = Vault::create(&SecretString::from("pw"), FAST).unwrap();
|
||||||
|
let bad: Vec<ProvisionEntry> = vec![
|
||||||
|
// Nothing is stored, so nothing is accepted, approved, generated or replaced.
|
||||||
|
display(0, Outcome::Accepted),
|
||||||
|
display(0, Outcome::Approved),
|
||||||
|
display(0, Outcome::Generated),
|
||||||
|
ProvisionEntry { replaced: true, ..display(0, Outcome::Confirmed) },
|
||||||
|
// A display is an offer.
|
||||||
|
ProvisionEntry { direction: Direction::Ask, ..display(0, Outcome::Confirmed) },
|
||||||
|
// Confirmed is a display offer's outcome only.
|
||||||
|
entry(0, Outcome::Confirmed),
|
||||||
|
ProvisionEntry { store: Store::Claude, ..entry(0, Outcome::Confirmed) },
|
||||||
|
];
|
||||||
|
for (i, e) in bad.into_iter().enumerate() {
|
||||||
|
assert!(matches!(v.provision_record(e), Err(Error::Provision(_))), "case {i}");
|
||||||
|
}
|
||||||
|
assert!(v.provision_audit().is_empty());
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user