From 9c5cb08ac0e92ccdb9afc747dfcfbb8a20558c59 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Thu, 24 Feb 2022 15:14:42 +0100 Subject: [PATCH] fixing crypto testing problems --- .../src/identities/manager.rs | 40 ++++++++++++------- .../matrix-sdk-crypto/src/identities/user.rs | 8 ++-- crates/matrix-sdk-crypto/src/store/caches.rs | 2 +- .../src/store/memorystore.rs | 2 +- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/crates/matrix-sdk-crypto/src/identities/manager.rs b/crates/matrix-sdk-crypto/src/identities/manager.rs index 84374bce7..75171cc64 100644 --- a/crates/matrix-sdk-crypto/src/identities/manager.rs +++ b/crates/matrix-sdk-crypto/src/identities/manager.rs @@ -540,13 +540,22 @@ impl IdentityManager { #[cfg(any(test, feature = "testing"))] pub(crate) mod testing { #![allow(dead_code)] + use std::sync::Arc; + + use matrix_sdk_common::locks::Mutex; use ruma::{ api::{client::r0::keys::get_keys::Response as KeyQueryResponse, IncomingResponse}, - device_id, user_id, DeviceId, UserId, + DeviceId, UserId, device_id, user_id, }; use serde_json::json; use crate::machine::testing::response_from_file; + use crate::{ + identities::IdentityManager, + olm::{PrivateCrossSigningIdentity, ReadOnlyAccount}, + store::{CryptoStore, MemoryStore, Store}, + verification::VerificationMachine, + }; pub fn user_id() -> &'static UserId { user_id!("@example:localhost") @@ -560,6 +569,18 @@ pub(crate) mod testing { device_id!("WSKKLTJZCL") } + pub(crate) fn manager() -> IdentityManager { + let identity = + Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(user_id().to_owned()))); + let user_id = Arc::from(user_id()); + let account = ReadOnlyAccount::new(&user_id, device_id()); + let store: Arc = Arc::new(MemoryStore::new()); + let verification = VerificationMachine::new(account, identity.clone(), store); + let store = + Store::new(user_id.clone(), identity, Arc::new(MemoryStore::new()), verification); + IdentityManager::new(user_id, device_id().into(), store) + } + pub fn other_key_query() -> KeyQueryResponse { let data = response_from_file(&json!({ "device_keys": { @@ -723,22 +744,11 @@ pub(crate) mod testing { #[cfg(test)] pub(crate) mod test { - use std::sync::Arc; - - use matrix_sdk_common::locks::Mutex; use matrix_sdk_test::async_test; - use ruma::{ - api::{client::r0::keys::get_keys::Response as KeyQueryResponse, IncomingResponse}, - DeviceId, UserId, - }; - use serde_json::json; - use super::testing::{device_id, other_key_query, other_user_id, own_key_query, user_id}; - use crate::{ - identities::IdentityManager, - olm::{PrivateCrossSigningIdentity, ReadOnlyAccount}, - store::{CryptoStore, MemoryStore, Store}, - verification::VerificationMachine, + use super::testing::{manager, device_id, other_key_query, other_user_id}; + use ruma::{ + DeviceId, UserId, device_id, user_id, }; #[async_test] diff --git a/crates/matrix-sdk-crypto/src/identities/user.rs b/crates/matrix-sdk-crypto/src/identities/user.rs index 457d9614a..3d128e218 100644 --- a/crates/matrix-sdk-crypto/src/identities/user.rs +++ b/crates/matrix-sdk-crypto/src/identities/user.rs @@ -946,7 +946,7 @@ pub(crate) mod testing { ReadOnlyDevice, }; - fn device(response: &KeyQueryResponse) -> (ReadOnlyDevice, ReadOnlyDevice) { + pub fn device(response: &KeyQueryResponse) -> (ReadOnlyDevice, ReadOnlyDevice) { let mut devices = response.device_keys.values().next().unwrap().values(); let first = ReadOnlyDevice::try_from(&devices.next().unwrap().deserialize().unwrap()).unwrap(); @@ -955,7 +955,7 @@ pub(crate) mod testing { (first, second) } - fn own_identity(response: &KeyQueryResponse) -> ReadOnlyOwnUserIdentity { + pub fn own_identity(response: &KeyQueryResponse) -> ReadOnlyOwnUserIdentity { let user_id = user_id!("@example:localhost"); let master_key = response.master_keys.get(user_id).unwrap().deserialize().unwrap(); @@ -989,11 +989,11 @@ pub(crate) mod test { use matrix_sdk_test::async_test; use ruma::{api::client::r0::keys::get_keys::Response as KeyQueryResponse, user_id}; - use super::testing::{get_other_identity, get_own_identity}; + use super::testing::{get_other_identity, get_own_identity, device}; use super::{ReadOnlyOwnUserIdentity, ReadOnlyUserIdentities, ReadOnlyUserIdentity}; use crate::{ identities::{ - manager::test::{other_key_query, own_key_query}, + manager::testing::{other_key_query, own_key_query}, Device, ReadOnlyDevice, }, olm::{PrivateCrossSigningIdentity, ReadOnlyAccount}, diff --git a/crates/matrix-sdk-crypto/src/store/caches.rs b/crates/matrix-sdk-crypto/src/store/caches.rs index ea3d204d6..160fc66e5 100644 --- a/crates/matrix-sdk-crypto/src/store/caches.rs +++ b/crates/matrix-sdk-crypto/src/store/caches.rs @@ -191,7 +191,7 @@ mod test { use ruma::room_id; use crate::{ - identities::device::test::get_device, + identities::device::testing::get_device, olm::{test::get_account_and_session, InboundGroupSession}, store::caches::{DeviceStore, GroupSessionStore, SessionStore}, }; diff --git a/crates/matrix-sdk-crypto/src/store/memorystore.rs b/crates/matrix-sdk-crypto/src/store/memorystore.rs index 53d527080..57b6ac242 100644 --- a/crates/matrix-sdk-crypto/src/store/memorystore.rs +++ b/crates/matrix-sdk-crypto/src/store/memorystore.rs @@ -312,7 +312,7 @@ mod test { use ruma::room_id; use crate::{ - identities::device::test::get_device, + identities::device::testing::get_device, olm::{test::get_account_and_session, InboundGroupSession, OlmMessageHash}, store::{memorystore::MemoryStore, Changes, CryptoStore}, };