Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
draft of an integration test
Browse files Browse the repository at this point in the history
andybalaam authored and richvdh committed Aug 7, 2024
1 parent 97c11ae commit 928157f
Showing 7 changed files with 84 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 75 additions & 2 deletions crates/matrix-sdk-crypto/src/store/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ macro_rules! cryptostore_integration_tests {
mod cryptostore_integration_tests {
use std::collections::{BTreeMap, HashMap};
use std::time::Duration;
use futures_util::stream::StreamExt;

use assert_matches::assert_matches;
use matrix_sdk_test::async_test;
@@ -48,7 +49,7 @@ macro_rules! cryptostore_integration_tests {
use $crate::{
olm::{
Account, Curve25519PublicKey, InboundGroupSession, OlmMessageHash,
PrivateCrossSigningIdentity, Session,
PrivateCrossSigningIdentity, SenderData, SenderDataType, Session
},
store::{
BackupDecryptionKey, Changes, CryptoStore, DeviceChanges, GossipRequest,
@@ -70,7 +71,8 @@ macro_rules! cryptostore_integration_tests {
DeviceKeys,
EventEncryptionAlgorithm,
},
GossippedSecret, LocalTrust, DeviceData, SecretInfo, ToDeviceRequest, TrackedUser,
EncryptionSettings, GossippedSecret, LocalTrust, DeviceData, SecretInfo,
ToDeviceRequest, TrackedUser,
};

use super::get_store;
@@ -559,6 +561,69 @@ macro_rules! cryptostore_integration_tests {
assert_eq!(store.inbound_group_session_counts(None).await.unwrap().total, 1);
}

#[async_test]
async fn fetch_inbound_group_sessions_for_device() {
// Given a store exists, containing inbound group sessions from different devices
let (account, store) =
get_loaded_store("fetch_inbound_group_sessions_for_device").await;

let dev1 = Curve25519PublicKey::from_base64(
"wjLpTLRqbqBzLs63aYaEv2Boi6cFEbbM/sSRQ2oAKk4"
).unwrap();
let dev2 = Curve25519PublicKey::from_base64(
"LTpv2DGMhggPAXO02+7f68CNEp6A40F0Yl8B094Y8gc"
).unwrap();

let dev_1_unknown_a = create_session(
&account, &dev1, SenderDataType::UnknownDevice).await;

let dev_1_unknown_b = create_session(
&account, &dev1, SenderDataType::UnknownDevice).await;

let dev_1_keys = create_session(
&account, &dev1, SenderDataType::DeviceInfo).await;

let dev_2_unknown = create_session(
&account, &dev1, SenderDataType::UnknownDevice).await;

let dev_2_keys = create_session(
&account, &dev1, SenderDataType::DeviceInfo).await;

let sessions = vec![
dev_1_unknown_a.clone(),
dev_1_unknown_b.clone(),
dev_1_keys.clone(),
dev_2_unknown.clone(),
dev_2_keys.clone(),
];

let changes = Changes {
inbound_group_sessions: sessions,
..Default::default()
};
store.save_changes(changes).await.expect("Can't save group session");

// When we fetch the list of sessions for device 1, unknown
let sessions_1_u: Vec<_> = store
.get_inbound_group_sessions_for_device(&dev1, SenderDataType::UnknownDevice)
.await
.unwrap()
.collect().await;

// Then the expected sessions are returned
assert_eq!(sessions_1_u, vec![dev_1_unknown_a, dev_1_unknown_b]);

// And when we ask for the list of sessions for device 2, with device keys
let sessions_2_d: Vec<_> = store
.get_inbound_group_sessions_for_device(&dev2, SenderDataType::DeviceInfo)
.await
.unwrap()
.collect().await;

// Then the matching session is returned
assert_eq!(sessions_2_d, vec![dev_2_keys]);
}

#[async_test]
async fn test_tracked_users() {
let dir = "test_tracked_users";
@@ -1110,6 +1175,14 @@ macro_rules! cryptostore_integration_tests {
fn session_info(session: &InboundGroupSession) -> (&RoomId, &str) {
(&session.room_id(), &session.session_id())
}

async fn create_session(
account: &Account,
device_curve_key: &Curve25519PublicKey,
sender_data_type: SenderDataType
) -> InboundGroupSession {
todo!()
}
}
};
}
4 changes: 2 additions & 2 deletions crates/matrix-sdk-crypto/src/store/memorystore.rs
Original file line number Diff line number Diff line change
@@ -381,7 +381,7 @@ impl CryptoStore for MemoryStore {

async fn get_inbound_group_sessions_for_device(
&self,
_device_key: Curve25519PublicKey,
_device_key: &Curve25519PublicKey,
_sender_data_type: SenderDataType,
) -> Result<InboundGroupSessionStream> {
todo!()
@@ -1241,7 +1241,7 @@ mod integration_tests {

async fn get_inbound_group_sessions_for_device(
&self,
device_key: Curve25519PublicKey,
device_key: &Curve25519PublicKey,
sender_data_type: SenderDataType,
) -> Result<InboundGroupSessionStream, Self::Error> {
self.0.get_inbound_group_sessions_for_device(device_key, sender_data_type).await
4 changes: 2 additions & 2 deletions crates/matrix-sdk-crypto/src/store/traits.rs
Original file line number Diff line number Diff line change
@@ -134,7 +134,7 @@ pub trait CryptoStore: AsyncTraitDeps {
/// and we want to update the sender data based on the new information.
async fn get_inbound_group_sessions_for_device(
&self,
device_key: Curve25519PublicKey,
device_key: &Curve25519PublicKey,
sender_data_type: SenderDataType,
) -> Result<InboundGroupSessionStream, Self::Error>;

@@ -422,7 +422,7 @@ impl<T: CryptoStore> CryptoStore for EraseCryptoStoreError<T> {

async fn get_inbound_group_sessions_for_device(
&self,
device_key: Curve25519PublicKey,
device_key: &Curve25519PublicKey,
sender_data_type: SenderDataType,
) -> Result<InboundGroupSessionStream> {
self.0
1 change: 1 addition & 0 deletions crates/matrix-sdk-indexeddb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ getrandom = { version = "0.2.6", features = ["js"] }
[dev-dependencies]
assert_matches = { workspace = true }
assert_matches2 = { workspace = true }
futures-util = { workspace = true }
matrix-sdk-base = { workspace = true, features = ["testing"] }
matrix-sdk-common = { workspace = true, features = ["js"] }
matrix-sdk-crypto = { workspace = true, features = ["js", "testing"] }
1 change: 1 addition & 0 deletions crates/matrix-sdk-sqlite/Cargo.toml
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ vodozemac = { workspace = true }

[dev-dependencies]
assert_matches = { workspace = true }
futures-util = { workspace = true }
glob = "0.3.0"
matrix-sdk-base = { workspace = true, features = ["testing"] }
matrix-sdk-crypto = { workspace = true, features = ["testing"] }
2 changes: 1 addition & 1 deletion crates/matrix-sdk-sqlite/src/crypto_store.rs
Original file line number Diff line number Diff line change
@@ -996,7 +996,7 @@ impl CryptoStore for SqliteCryptoStore {

async fn get_inbound_group_sessions_for_device(
&self,
_device_key: Curve25519PublicKey,
_device_key: &Curve25519PublicKey,
_sender_data_type: SenderDataType,
) -> Result<InboundGroupSessionStream> {
todo!()

0 comments on commit 928157f

Please sign in to comment.