crypto: Move create_session test helper to test_helpers

This commit is contained in:
Richard van der Hoff
2024-08-07 17:02:47 +01:00
parent 2c0d858833
commit 066fdf99c3
3 changed files with 21 additions and 22 deletions

View File

@@ -389,8 +389,8 @@ mod tests {
use crate::{
machine::{
test_helpers::get_prepared_machine_test_helper,
tests::{create_session, to_device_requests_to_content},
test_helpers::{create_session, get_prepared_machine_test_helper},
tests::to_device_requests_to_content,
},
olm::OutboundGroupSession,
types::{events::ToDeviceEvent, DeviceKeys as DeviceKeysType},

View File

@@ -2408,7 +2408,6 @@ pub(crate) mod tests {
api::{
client::{
keys::{
claim_keys,
get_keys::{self, v3::Response as KeyQueryResponse},
upload_keys,
},
@@ -2418,7 +2417,6 @@ pub(crate) mod tests {
IncomingResponse,
},
device_id,
encryption::OneTimeKey,
events::{
dummy::ToDeviceDummyEventContent,
key::verification::VerificationMethod,
@@ -2432,7 +2430,7 @@ pub(crate) mod tests {
serde::Raw,
to_device::DeviceIdOrAllDevices,
uint, user_id, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch,
OwnedDeviceKeyId, RoomId, SecondsSinceUnixEpoch, TransactionId, UserId,
RoomId, SecondsSinceUnixEpoch, TransactionId, UserId,
};
use serde_json::{json, value::to_raw_value};
use vodozemac::{
@@ -2445,7 +2443,7 @@ pub(crate) mod tests {
error::{EventError, SetRoomSettingsError},
machine::{
test_helpers::{
get_machine_after_query_test_helper, get_machine_pair,
create_session, get_machine_after_query_test_helper, get_machine_pair,
get_machine_pair_with_session, get_machine_pair_with_setup_sessions_test_helper,
get_prepared_machine_test_helper,
},
@@ -2782,22 +2780,6 @@ pub(crate) mod tests {
assert!(user_sessions.contains_key(alice_device));
}
pub async fn create_session(
machine: &OlmMachine,
user_id: &UserId,
device_id: &DeviceId,
key_id: OwnedDeviceKeyId,
one_time_key: Raw<OneTimeKey>,
) {
let one_time_keys = BTreeMap::from([(
user_id.to_owned(),
BTreeMap::from([(device_id.to_owned(), BTreeMap::from([(key_id, one_time_key)]))]),
)]);
let response = claim_keys::v3::Response::new(one_time_keys);
machine.inner.session_manager.create_sessions(&response).await.unwrap();
}
#[async_test]
async fn test_session_creation() {
let (alice_machine, bob_machine, mut one_time_keys) =

View File

@@ -169,3 +169,20 @@ pub async fn get_machine_pair_with_setup_sessions_test_helper(
(alice, bob)
}
/// Create an Olm session from the given machine to the given device
pub async fn create_session(
machine: &OlmMachine,
user_id: &UserId,
device_id: &DeviceId,
key_id: OwnedDeviceKeyId,
one_time_key: Raw<OneTimeKey>,
) {
let one_time_keys = BTreeMap::from([(
user_id.to_owned(),
BTreeMap::from([(device_id.to_owned(), BTreeMap::from([(key_id, one_time_key)]))]),
)]);
let response = claim_keys::v3::Response::new(one_time_keys);
machine.inner.session_manager.create_sessions(&response).await.unwrap();
}