use super::*; use serde_json::json; const ROW: &str = "00000000-0000-4000-8000-0000000000c1"; fn vmk() -> Vmk { Vmk::from_bytes([26u8; 32]) } #[test] fn ten_earlier_passwords_are_kept_newest_first_and_none_twice() { let mut history = History::default(); for n in 0..12 { history.push(&format!("SYNTHETIC-{n:02}"), &format!("2026-11-{:02}T00:00:00Z", n + 1)); } assert_eq!(history.0.len(), HISTORY_MAX); assert_eq!(history.0[0].password, "SYNTHETIC-11"); assert_eq!(history.0[9].password, "SYNTHETIC-02", "the two oldest are gone"); history.push("SYNTHETIC-11", "2026-12-01T00:00:00Z"); assert_eq!(history.0[0].until, "2026-11-12T00:00:00Z", "the newest is not kept twice"); history.push("", "2026-12-01T00:00:00Z"); assert_eq!(history.0.len(), HISTORY_MAX); } #[test] fn the_history_seals_into_its_own_column_and_opens_only_under_the_vault() { let mut history = History::default(); history.push("SYNTHETIC-before", "2026-11-01T00:00:00Z"); let sealed = history.seal(&vmk(), ROW, 2).unwrap(); assert!(sealed.starts_with("v2:") && !sealed.contains("SYNTHETIC")); let mut row = Map::new(); row.insert(HISTORY_ENC.into(), json!(sealed)); row.insert("vmk_version".into(), json!(2)); assert_eq!(History::open(&row, ROW, &vmk()).unwrap(), history); assert!(History::open(&row, ROW, &Vmk::from_bytes([27u8; 32])).is_err(), "another vault key does not open it"); assert!(History::open(&row, "another-row", &vmk()).is_err(), "it is bound to its row"); assert_eq!(History::open(&Map::new(), ROW, &vmk()).unwrap(), History::default(), "no column, no history"); } #[test] fn the_bin_keeps_a_secret_thirty_days() { let day = 86_400; assert!(!trash_due(0, 30 * day)); assert!(trash_due(0, 30 * day + 1)); assert!(!trash_due(100, 50), "a clock behind the stamp keeps it"); }