Skip to content

Commit

Permalink
test(crypto): Add a snapshot test for the inbound group session pickle
Browse files Browse the repository at this point in the history
  • Loading branch information
poljar committed Feb 25, 2025
1 parent af62f09 commit c1e28aa
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
53 changes: 53 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ hmac = "0.12.1"
http = "1.2.0"
imbl = "4.0.1"
indexmap = "2.7.1"
insta = { version = "1.42.1", features = ["json"] }
insta = { version = "1.42.1", features = ["json", "redactions"] }
itertools = "0.14.0"
js-sys = "0.3.69"
mime = "0.3.17"
Expand Down
17 changes: 17 additions & 0 deletions crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ impl TryFrom<&DecryptedForwardedRoomKeyEvent> for InboundGroupSession {
#[cfg(test)]
mod tests {
use assert_matches2::assert_let;
use insta::assert_json_snapshot;
use matrix_sdk_test::async_test;
use ruma::{
device_id, events::room::history_visibility::HistoryVisibility, owned_room_id, room_id,
Expand All @@ -741,6 +742,22 @@ mod tests {
device_id!("ALICEDEVICE")
}

#[async_test]
async fn test_pickle_snapshot() {
let account = Account::new(alice_id());
let room_id = room_id!("!test:localhost");
let (_, session) = account.create_group_session_pair_with_defaults(room_id).await;

let pickle = session.pickle().await;

assert_json_snapshot!(pickle, {
".pickle.initial_ratchet.inner" => "[ratchet]",
".pickle.signing_key" => "[signing_key]",
".sender_key" => "[sender_key]",
".signing_key.ed25519" => "[ed25519_key]",
});
}

#[async_test]
async fn test_can_deserialise_pickled_session_without_sender_data() {
// Given the raw JSON for a picked inbound group session without any sender_data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
source: crates/matrix-sdk-crypto/src/olm/group_sessions/inbound.rs
expression: pickle
---
{
"pickle": {
"initial_ratchet": {
"inner": "[ratchet]",
"counter": 0
},
"signing_key": "[signing_key]",
"signing_key_verified": true,
"config": {
"version": "V1"
}
},
"sender_key": "[sender_key]",
"signing_key": {
"ed25519": "[ed25519_key]"
},
"sender_data": {
"UnknownDevice": {
"legacy_session": false
}
},
"room_id": "!test:localhost",
"imported": false,
"backed_up": false,
"history_visibility": "shared",
"algorithm": "m.megolm.v1.aes-sha2",
"shared_history": true
}

0 comments on commit c1e28aa

Please sign in to comment.