This commit is contained in:
yves committed 2026-11-20 23:17:15 +01:00
1 parent 10af480218
commit 47b73e6935
11 files changed
+470 -28

No files matched your search

+64 -3
View File
@@ -5,7 +5,7 @@ use meow_core::contact::Contact;
use meow_core::server::{ServerInfo, ServerKeys};
use meow_crypto::password::KdfParams;
use meow_store::blocks::BLOCK_SIZE;
use meow_store::{Batch, Content, Error, HistoryEntry, PendingAck, SpaceId, State, Store};
use meow_store::{Batch, Content, Error, HistoryEntry, PendingAck, SpaceId, State, Status, Store};
const KDF: KdfParams = KdfParams::INSECURE_TEST;
const MAIN: SpaceId = SpaceId::MAIN;
@@ -40,6 +40,7 @@ fn text(c: &Contact, t: &str) -> HistoryEntry {
sent_at_ms: 1,
received_at: 2,
content: Content::Text(t.into()),
status: Status::Delivered,
}
}
@@ -141,6 +142,7 @@ fn state_segments_and_files() {
let later = Batch {
history: vec![text(&bob, "last")],
files: vec![],
status: vec![],
};
store.save(MAIN, &state, later).unwrap();
drop(store);
@@ -206,12 +208,14 @@ fn hidden_spaces() {
let batch = Batch {
history: vec![text(&secret, "for your eyes only")],
files: vec![],
status: vec![],
};
store.save(h, &hidden, batch).unwrap();
// A contact of another space cannot receive history here.
let wrong = Batch {
history: vec![text(&secret, "x")],
files: vec![],
status: vec![],
};
assert!(store.save(MAIN, &main, wrong).is_err());
assert!(matches!(
@@ -254,7 +258,8 @@ fn hidden_spaces() {
fn an_attacker_without_password_sees_only_uniform_blocks() {
let (path, dir) = tmp();
let s = server();
let bob = contact("bob", &s);
// Needles must be long: short ones (e.g. 3 bytes) occur by chance in megabytes of random filler.
let bob = contact("bob-the-contact-name", &s);
let mut store = Store::create(&path, "alice-the-nickname", "pw", KDF, false).unwrap();
let state = State {
nickname: "alice-the-nickname".into(),
@@ -265,6 +270,7 @@ fn an_attacker_without_password_sees_only_uniform_blocks() {
let batch = Batch {
history: vec![text(&bob, "very secret text one"), text(&bob, "very secret text two")],
files: vec![],
status: vec![],
};
store.save(MAIN, &state, batch).unwrap();
let h = store.create_space("hidden").unwrap();
@@ -293,7 +299,7 @@ fn an_attacker_without_password_sees_only_uniform_blocks() {
let wal = std::fs::metadata(format!("{}-wal", path.display())).map_or(0, |m| m.len());
assert_eq!(wal, 0);
let raw = std::fs::read(&path).unwrap();
for needle in ["alice-the-nickname", "very secret", "bob", "http://s"] {
for needle in ["alice-the-nickname", "very secret text", "bob-the-contact-name"] {
assert!(
!raw.windows(needle.len()).any(|w| w == needle.as_bytes()),
"{needle:?} found in clear"
@@ -342,6 +348,7 @@ fn rewrites_move_objects_and_wipe_old_blocks() {
Batch {
history: vec![text(&bob, "hello")],
files: vec![],
status: vec![],
},
)
.unwrap();
@@ -417,3 +424,57 @@ fn outbox_items_persist_per_space() {
assert!(store.load(h2).unwrap().outbox.is_empty());
let _ = std::fs::remove_dir_all(dir);
}
#[test]
fn status_only_moves_forward_in_any_segment() {
let (path, dir) = tmp();
let s = server();
let bob = contact("bob", &s);
let mut store = Store::create(&path, "alice", "pw", KDF, false).unwrap();
let mut state = store.load(MAIN).unwrap();
state.contacts.push(bob.clone());
let filler = "x".repeat(1000);
let msgs: Vec<HistoryEntry> = (0..30)
.map(|i| HistoryEntry {
outbound: true,
status: Status::Queued,
..text(&bob, &format!("{i}{filler}"))
})
.collect();
let (first, last) = (msgs[0].id.clone(), msgs[29].id.clone());
store
.save(
MAIN,
&state,
Batch {
history: msgs,
..Batch::default()
},
)
.unwrap();
// First message is in the oldest segment, last one in the latest.
let upd = |v: Vec<(Vec<u8>, Status)>| Batch {
status: v.into_iter().map(|(m, s)| (bob.id.clone(), m, s)).collect(),
..Batch::default()
};
store
.save(
MAIN,
&state,
upd(vec![
(first.clone(), Status::Read),
(last.clone(), Status::Delivered),
(b"unknown".to_vec(), Status::Read),
]),
)
.unwrap();
// A late, lower status does not go back.
store
.save(MAIN, &state, upd(vec![(first.clone(), Status::Sent)]))
.unwrap();
let all = store.full_history(MAIN, &bob.id).unwrap();
assert_eq!(all[0].status, Status::Read);
assert_eq!(all[29].status, Status::Delivered);
assert!(all[1..29].iter().all(|e| e.status == Status::Queued));
let _ = std::fs::remove_dir_all(dir);
}