From c8a2f4d4953a96689996498f79466a9c9f8d21d1 Mon Sep 17 00:00:00 2001 From: Nicholas Molnar <65710+neekolas@users.noreply.github.com> Date: Mon, 19 Aug 2024 13:50:46 -0700 Subject: [PATCH] Fix test --- openmls/src/group/tests/test_past_secrets.rs | 50 +++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/openmls/src/group/tests/test_past_secrets.rs b/openmls/src/group/tests/test_past_secrets.rs index f065919d8..63a203296 100644 --- a/openmls/src/group/tests/test_past_secrets.rs +++ b/openmls/src/group/tests/test_past_secrets.rs @@ -1,16 +1,22 @@ //! This module contains tests regarding the use of [`MessageSecretsStore`] in [`MlsGroup`] -use super::utils::{generate_credential_with_key, generate_key_package}; +use crate::group::tests_and_kats::utils::{generate_credential_with_key, generate_key_package}; use crate::{ framing::{MessageDecryptionError, MlsMessageIn, ProcessedMessageContent}, group::*, + treesync::LeafNodeParameters, }; +use openmls_traits::OpenMlsProvider as _; + #[openmls_test::openmls_test] -fn test_past_secrets_in_group( +fn test_past_secrets_in_group( ciphersuite: Ciphersuite, - provider: &impl crate::storage::OpenMlsProvider, + provider: &Provider, ) { + let alice_provider = &mut Provider::default(); + let bob_provider = &mut Provider::default(); + // Test this for different parameters for max_epochs in (0..10usize).step_by(2) { let group_id = GroupId::from_slice(b"Test Group"); @@ -19,19 +25,19 @@ fn test_past_secrets_in_group( let alice_credential_with_keys = generate_credential_with_key( b"Alice".to_vec(), ciphersuite.signature_algorithm(), - provider, + alice_provider, ); let bob_credential_with_keys = generate_credential_with_key( b"Bob".to_vec(), ciphersuite.signature_algorithm(), - provider, + bob_provider, ); // Generate KeyPackages let bob_key_package = generate_key_package( ciphersuite, Extensions::empty(), - provider, + bob_provider, bob_credential_with_keys, ); @@ -44,7 +50,7 @@ fn test_past_secrets_in_group( // === Alice creates a group === let mut alice_group = MlsGroup::new_with_group_id( - provider, + alice_provider, &alice_credential_with_keys.signer, &mls_group_create_config, group_id.clone(), @@ -55,14 +61,14 @@ fn test_past_secrets_in_group( // Alice adds Bob let (_message, welcome, _group_info) = alice_group .add_members( - provider, + alice_provider, &alice_credential_with_keys.signer, &[bob_key_package.key_package().clone()], ) .expect("An unexpected error occurred."); alice_group - .merge_pending_commit(provider) + .merge_pending_commit(alice_provider) .expect("error merging pending commit"); let welcome: MlsMessageIn = welcome.into(); @@ -71,13 +77,13 @@ fn test_past_secrets_in_group( .expect("expected message to be a welcome"); let mut bob_group = StagedWelcome::new_from_welcome( - provider, + bob_provider, mls_group_create_config.join_config(), welcome, Some(alice_group.export_ratchet_tree().into()), ) .expect("Error creating staged join from Welcome") - .into_group(provider) + .into_group(bob_provider) .expect("Error creating group from staged join"); // Generate application message for different epochs @@ -87,19 +93,23 @@ fn test_past_secrets_in_group( for _ in 0..max_epochs { let application_message = alice_group - .create_message(provider, &alice_credential_with_keys.signer, &[1, 2, 3]) + .create_message( + alice_provider, + &alice_credential_with_keys.signer, + &[1, 2, 3], + ) .expect("An unexpected error occurred."); application_messages.push(application_message.into_protocol_message().unwrap()); let (message, _welcome, _group_info) = alice_group - .self_update(provider, &alice_credential_with_keys.signer) + .self_update(alice_provider, &alice_credential_with_keys.signer) .expect("An unexpected error occurred."); update_commits.push(message.clone()); alice_group - .merge_pending_commit(provider) + .merge_pending_commit(alice_provider) .expect("error merging pending commit"); } @@ -107,14 +117,14 @@ fn test_past_secrets_in_group( for update_commit in update_commits { let bob_processed_message = bob_group - .process_message(provider, update_commit.into_protocol_message().unwrap()) + .process_message(bob_provider, update_commit.into_protocol_message().unwrap()) .expect("An unexpected error occurred."); if let ProcessedMessageContent::StagedCommitMessage(staged_commit) = bob_processed_message.into_content() { bob_group - .merge_staged_commit(provider, *staged_commit) + .merge_staged_commit(bob_provider, *staged_commit) .expect("Error merging commit."); } else { unreachable!("Expected a StagedCommit."); @@ -123,10 +133,14 @@ fn test_past_secrets_in_group( // === Test application messages from older epochs === + let mut bob_group = MlsGroup::load(bob_provider.storage(), &group_id) + .expect("error re-loading bob's group") + .expect("no such group"); + // The first messages should fail for application_message in application_messages.iter().take(max_epochs / 2) { let err = bob_group - .process_message(provider, application_message.clone()) + .process_message(bob_provider, application_message.clone()) .expect_err("An unexpected error occurred."); assert!(matches!( err, @@ -139,7 +153,7 @@ fn test_past_secrets_in_group( // The last messages should not fail for application_message in application_messages.iter().skip(max_epochs / 2) { let bob_processed_message = bob_group - .process_message(provider, application_message.clone()) + .process_message(bob_provider, application_message.clone()) .expect("An unexpected error occurred."); if let ProcessedMessageContent::ApplicationMessage(application_message) =