Skip to content

Commit 541586f

Browse files
BillCarsonFrpoljar
authored andcommitted
review: add snapshot test with proper redaction
1 parent f89150d commit 541586f

5 files changed

+111
-4
lines changed

crates/matrix-sdk-crypto/src/machine/tests/send_encrypted_to_device.rs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
// limitations under the License.
1414

1515
use assert_matches2::{assert_let, assert_matches};
16+
use insta::assert_json_snapshot;
1617
use matrix_sdk_test::async_test;
1718
use ruma::{events::AnyToDeviceEvent, serde::Raw, to_device::DeviceIdOrAllDevices};
18-
use serde_json::{json, value::to_raw_value};
19+
use serde_json::{json, value::to_raw_value, Value};
1920

2021
use crate::{
2122
machine::{
@@ -112,11 +113,17 @@ async fn test_processed_to_device_variants() {
112113
let (alice, bob) =
113114
get_machine_pair_with_session(tests::alice_id(), tests::user_id(), false).await;
114115

115-
let custom_event_type = "m.new_device";
116+
let custom_event_type = "rtc.call.encryption_keys";
116117

117118
let custom_content = json!({
118119
"device_id": "XYZABCDE",
119-
"rooms": ["!726s6s6q:example.com"]
120+
"call_id": "",
121+
"keys": [
122+
{
123+
"index": 0,
124+
"key": "I7qrSrCR7Yo9B4iGVnR8IA"
125+
}
126+
],
120127
});
121128

122129
let device = alice.get_device(bob.user_id(), bob.device_id(), None).await.unwrap().unwrap();
@@ -210,14 +217,38 @@ async fn test_processed_to_device_variants() {
210217
let processed_event = &processed[0];
211218
assert_matches!(processed_event, ProcessedToDeviceEvent::Decrypted(_));
212219

220+
assert_json_snapshot!(
221+
serde_json::from_str::<Value>(processed_event.to_raw().json().get()).unwrap(),
222+
{
223+
".keys.ed25519" => "[sender_ed25519_key]",
224+
r#"["org.matrix.msc4147.device_keys"].device_id"# => "[ABCDEFGH]",
225+
r#"["org.matrix.msc4147.device_keys"].keys"# => "++REDACTED++",
226+
r#"["org.matrix.msc4147.device_keys"].signatures"# => "++REDACTED++",
227+
".recipient_keys.ed25519" => "[recipient_sender_key]",
228+
}
229+
);
230+
213231
let processed_event = &processed[1];
214232
assert_matches!(processed_event, ProcessedToDeviceEvent::PlainText(_));
233+
assert_json_snapshot!(
234+
serde_json::from_str::<Value>(processed_event.to_raw().json().get()).unwrap(),
235+
);
215236

216237
let processed_event = &processed[2];
217238
assert_matches!(processed_event, ProcessedToDeviceEvent::Invalid(_));
239+
assert_json_snapshot!(
240+
serde_json::from_str::<Value>(processed_event.to_raw().json().get()).unwrap(),
241+
);
218242

219243
let processed_event = &processed[3];
220-
assert_matches!(processed_event, ProcessedToDeviceEvent::UnableToDecrypt { .. });
244+
assert_matches!(processed_event, ProcessedToDeviceEvent::UnableToDecrypt(_));
245+
assert_json_snapshot!(
246+
serde_json::from_str::<Value>(processed_event.to_raw().json().get()).unwrap(),
247+
{
248+
".content.sender_key" => "[sender_ed25519_key]",
249+
".content.ciphertext" => "[++REDACTED++]",
250+
}
251+
);
221252
}
222253

223254
#[async_test]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: crates/matrix-sdk-crypto/src/machine/tests/send_encrypted_to_device.rs
3+
expression: "serde_json::from_str::<Value>(processed_event.to_raw().json().get()).unwrap()"
4+
---
5+
{
6+
"content": {
7+
"device_id": "XYZABCDE",
8+
"rooms": [
9+
"!726s6s6q:example.com"
10+
]
11+
},
12+
"sender": "@alice:example.com",
13+
"type": "m.new_device"
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
source: crates/matrix-sdk-crypto/src/machine/tests/send_encrypted_to_device.rs
3+
expression: "serde_json::from_str::<Value>(processed_event.to_raw().json().get()).unwrap()"
4+
---
5+
{
6+
"content": {
7+
"device_id": "XYZABCDE",
8+
"rooms": [
9+
"!726s6s6q:example.com"
10+
]
11+
},
12+
"sender": "@alice:example.com"
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: crates/matrix-sdk-crypto/src/machine/tests/send_encrypted_to_device.rs
3+
expression: "serde_json::from_str::<Value>(processed_event.to_raw().json().get()).unwrap()"
4+
---
5+
{
6+
"content": {
7+
"algorithm": "m.olm.v1.curve25519-aes-sha2",
8+
"ciphertext": "[++REDACTED++]",
9+
"org.matrix.msgid": "93ee0170aa7740d0ac9ee137e820302d",
10+
"sender_key": "[sender_ed25519_key]"
11+
},
12+
"sender": "@alice:example.org",
13+
"type": "m.room.encrypted"
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
source: crates/matrix-sdk-crypto/src/machine/tests/send_encrypted_to_device.rs
3+
expression: "serde_json::from_str::<Value>(processed_event.to_raw().json().get()).unwrap()"
4+
---
5+
{
6+
"content": {
7+
"call_id": "",
8+
"device_id": "XYZABCDE",
9+
"keys": [
10+
{
11+
"index": 0,
12+
"key": "I7qrSrCR7Yo9B4iGVnR8IA"
13+
}
14+
]
15+
},
16+
"keys": {
17+
"ed25519": "[sender_ed25519_key]"
18+
},
19+
"org.matrix.msc4147.device_keys": {
20+
"algorithms": [
21+
"m.olm.v1.curve25519-aes-sha2",
22+
"m.megolm.v1.aes-sha2"
23+
],
24+
"device_id": "[ABCDEFGH]",
25+
"keys": "++REDACTED++",
26+
"signatures": "++REDACTED++",
27+
"user_id": "@alice:example.org"
28+
},
29+
"recipient": "@bob:example.com",
30+
"recipient_keys": {
31+
"ed25519": "[recipient_sender_key]"
32+
},
33+
"sender": "@alice:example.org",
34+
"type": "rtc.call.encryption_keys"
35+
}

0 commit comments

Comments
 (0)