core_crypto/mls/conversation/
orphan_welcome.rs

1//! This deals with DS inconsistencies. When a Welcome message is received, the client might have
2//! already deleted its associated KeyPackage (and encryption key).
3//! Feel free to remove this when this is no longer a problem !!!
4
5#[cfg(test)]
6mod tests {
7    use crate::CryptoError;
8    use openmls::prelude::KeyPackage;
9    use openmls_traits::OpenMlsCryptoProvider;
10    use wasm_bindgen_test::*;
11
12    use crate::test_utils::*;
13
14    wasm_bindgen_test_configure!(run_in_browser);
15
16    #[apply(all_cred_cipher)]
17    #[wasm_bindgen_test]
18    pub async fn orphan_welcome_should_generate_external_commit(case: TestCase) {
19        run_test_with_client_ids(case.clone(), ["alice", "bob"], move |[alice_central, bob_central]| {
20            Box::pin(async move {
21                let id = conversation_id();
22
23                alice_central
24                    .context
25                    .new_conversation(&id, case.credential_type, case.cfg.clone())
26                    .await
27                    .unwrap();
28
29                let bob = bob_central.rand_key_package(&case).await;
30                let bob_kp_ref = KeyPackage::from(bob.clone())
31                    .hash_ref(bob_central.context.mls_provider().await.unwrap().crypto())
32                    .unwrap();
33
34                // Alice invites Bob with a KeyPackage...
35                let welcome = alice_central
36                    .context
37                    .add_members_to_conversation(&id, vec![bob])
38                    .await
39                    .unwrap()
40                    .welcome;
41
42                // ...Bob deletes locally (with the associated private key) before processing the Welcome
43                bob_central.context.delete_keypackages(&[bob_kp_ref]).await.unwrap();
44
45                // in that case a dedicated error is thrown for clients to identify this case
46                // and rejoin with an external commit
47                let process_welcome = bob_central
48                    .context
49                    .process_welcome_message(welcome.into(), case.custom_cfg())
50                    .await;
51                assert!(matches!(process_welcome.unwrap_err(), CryptoError::OrphanWelcome));
52            })
53        })
54        .await;
55    }
56}