Skip to content

Commit 5cb4dd9

Browse files
committed
tests: add missing required state types
chore(base): clippy lint - use let-else fix: minor fixes feat: fixup fix: remove proxy chore: satisfy the linter
1 parent 8a88251 commit 5cb4dd9

File tree

5 files changed

+52
-24
lines changed

5 files changed

+52
-24
lines changed

crates/matrix-sdk-base/src/response_processors/state_events.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ use ruma::{
2525
use serde::Deserialize;
2626
use tracing::warn;
2727

28-
use super::{Context, e2ee};
28+
use super::Context;
29+
#[cfg(feature = "e2e-encryption")]
30+
use super::e2ee;
2931
use crate::store::BaseStateStore;
3032

3133
/// Collect [`AnySyncStateEvent`].
@@ -41,7 +43,7 @@ pub mod sync {
4143
room::member::{MembershipState, RoomMemberEventContent},
4244
},
4345
};
44-
use tracing::{error, instrument, warn};
46+
use tracing::{error, instrument};
4547

4648
use super::{super::profiles, AnySyncStateEvent, Context, Raw};
4749
use crate::{
@@ -156,19 +158,17 @@ pub mod sync {
156158
.unwrap();
157159
if let RoomEventDecryptionResult::Decrypted(room_event) = decrypted_event {
158160
// Unpack event type and state key from outer.
159-
let (outer_event_type, outer_state_key) =
160-
match outer.state_key().split_once(":") {
161-
None => {
162-
warn!(
163-
event_id = outer.event_id().as_str(),
164-
state_key = event.state_key(),
165-
"Malformed state key"
166-
);
167-
// Discard the event entirely.
168-
continue;
169-
}
170-
Some(result) => result,
171-
};
161+
let Some((outer_event_type, outer_state_key)) =
162+
outer.state_key().split_once(":")
163+
else {
164+
error!(
165+
event_id = outer.event_id().as_str(),
166+
state_key = event.state_key(),
167+
"Malformed state key"
168+
);
169+
// Discard the event entirely.
170+
continue;
171+
};
172172

173173
let inner = match room_event
174174
.event
@@ -178,15 +178,15 @@ pub mod sync {
178178
{
179179
Ok(inner) => inner,
180180
Err(e) => {
181-
warn!("Malformed event body: {e}");
181+
error!("Malformed event body: {e}");
182182
continue;
183183
}
184184
};
185185

186186
// Check event types match, discard if not.
187187
let inner_event_type = inner.event_type().to_string();
188188
if outer_event_type != inner_event_type {
189-
warn!(
189+
error!(
190190
event_id = outer.event_id().as_str(),
191191
expected = outer_event_type,
192192
found = inner_event_type,
@@ -197,7 +197,7 @@ pub mod sync {
197197

198198
// Check state keys match, discard if not.
199199
if outer_state_key != inner.state_key() {
200-
warn!(
200+
error!(
201201
event_id = outer.event_id().as_str(),
202202
expected = outer_state_key,
203203
found = inner.state_key(),

crates/matrix-sdk-ui/tests/integration/room_list_service.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ async fn test_sync_all_states() -> Result<(), Error> {
369369
["m.room.create", ""],
370370
["m.room.history_visibility", ""],
371371
["io.element.functional_members", ""],
372+
["m.room.encrypted", "*"]
372373
],
373374
"filters": {},
374375
"timeline_limit": 1,
@@ -2273,6 +2274,7 @@ async fn test_room_subscription() -> Result<(), Error> {
22732274
["m.room.create", ""],
22742275
["m.room.history_visibility", ""],
22752276
["io.element.functional_members", ""],
2277+
["m.room.encrypted", "*"],
22762278
["m.room.pinned_events", ""],
22772279
],
22782280
"timeline_limit": 20,
@@ -2316,6 +2318,7 @@ async fn test_room_subscription() -> Result<(), Error> {
23162318
["m.room.create", ""],
23172319
["m.room.history_visibility", ""],
23182320
["io.element.functional_members", ""],
2321+
["m.room.encrypted", "*"],
23192322
["m.room.pinned_events", ""],
23202323
],
23212324
"timeline_limit": 20,

crates/matrix-sdk/src/room/futures.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,12 @@ impl<'a> SendStateEventRaw<'a> {
407407
}
408408

409409
/// Returns `true` if the inner event should be encrypted.
410+
#[cfg(feature = "e2e-encryption")]
410411
fn should_encrypt(room: &Room, event_type: &str) -> bool {
412+
use tracing::debug;
413+
411414
if !room.encryption_state().is_state_encrypted() {
412-
trace!("Sending plaintext event as the room does NOT support encrypted state events.");
415+
debug!("Sending plaintext event as the room does NOT support encrypted state events.");
413416
return false;
414417
}
415418

@@ -427,6 +430,7 @@ impl<'a> SendStateEventRaw<'a> {
427430
| "m.space.child"
428431
| "m.space.parent"
429432
) {
433+
debug!("Sending plaintext event as its type is excluded from encryption.");
430434
return false;
431435
}
432436

@@ -439,17 +443,28 @@ impl<'a> IntoFuture for SendStateEventRaw<'a> {
439443
boxed_into_future!(extra_bounds: 'a);
440444

441445
fn into_future(self) -> Self::IntoFuture {
446+
#[cfg(feature = "e2e-encryption")]
442447
let Self { room, mut event_type, state_key, mut content, tracing_span, request_config } =
443448
self;
444449

450+
// This is here purely to satisfy the linter on non-encrypting targets.
451+
#[cfg(not(feature = "e2e-encryption"))]
452+
let Self { room, event_type, state_key, content, tracing_span, request_config } = self;
453+
445454
let fut = async move {
446455
room.ensure_room_joined()?;
456+
457+
#[cfg(feature = "e2e-encryption")]
447458
let mut state_key = state_key.to_owned();
459+
#[cfg(not(feature = "e2e-encryption"))]
460+
let state_key = state_key.to_owned();
448461

449462
#[cfg(feature = "e2e-encryption")]
450463
if Self::should_encrypt(room, event_type) {
464+
use tracing::debug;
465+
451466
Span::current().record("is_room_encrypted", true);
452-
trace!(
467+
debug!(
453468
room_id = ?room.room_id(),
454469
"Sending encrypted event because the room is encrypted.",
455470
);

crates/matrix-sdk/src/test_utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub async fn logged_in_client_with_server() -> (Client, wiremock::MockServer) {
121121
#[macro_export]
122122
macro_rules! assert_next_with_timeout {
123123
($stream:expr) => {
124-
$crate::assert_next_with_timeout!($stream, 5000)
124+
$crate::assert_next_with_timeout!($stream, 500)
125125
};
126126
($stream:expr, $timeout_ms:expr) => {{
127127
// Needed for subscribers, as they won't use the StreamExt features

testing/matrix-sdk-integration-testing/src/tests/e2ee/state_events.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::ops::Deref;
1+
use std::{ops::Deref, time::Duration};
22

33
use anyhow::Result;
44
use assert_matches2::assert_let;
@@ -52,14 +52,24 @@ async fn test_e2ee_state_events() -> Result<()> {
5252
.await?,
5353
);
5454

55-
// Alice creates a room ...
55+
// Alice creates an encrypted room ...
5656
let alice_room = alice
5757
.create_room(assign!(CreateRoomRequest::new(), {
5858
name: Some("Cat Photos".to_owned()),
5959
preset: Some(RoomPreset::PublicChat),
6060
}))
6161
.await?;
62-
alice_room.enable_encryption().await?;
62+
alice_room.enable_encryption_with_state().await?;
63+
64+
// HACK: wait for sync
65+
let _ = tokio::time::sleep(Duration::from_secs(3)).await;
66+
67+
// (sanity checks)
68+
assert!(alice_room.encryption_state().is_encrypted(), "Encryption was not enabled.");
69+
assert!(
70+
alice_room.encryption_state().is_state_encrypted(),
71+
"State encryption was not enabled."
72+
);
6373

6474
info!(room_id = ?alice_room.room_id(), "Alice has created and enabled encryption in the room");
6575

0 commit comments

Comments
 (0)