mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 21:52:30 -04:00
fixing crypto testing problems
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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},
|
||||
|
||||
@@ -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},
|
||||
};
|
||||
|
||||
@@ -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},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user