store in client
This commit is contained in:
1 parent
64ee239d1d
commit
a520ddb557
10 files changed
+575
-347
No files matched your search
@@ -107,11 +107,23 @@ async fn file_and_server_invitations_then_messaging() {
|
||||
std::fs::write(&f, b"file content").unwrap();
|
||||
bob.send_file("alice", &f).await.unwrap();
|
||||
let ev = alice.sync(Duration::ZERO).await.unwrap();
|
||||
assert!(ev.contains(&Event::File {
|
||||
contact: "bob".into(),
|
||||
name: "note.txt".into(),
|
||||
data: b"file content".to_vec()
|
||||
}));
|
||||
let file_id = ev
|
||||
.iter()
|
||||
.find_map(|e| match e {
|
||||
Event::File {
|
||||
contact,
|
||||
id,
|
||||
name,
|
||||
data,
|
||||
} if contact == "bob" && name == "note.txt" => {
|
||||
assert_eq!(data, b"file content");
|
||||
Some(id.clone())
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.expect("file event");
|
||||
// The content is kept in the store.
|
||||
assert_eq!(alice.file("bob", &file_id).unwrap().unwrap(), b"file content");
|
||||
|
||||
// ── server invitation ──
|
||||
let url = bob
|
||||
@@ -148,7 +160,7 @@ async fn file_and_server_invitations_then_messaging() {
|
||||
let path = dir.join("alice.mwid2");
|
||||
drop(alice);
|
||||
let waiter = tokio::spawn(async move {
|
||||
let mut alice = MeowClient::open(&path, "pw", KdfParams::INSECURE_TEST).await.unwrap();
|
||||
let mut alice = MeowClient::open(&path, "pw").await.unwrap();
|
||||
let start = std::time::Instant::now();
|
||||
let ev = alice.sync(Duration::from_secs(20)).await.unwrap();
|
||||
(texts(&ev), start.elapsed())
|
||||
@@ -161,20 +173,14 @@ async fn file_and_server_invitations_then_messaging() {
|
||||
|
||||
// ── one process at a time per identity ──
|
||||
assert!(matches!(
|
||||
MeowClient::open(&dir.join("bob.mwid2"), "pw", KdfParams::INSECURE_TEST).await,
|
||||
MeowClient::open(&dir.join("bob.mwid2"), "pw").await,
|
||||
Err(meow_client::Error::Locked(_))
|
||||
));
|
||||
drop(bob);
|
||||
|
||||
// ── persistence & wrong password ──
|
||||
assert!(
|
||||
MeowClient::open(&dir.join("bob.mwid2"), "nope", KdfParams::INSECURE_TEST)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
let bob2 = MeowClient::open(&dir.join("bob.mwid2"), "pw", KdfParams::INSECURE_TEST)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(MeowClient::open(&dir.join("bob.mwid2"), "nope").await.is_err());
|
||||
let bob2 = MeowClient::open(&dir.join("bob.mwid2"), "pw").await.unwrap();
|
||||
assert_eq!(bob2.contacts().len(), 2);
|
||||
assert_eq!(bob2.history("alice").unwrap().len(), 6); // 5 sent + "hi bob"
|
||||
|
||||
@@ -306,7 +312,7 @@ async fn no_message_lost_when_the_client_dies() {
|
||||
assert_eq!(raw_pull(&server, &mailbox).await.len(), 1);
|
||||
let path = dir.join("alice.mwid2");
|
||||
drop(alice);
|
||||
let mut alice = MeowClient::open(&path, "pw", KdfParams::INSECURE_TEST).await.unwrap();
|
||||
let mut alice = MeowClient::open(&path, "pw").await.unwrap();
|
||||
assert!(alice.sync(Duration::ZERO).await.unwrap().is_empty());
|
||||
store.drop_acks.store(false, std::sync::atomic::Ordering::SeqCst);
|
||||
assert!(alice.sync(Duration::ZERO).await.unwrap().is_empty());
|
||||
@@ -337,3 +343,75 @@ async fn no_message_lost_when_the_client_dies() {
|
||||
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
// ───────────── hidden spaces (roadmap lot 4.5) ─────────────
|
||||
|
||||
/// File invitation from `a` to `b`, completed.
|
||||
async fn connect(a: &mut MeowClient, b: &mut MeowClient, b_name: &str) {
|
||||
let offer = a.create_invitation(b_name, &[], "", 3600).await.unwrap();
|
||||
let answer = b.answer_invitation(&offer, None, &[]).await.unwrap();
|
||||
let confirm = a.accept_answer(&answer).await.unwrap();
|
||||
b.finalize_invitation(&confirm).await.unwrap();
|
||||
a.sync(Duration::ZERO).await.unwrap();
|
||||
}
|
||||
|
||||
fn names(c: &MeowClient) -> Vec<String> {
|
||||
c.contacts().iter().map(|k| k.name.clone()).collect()
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn hidden_contacts() {
|
||||
let servers = vec![spawn_server().await];
|
||||
let dir = tmpdir();
|
||||
let path = dir.join("alice.mwid2");
|
||||
let mut alice = client(&dir, "alice", &servers).await;
|
||||
let mut bob = client(&dir, "bob", &servers).await;
|
||||
let mut carol = client(&dir, "carol", &servers).await;
|
||||
connect(&mut alice, &mut bob, "bob").await;
|
||||
connect(&mut alice, &mut carol, "carol").await;
|
||||
bob.send_text("alice", "before hiding").await.unwrap();
|
||||
assert_eq!(texts(&alice.sync(Duration::ZERO).await.unwrap()), vec!["before hiding"]);
|
||||
|
||||
// Hide bob, with his history.
|
||||
alice.hide_contact("bob", "bob-pw").await.unwrap();
|
||||
assert!(alice.is_hidden("bob").unwrap());
|
||||
assert!(!alice.is_hidden("carol").unwrap());
|
||||
assert_eq!(alice.history("bob").unwrap().len(), 1);
|
||||
drop(alice);
|
||||
|
||||
// Without the hidden password, bob does not exist and is not even polled.
|
||||
let mut alice = MeowClient::open(&path, "pw").await.unwrap();
|
||||
assert_eq!(names(&alice), vec!["carol"]);
|
||||
assert!(alice.history("bob").is_err());
|
||||
bob.send_text("alice", "while locked").await.unwrap();
|
||||
carol.send_text("alice", "hi").await.unwrap();
|
||||
assert_eq!(texts(&alice.sync(Duration::ZERO).await.unwrap()), vec!["hi"]);
|
||||
|
||||
// With it, bob is back and his messages were waiting on the server.
|
||||
assert!(!alice.unlock("wrong").await.unwrap());
|
||||
assert!(alice.unlock("bob-pw").await.unwrap());
|
||||
assert_eq!(names(&alice), vec!["carol", "bob"]);
|
||||
assert_eq!(texts(&alice.sync(Duration::ZERO).await.unwrap()), vec!["while locked"]);
|
||||
alice.send_text("bob", "from the hidden side").await.unwrap();
|
||||
assert_eq!(
|
||||
texts(&bob.sync(Duration::ZERO).await.unwrap()),
|
||||
vec!["from the hidden side"]
|
||||
);
|
||||
assert_eq!(alice.history("bob").unwrap().len(), 3);
|
||||
|
||||
// Several contacts can share a hidden space.
|
||||
alice.hide_contact("carol", "bob-pw").await.unwrap();
|
||||
drop(alice);
|
||||
let mut alice = MeowClient::open(&path, "pw").await.unwrap();
|
||||
assert!(names(&alice).is_empty());
|
||||
assert!(alice.unlock("bob-pw").await.unwrap());
|
||||
assert_eq!(names(&alice), vec!["bob", "carol"]);
|
||||
|
||||
// Back to the main space.
|
||||
alice.reveal_contact("bob").await.unwrap();
|
||||
drop(alice);
|
||||
let alice = MeowClient::open(&path, "pw").await.unwrap();
|
||||
assert_eq!(names(&alice), vec!["bob"]);
|
||||
assert_eq!(alice.history("bob").unwrap().len(), 3);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
Reference in new issue
Block a user