Skip to content

Commit 4f612fd

Browse files
committed
test: Add test_send_avatar_in_securejoin
1 parent 6a6881b commit 4f612fd

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

src/securejoin/securejoin_tests.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use crate::key::self_fingerprint;
88
use crate::receive_imf::receive_imf;
99
use crate::stock_str::{self, chat_protection_enabled};
1010
use crate::test_utils::{
11-
TestContext, TestContextManager, TimeShiftFalsePositiveNote, get_chat_msg,
11+
AVATAR_64x64_BYTES, AVATAR_64x64_DEDUPLICATED, TestContext, TestContextManager,
12+
TimeShiftFalsePositiveNote, get_chat_msg,
1213
};
1314
use crate::tools::SystemTime;
1415
use std::time::Duration;
@@ -819,3 +820,50 @@ async fn test_wrong_auth_token() -> Result<()> {
819820

820821
Ok(())
821822
}
823+
824+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
825+
async fn test_send_avatar_in_securejoin() -> Result<()> {
826+
async fn exec_securejoin_group(
827+
tcm: &TestContextManager,
828+
scanner: &TestContext,
829+
scanned: &TestContext,
830+
) {
831+
let chat_id = chat::create_group_chat(scanned, ProtectionStatus::Protected, "group")
832+
.await
833+
.unwrap();
834+
let qr = get_securejoin_qr(scanned, Some(chat_id)).await.unwrap();
835+
tcm.exec_securejoin_qr(scanner, scanned, &qr).await;
836+
}
837+
838+
for alice_scans in [true, false] {
839+
let mut tcm = TestContextManager::new();
840+
let alice = &tcm.alice().await;
841+
let bob = &tcm.bob().await;
842+
843+
let file = alice.dir.path().join("avatar.png");
844+
tokio::fs::write(&file, AVATAR_64x64_BYTES).await?;
845+
alice
846+
.set_config(Config::Selfavatar, Some(file.to_str().unwrap()))
847+
.await?;
848+
849+
if alice_scans {
850+
tcm.execute_securejoin(alice, bob).await;
851+
//exec_securejoin_group(&tcm, alice, bob).await;
852+
//exec_securejoin_broadcast(&tcm, alice, bob).await;
853+
// TODO also test these
854+
} else {
855+
tcm.execute_securejoin(bob, alice).await;
856+
//exec_securejoin_group(&tcm, bob, alice).await;
857+
//exec_securejoin_broadcast(&tcm, alice, bob).await;
858+
}
859+
860+
let alice_on_bob = bob.add_or_lookup_contact_no_key(&alice).await;
861+
let avatar = alice_on_bob.get_profile_image(&bob).await?.unwrap();
862+
assert_eq!(
863+
avatar.file_name().unwrap().to_str().unwrap(),
864+
AVATAR_64x64_DEDUPLICATED
865+
);
866+
}
867+
868+
Ok(())
869+
}

0 commit comments

Comments
 (0)