-
-
Notifications
You must be signed in to change notification settings - Fork 120
fix: emit ChatModified event when can_send changes during secure join
#7735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1370,3 +1370,109 @@ gU6dGXsFMe/RpRHrIAkMAaM5xkxMDRuRJDxiUdS/X+Y8 | |||||
|
|
||||||
| Ok(()) | ||||||
| } | ||||||
|
|
||||||
| #[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||||||
| async fn test_secure_join_group_can_send_and_event() -> Result<()> { | ||||||
| let mut tcm = TestContextManager::new(); | ||||||
| let alice = tcm.alice().await; | ||||||
| let bob = tcm.bob().await; | ||||||
|
|
||||||
| let alice_chatid = chat::create_group(&alice, "the chat").await?; | ||||||
|
|
||||||
| tcm.section("Step 1: Generate QR-code, secure-join implied by chatid"); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
If the reader doesn't already know what the comment means, it is more confusing than helpful. And if you want to know, you can just go to |
||||||
| let qr = get_securejoin_qr(&alice, Some(alice_chatid)).await.unwrap(); | ||||||
|
|
||||||
| tcm.section("Step 2: Bob scans QR-code, sends vg-request"); | ||||||
| let bob_chatid = join_securejoin(&bob, &qr).await?; | ||||||
| assert_eq!( | ||||||
| Chat::load_from_db(&bob, bob_chatid) | ||||||
| .await? | ||||||
| .can_send(&bob) | ||||||
| .await?, | ||||||
| false | ||||||
| ); | ||||||
|
|
||||||
| let sent = bob.pop_sent_msg().await; | ||||||
| let _ = alice.parse_msg(&sent).await; | ||||||
|
|
||||||
| tcm.section("Step 3: Alice receives vg-request, sends vg-auth-required"); | ||||||
| alice.recv_msg_trash(&sent).await; | ||||||
| let sent = alice.pop_sent_msg().await; | ||||||
| let _ = bob.parse_msg(&sent).await; | ||||||
|
|
||||||
| tcm.section("Step 4: Bob receives vg-auth-required, sends vg-request-with-auth"); | ||||||
| bob.recv_msg_trash(&sent).await; | ||||||
| let sent = bob.pop_sent_msg().await; | ||||||
|
|
||||||
| tcm.section("Step 5+6: Alice receives vg-request-with-auth, sends vg-member-added"); | ||||||
| alice.recv_msg_trash(&sent).await; | ||||||
| let sent = alice.pop_sent_msg().await; | ||||||
|
|
||||||
| bob.evtracker.clear_events(); | ||||||
| assert_eq!( | ||||||
| Chat::load_from_db(&bob, bob_chatid) | ||||||
| .await? | ||||||
| .can_send(&bob) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better use |
||||||
| .await?, | ||||||
| false | ||||||
| ); | ||||||
|
|
||||||
| tcm.section("Step 7: Bob receives vg-member-added"); | ||||||
| bob.recv_msg(&sent).await; | ||||||
|
|
||||||
| bob.evtracker | ||||||
| .get_matching(|typ| typ == &EventType::ChatModified(bob_chatid)) | ||||||
| .await; | ||||||
|
|
||||||
| assert_eq!( | ||||||
| Chat::load_from_db(&bob, bob_chatid) | ||||||
| .await? | ||||||
| .can_send(&bob) | ||||||
| .await?, | ||||||
| true | ||||||
| ); | ||||||
|
|
||||||
| Ok(()) | ||||||
| } | ||||||
|
|
||||||
| #[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||||||
| async fn test_secure_join_contact_can_send_and_event() -> Result<()> { | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's already
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The used way of awaiting events drops all other events that are emitted. So when order of events is stable it could work to use the existing method. I thought a new test, which only tests for the event is cleaner and has less risk of breaking an existing test. Also in this particular test there is this line core/src/securejoin/securejoin_tests.rs Line 139 in 659d21a
which already seemed to change can_send, because it already ingests alice's key.
Thought about it, but since that test is already hard to understand for me, I did not want to make it even more complex and more importantly I don't want to accidentally break an important test by editing it to test something less important.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall i agree with adding new test code to not intersect with checks for
|
||||||
| let mut tcm = TestContextManager::new(); | ||||||
| let alice = tcm.alice().await; | ||||||
| let bob = tcm.bob().await; | ||||||
|
|
||||||
| tcm.section("Step 1: Generate QR-code, ChatId(0) indicates setup-contact"); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| let qr = get_securejoin_qr(&alice, None).await?; | ||||||
|
|
||||||
| tcm.section("Step 2: Bob scans QR-code, sends vc-request"); | ||||||
| let bob_chat_id = join_securejoin(&bob.ctx, &qr).await?; | ||||||
|
|
||||||
| let bob_chat = Chat::load_from_db(&bob, bob_chat_id).await?; | ||||||
| assert_eq!( | ||||||
| bob_chat.why_cant_send(&bob).await?, | ||||||
| Some(CantSendReason::MissingKey) | ||||||
| ); | ||||||
|
|
||||||
| let sent = bob.pop_sent_msg().await; | ||||||
|
|
||||||
| tcm.section("Step 3: Alice receives vc-request, sends vc-auth-required"); | ||||||
| alice.recv_msg_trash(&sent).await; | ||||||
|
|
||||||
| let sent = alice.pop_sent_msg().await; | ||||||
| let bob_chat = bob.get_chat(&alice).await; | ||||||
| assert_eq!(bob_chat.can_send(&bob).await?, false); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why checking again here? Bob hasn't received any message from Alice since the previous check. I think that the previous check should just be moved here, it's better because it also checks the reason |
||||||
| bob.evtracker.clear_events(); | ||||||
|
|
||||||
| tcm.section("Step 4: Bob receives vc-auth-required, sends vc-request-with-auth"); | ||||||
| bob.recv_msg_trash(&sent).await; | ||||||
|
|
||||||
| bob.evtracker | ||||||
| .get_matching(|typ| typ == &EventType::ChatModified(bob_chat_id)) | ||||||
| .await; | ||||||
|
|
||||||
| let bob_chat = bob.get_chat(&alice).await; | ||||||
| assert_eq!(bob_chat.can_send(&bob).await?, true); | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NB: Bob already can send, but if |
||||||
|
|
||||||
| // Rest of the steps (4-7) are irrelevant for this test | ||||||
| Ok(()) | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.