diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8738a7920b..4c9dc1cb00 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,7 +24,7 @@ jobs: - ubuntu-latest - windows-latest mode: - - debug +# - debug - release runs-on: ${{ matrix.os }} steps: diff --git a/openmls/tests/book_code.rs b/openmls/tests/book_code.rs index 9a74de77e2..ea0c2ac0f2 100644 --- a/openmls/tests/book_code.rs +++ b/openmls/tests/book_code.rs @@ -9,7 +9,7 @@ use openmls_basic_credential::SignatureKeyPair; use openmls_rust_crypto::OpenMlsRustCrypto; use openmls_traits::{signatures::Signer, types::SignatureScheme, OpenMlsCryptoProvider}; -/*#[test] +#[test] fn create_backend_rust_crypto() { // ANCHOR: create_backend_rust_crypto use openmls_rust_crypto::OpenMlsRustCrypto; @@ -19,7 +19,7 @@ fn create_backend_rust_crypto() { // Suppress warning. let _backend = backend; -}*/ +} async fn generate_credential( identity: Vec, @@ -30,8 +30,11 @@ async fn generate_credential( let credential = Credential::new_basic(identity); // ANCHOR_END: create_basic_credential // ANCHOR: create_credential_keys - let signature_keys = - SignatureKeyPair::new(signature_algorithm, &mut *backend.rand().borrow_rand().unwrap()).unwrap(); + let signature_keys = SignatureKeyPair::new( + signature_algorithm, + &mut *backend.rand().borrow_rand().unwrap(), + ) + .unwrap(); signature_keys.store(backend.key_store()).await.unwrap(); // ANCHOR_END: create_credential_keys @@ -80,13 +83,8 @@ async fn generate_key_package( /// - Alice removes Charlie and adds Bob /// - Bob leaves /// - Test saving the group state -// #[apply(ciphersuites_and_backends)] -// async fn book_operations(ciphersuite: Ciphersuite, backend: &impl OpenMlsCryptoProvider) { -#[async_std::test] -async fn book_operations() { - let backend = &OpenMlsRustCrypto::default(); - let ciphersuite = Ciphersuite::MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519; - +#[apply(ciphersuites_and_backends)] +async fn book_operations(ciphersuite: Ciphersuite, backend: &impl OpenMlsCryptoProvider) { // Generate credentials with keys let (alice_credential, alice_signature_keys) = generate_credential("Alice".into(), ciphersuite.signature_algorithm(), backend).await; @@ -112,8 +110,12 @@ async fn book_operations() { // Define the MlsGroup configuration // delivery service credentials - let (ds_credential_with_key, ds_signature_keys) = - generate_credential("delivery-service".into(), ciphersuite.signature_algorithm(), backend).await; + let (ds_credential_with_key, ds_signature_keys) = generate_credential( + "delivery-service".into(), + ciphersuite.signature_algorithm(), + backend, + ) + .await; // ANCHOR: mls_group_config_example let mls_group_config = MlsGroupConfig::builder() @@ -178,7 +180,10 @@ async fn book_operations() { // Check that we received the correct proposals if let Some(staged_commit) = alice_group.pending_commit() { - let add = staged_commit.add_proposals().next().expect("Expected a proposal."); + let add = staged_commit + .add_proposals() + .next() + .expect("Expected a proposal."); // Check that Bob was added assert_eq!( add.add_proposal().key_package().leaf_node().credential(), @@ -262,10 +267,13 @@ async fn book_operations() { // Message serialization - let bytes = mls_message_out.to_bytes().expect("Could not serialize message."); + let bytes = mls_message_out + .to_bytes() + .expect("Could not serialize message."); // ANCHOR: mls_message_in_from_bytes - let mls_message = MlsMessageIn::tls_deserialize_exact(bytes).expect("Could not deserialize message."); + let mls_message = + MlsMessageIn::tls_deserialize_exact(bytes).expect("Could not deserialize message."); // ANCHOR_END: mls_message_in_from_bytes // ANCHOR: process_message @@ -278,7 +286,9 @@ async fn book_operations() { // Check that we received the correct message // ANCHOR: inspect_application_message - if let ProcessedMessageContent::ApplicationMessage(application_message) = processed_message.into_content() { + if let ProcessedMessageContent::ApplicationMessage(application_message) = + processed_message.into_content() + { // Check the message assert_eq!(application_message.into_bytes(), b"Hi, I'm Alice!"); } @@ -306,7 +316,9 @@ async fn book_operations() { .expect("Could not process message."); // Check that we received the correct message - if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = alice_processed_message.into_content() { + if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = + alice_processed_message.into_content() + { // Merge staged Commit alice_group .merge_staged_commit(backend, *staged_commit) @@ -331,7 +343,10 @@ async fn book_operations() { ); // Make sure that both groups have the same public tree - assert_eq!(alice_group.export_ratchet_tree(), bob_group.export_ratchet_tree()); + assert_eq!( + alice_group.export_ratchet_tree(), + bob_group.export_ratchet_tree() + ); // === Alice updates and commits === // ANCHOR: propose_self_update @@ -352,10 +367,15 @@ async fn book_operations() { .expect("Could not process message."); // Check that we received the correct proposals - if let ProcessedMessageContent::ProposalMessage(staged_proposal) = bob_processed_message.into_content() { + if let ProcessedMessageContent::ProposalMessage(staged_proposal) = + bob_processed_message.into_content() + { if let Proposal::Update(ref update_proposal) = staged_proposal.proposal() { // Check that Alice updated - assert_eq!(update_proposal.leaf_node().credential(), &alice_credential.credential); + assert_eq!( + update_proposal.leaf_node().credential(), + &alice_credential.credential + ); // Store proposal alice_group.store_pending_proposal(*staged_proposal.clone()); } else { @@ -393,7 +413,9 @@ async fn book_operations() { .expect("Could not process message."); // Check that we received the correct message - if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = bob_processed_message.into_content() { + if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = + bob_processed_message.into_content() + { bob_group .merge_staged_commit(backend, *staged_commit) .await @@ -414,7 +436,10 @@ async fn book_operations() { ); // Make sure that both groups have the same public tree - assert_eq!(alice_group.export_ratchet_tree(), bob_group.export_ratchet_tree()); + assert_eq!( + alice_group.export_ratchet_tree(), + bob_group.export_ratchet_tree() + ); // === Bob adds Charlie === let charlie_key_package = generate_key_package( @@ -427,14 +452,20 @@ async fn book_operations() { .await; let (queued_message, welcome, _group_info) = bob_group - .add_members(backend, &bob_signature_keys, vec![charlie_key_package.into()]) + .add_members( + backend, + &bob_signature_keys, + vec![charlie_key_package.into()], + ) .await .unwrap(); let alice_processed_message = alice_group .process_message( backend, - queued_message.into_protocol_message().expect("Unexpected message type"), + queued_message + .into_protocol_message() + .expect("Unexpected message type"), ) .await .expect("Could not process message."); @@ -444,7 +475,9 @@ async fn book_operations() { .expect("error merging pending commit"); // Merge Commit - if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = alice_processed_message.into_content() { + if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = + alice_processed_message.into_content() + { alice_group .merge_staged_commit(backend, *staged_commit) .await @@ -463,8 +496,14 @@ async fn book_operations() { .expect("Error creating group from Welcome"); // Make sure that all groups have the same public tree - assert_eq!(alice_group.export_ratchet_tree(), bob_group.export_ratchet_tree(),); - assert_eq!(alice_group.export_ratchet_tree(), charlie_group.export_ratchet_tree()); + assert_eq!( + alice_group.export_ratchet_tree(), + bob_group.export_ratchet_tree(), + ); + assert_eq!( + alice_group.export_ratchet_tree(), + charlie_group.export_ratchet_tree() + ); // Check that Alice, Bob & Charlie are the members of the group let members = alice_group.members().collect::>(); @@ -492,7 +531,9 @@ async fn book_operations() { let _bob_processed_message = bob_group .process_message( backend, - queued_message.into_protocol_message().expect("Unexpected message type"), + queued_message + .into_protocol_message() + .expect("Unexpected message type"), ) .await .expect("Could not process message."); @@ -516,7 +557,9 @@ async fn book_operations() { let bob_processed_message = bob_group .process_message( backend, - queued_message.into_protocol_message().expect("Unexpected message type"), + queued_message + .into_protocol_message() + .expect("Unexpected message type"), ) .await .expect("Could not process message."); @@ -526,7 +569,9 @@ async fn book_operations() { .expect("error merging pending commit"); // Merge Commit - if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = alice_processed_message.into_content() { + if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = + alice_processed_message.into_content() + { alice_group .merge_staged_commit(backend, *staged_commit) .await @@ -536,7 +581,9 @@ async fn book_operations() { } // Merge Commit - if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = bob_processed_message.into_content() { + if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = + bob_processed_message.into_content() + { bob_group .merge_staged_commit(backend, *staged_commit) .await @@ -559,8 +606,14 @@ async fn book_operations() { ); // Make sure that all groups have the same public tree - assert_eq!(alice_group.export_ratchet_tree(), bob_group.export_ratchet_tree(),); - assert_eq!(alice_group.export_ratchet_tree(), charlie_group.export_ratchet_tree()); + assert_eq!( + alice_group.export_ratchet_tree(), + bob_group.export_ratchet_tree(), + ); + assert_eq!( + alice_group.export_ratchet_tree(), + charlie_group.export_ratchet_tree() + ); // ANCHOR: retrieve_members let charlie_members = charlie_group.members().collect::>(); @@ -570,7 +623,9 @@ async fn book_operations() { .iter() .find( |Member { - index: _, credential, .. + index: _, + credential, + .. }| credential.identity() == b"Bob", ) .expect("Couldn't find Bob in the list of group members."); @@ -578,7 +633,9 @@ async fn book_operations() { // Make sure that this is Bob's actual KP reference. assert_eq!( bob_member.credential.identity(), - bob_group.own_identity().expect("An unexpected error occurred.") + bob_group + .own_identity() + .expect("An unexpected error occurred.") ); // === Charlie removes Bob === @@ -634,11 +691,19 @@ async fn book_operations() { // Check that we receive the correct proposal for Alice // ANCHOR: inspect_staged_commit - if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = alice_processed_message.into_content() { + if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = + alice_processed_message.into_content() + { // We expect a remove proposal - let remove = staged_commit.remove_proposals().next().expect("Expected a proposal."); + let remove = staged_commit + .remove_proposals() + .next() + .expect("Expected a proposal."); // Check that Bob was removed - assert_eq!(remove.remove_proposal().removed(), bob_group.own_leaf_index()); + assert_eq!( + remove.remove_proposal().removed(), + bob_group.own_leaf_index() + ); // Check that Charlie removed Bob assert!(matches!( remove.sender(), @@ -658,15 +723,17 @@ async fn book_operations() { // Check that we receive the correct proposal for Bob // ANCHOR: remove_operation // ANCHOR: getting_removed - if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = bob_processed_message.into_content() { + if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = + bob_processed_message.into_content() + { let remove_proposal = staged_commit .remove_proposals() .next() .expect("An unexpected error occurred."); // We construct a RemoveOperation enum to help us interpret the remove operation - let remove_operation = - RemoveOperation::new(remove_proposal, &bob_group).expect("An unexpected Error occurred."); + let remove_operation = RemoveOperation::new(remove_proposal, &bob_group) + .expect("An unexpected Error occurred."); match remove_operation { RemoveOperation::WeLeft => unreachable!(), @@ -701,7 +768,10 @@ async fn book_operations() { // ANCHOR_END: getting_removed // Make sure that all groups have the same public tree - assert_eq!(alice_group.export_ratchet_tree(), charlie_group.export_ratchet_tree()); + assert_eq!( + alice_group.export_ratchet_tree(), + charlie_group.export_ratchet_tree() + ); // Make sure the group only contains two members assert_eq!(alice_group.members().count(), 2); @@ -731,7 +801,11 @@ async fn book_operations() { // Create RemoveProposal and process it // ANCHOR: propose_remove let (mls_message_out, _proposal_ref) = alice_group - .propose_remove_member(backend, &alice_signature_keys, charlie_group.own_leaf_index()) + .propose_remove_member( + backend, + &alice_signature_keys, + charlie_group.own_leaf_index(), + ) .expect("Could not create proposal to remove Charlie."); // ANCHOR_END: propose_remove @@ -746,7 +820,9 @@ async fn book_operations() { .expect("Could not process message."); // Check that we received the correct proposals - if let ProcessedMessageContent::ProposalMessage(staged_proposal) = charlie_processed_message.into_content() { + if let ProcessedMessageContent::ProposalMessage(staged_proposal) = + charlie_processed_message.into_content() + { if let Proposal::Remove(ref remove_proposal) = staged_proposal.proposal() { // Check that Charlie was removed assert_eq!(remove_proposal.removed(), charlie_group.own_leaf_index()); @@ -768,7 +844,11 @@ async fn book_operations() { // Create AddProposal and remove it // ANCHOR: rollback_proposal_by_ref let (_mls_message_out, proposal_ref) = alice_group - .propose_add_member(backend, &alice_signature_keys, bob_key_package.clone().into()) + .propose_add_member( + backend, + &alice_signature_keys, + bob_key_package.clone().into(), + ) .expect("Could not create proposal to add Bob"); alice_group .remove_pending_proposal(backend.key_store(), &proposal_ref) @@ -779,7 +859,11 @@ async fn book_operations() { // Create AddProposal and process it // ANCHOR: propose_add let (mls_message_out, _proposal_ref) = alice_group - .propose_add_member(backend, &alice_signature_keys, bob_key_package.clone().into()) + .propose_add_member( + backend, + &alice_signature_keys, + bob_key_package.clone().into(), + ) .expect("Could not create proposal to add Bob"); // ANCHOR_END: propose_add @@ -795,7 +879,9 @@ async fn book_operations() { // Check that we received the correct proposals // ANCHOR: inspect_add_proposal - if let ProcessedMessageContent::ProposalMessage(staged_proposal) = charlie_processed_message.into_content() { + if let ProcessedMessageContent::ProposalMessage(staged_proposal) = + charlie_processed_message.into_content() + { // In the case we received an Add Proposal if let Proposal::Add(add_proposal) = staged_proposal.proposal() { // Check that Bob was added @@ -829,7 +915,9 @@ async fn book_operations() { let charlie_processed_message = charlie_group .process_message( backend, - queued_message.into_protocol_message().expect("Unexpected message type"), + queued_message + .into_protocol_message() + .expect("Unexpected message type"), ) .await .expect("Could not process message."); @@ -841,7 +929,9 @@ async fn book_operations() { .expect("error merging pending commit"); // Merge Commit - if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = charlie_processed_message.into_content() { + if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = + charlie_processed_message.into_content() + { charlie_group .merge_staged_commit(backend, *staged_commit) .await @@ -896,7 +986,9 @@ async fn book_operations() { let bob_processed_message = bob_group .process_message( backend, - queued_message.into_protocol_message().expect("Unexpected message type"), + queued_message + .into_protocol_message() + .expect("Unexpected message type"), ) .await .expect("Could not process message."); @@ -907,18 +999,21 @@ async fn book_operations() { // As provided by looking up the sender manually via the `member()` function // ANCHOR: member_lookup - let sender_cred_from_group = if let Sender::Member(sender_index) = bob_processed_message.sender() { - bob_group - .member(*sender_index) - .expect("Could not find sender in group.") - .clone() - } else { - unreachable!("Expected sender type to be `Member`.") - }; + let sender_cred_from_group = + if let Sender::Member(sender_index) = bob_processed_message.sender() { + bob_group + .member(*sender_index) + .expect("Could not find sender in group.") + .clone() + } else { + unreachable!("Expected sender type to be `Member`.") + }; // ANCHOR_END: member_lookup // Check that we received the correct message - if let ProcessedMessageContent::ApplicationMessage(application_message) = bob_processed_message.into_content() { + if let ProcessedMessageContent::ApplicationMessage(application_message) = + bob_processed_message.into_content() + { // Check the message assert_eq!(application_message.into_bytes(), message_alice); // Check that Alice sent the message @@ -942,13 +1037,17 @@ async fn book_operations() { let alice_processed_message = alice_group .process_message( backend, - queued_message.into_protocol_message().expect("Unexpected message type"), + queued_message + .into_protocol_message() + .expect("Unexpected message type"), ) .await .expect("Could not process message."); // Store proposal - if let ProcessedMessageContent::ProposalMessage(staged_proposal) = alice_processed_message.into_content() { + if let ProcessedMessageContent::ProposalMessage(staged_proposal) = + alice_processed_message.into_content() + { // Store proposal alice_group.store_pending_proposal(*staged_proposal); } else { @@ -975,9 +1074,15 @@ async fn book_operations() { // Check that we received the correct proposals if let Some(staged_commit) = alice_group.pending_commit() { - let remove = staged_commit.remove_proposals().next().expect("Expected a proposal."); + let remove = staged_commit + .remove_proposals() + .next() + .expect("Expected a proposal."); // Check that Bob was removed - assert_eq!(remove.remove_proposal().removed(), bob_group.own_leaf_index()); + assert_eq!( + remove.remove_proposal().removed(), + bob_group.own_leaf_index() + ); // Check that Bob removed himself assert!(matches!( remove.sender(), @@ -996,16 +1101,26 @@ async fn book_operations() { let bob_processed_message = bob_group .process_message( backend, - queued_message.into_protocol_message().expect("Unexpected message type"), + queued_message + .into_protocol_message() + .expect("Unexpected message type"), ) .await .expect("Could not process message."); // Check that we received the correct proposals - if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = bob_processed_message.into_content() { - let remove = staged_commit.remove_proposals().next().expect("Expected a proposal."); + if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = + bob_processed_message.into_content() + { + let remove = staged_commit + .remove_proposals() + .next() + .expect("Expected a proposal."); // Check that Bob was removed - assert_eq!(remove.remove_proposal().removed(), bob_group.own_leaf_index()); + assert_eq!( + remove.remove_proposal().removed(), + bob_group.own_leaf_index() + ); // Check that Bob removed himself assert!(matches!( remove.sender(), @@ -1057,7 +1172,9 @@ async fn book_operations() { let alice_processed_message = alice_group .process_message( backend, - proposal.into_protocol_message().expect("Unexpected message type."), + proposal + .into_protocol_message() + .expect("Unexpected message type."), ) .await .expect("Could not process message."); @@ -1078,7 +1195,10 @@ async fn book_operations() { let bob_group = MlsGroup::new_from_welcome( backend, &mls_group_config, - welcome.unwrap().into_welcome().expect("Unexpected message type."), + welcome + .unwrap() + .into_welcome() + .expect("Unexpected message type."), None, ) .await @@ -1116,7 +1236,9 @@ async fn book_operations() { let alice_processed_message = alice_group .process_message( backend, - proposal.into_protocol_message().expect("Unexpected message type."), + proposal + .into_protocol_message() + .expect("Unexpected message type."), ) .await .expect("Could not process message."); @@ -1198,7 +1320,7 @@ async fn book_operations() { ); } -/*#[apply(ciphersuites_and_backends)] +#[apply(ciphersuites_and_backends)] async fn test_empty_input_errors(ciphersuite: Ciphersuite, backend: &impl OpenMlsCryptoProvider) { let group_id = GroupId::from_slice(b"Test Group"); @@ -1237,4 +1359,3 @@ async fn test_empty_input_errors(ciphersuite: Ciphersuite, backend: &impl OpenMl RemoveMembersError::EmptyInput(EmptyInputError::RemoveMembers) )); } -*/