fixing crypto testing problems

This commit is contained in:
Benjamin Kampmann
2022-02-24 15:14:42 +01:00
parent d7f30167a0
commit 9c5cb08ac0
4 changed files with 31 additions and 21 deletions

View File

@@ -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<dyn CryptoStore> = 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]

View File

@@ -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},

View File

@@ -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},
};

View File

@@ -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},
};