Skip to content

Commit 8bb5e50

Browse files
committed
test(crypto): use MegolmV2 in tests where experimental-algorithms are enabled
1 parent 7aead98 commit 8bb5e50

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

crates/matrix-sdk-crypto/src/store/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,17 @@ mod tests {
19671967
// We sort the sessions in the bundle, so that the snapshot is stable.
19681968
bundle.room_keys.sort_by_key(|session| session.session_id.clone());
19691969

1970+
// We substitute the algorithm, since this changes based on feature flags.
1971+
let algorithm = if cfg!(feature = "experimental-algorithms") {
1972+
"m.megolm.v2.aes-sha2"
1973+
} else {
1974+
"m.megolm.v1.aes-sha2"
1975+
};
1976+
let map_algorithm = move |value: Content, _path: ContentPath<'_>| {
1977+
assert_eq!(value.as_str().unwrap(), algorithm);
1978+
"[algorithm]"
1979+
};
1980+
19701981
// We also substitute alice's keys in the snapshot with placeholders
19711982
let alice_curve_key = alice.identity_keys().curve25519.to_base64();
19721983
let map_alice_curve_key = move |value: Content, _path: ContentPath<'_>| {
@@ -1981,6 +1992,8 @@ mod tests {
19811992

19821993
insta::with_settings!({ sort_maps => true }, {
19831994
assert_json_snapshot!(bundle, {
1995+
".withheld[].algorithm" => insta::dynamic_redaction(map_algorithm),
1996+
".room_keys[].algorithm" => insta::dynamic_redaction(map_algorithm),
19841997
".room_keys[].sender_key" => insta::dynamic_redaction(map_alice_curve_key.clone()),
19851998
".withheld[].sender_key" => insta::dynamic_redaction(map_alice_curve_key),
19861999
".room_keys[].sender_claimed_keys.ed25519" => insta::dynamic_redaction(map_alice_ed25519_key),
@@ -2036,6 +2049,12 @@ mod tests {
20362049
///
20372050
/// `olm_machine` is used to set the `sender_key` and `signing_key`
20382051
/// fields of the resultant session.
2052+
///
2053+
/// The encryption algorithm used for the session depends on the
2054+
/// `experimental-algorithms` feature flag:
2055+
///
2056+
/// - When not set, the session uses `m.megolm.v1.aes-sha2`.
2057+
/// - When set, the session uses `m.megolm.v2.aes-sha2`.
20392058
fn create_inbound_group_session_with_visibility(
20402059
olm_machine: &OlmMachine,
20412060
room_id: &RoomId,
@@ -2049,7 +2068,10 @@ mod tests {
20492068
room_id,
20502069
session_key,
20512070
SenderData::unknown(),
2071+
#[cfg(not(feature = "experimental-algorithms"))]
20522072
EventEncryptionAlgorithm::MegolmV1AesSha2,
2073+
#[cfg(feature = "experimental-algorithms")]
2074+
EventEncryptionAlgorithm::MegolmV2AesSha2,
20532075
None,
20542076
shared_history,
20552077
)

crates/matrix-sdk-crypto/src/store/snapshots/matrix_sdk_crypto__store__tests__build_room_key_bundle.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ expression: bundle
55
{
66
"room_keys": [
77
{
8-
"algorithm": "m.megolm.v1.aes-sha2",
8+
"algorithm": "[algorithm]",
99
"room_id": "!room1:localhost",
1010
"sender_key": "[alice curve key]",
1111
"session_id": "AWcCd1w7VlIPYaZeB53LqfgHbQxYjWMY/bCJ7E5ZsVI",
@@ -15,7 +15,7 @@ expression: bundle
1515
}
1616
},
1717
{
18-
"algorithm": "m.megolm.v1.aes-sha2",
18+
"algorithm": "[algorithm]",
1919
"room_id": "!room1:localhost",
2020
"sender_key": "[alice curve key]",
2121
"session_id": "y1i8rPyf5MMnB0tenJPrMqWO6oAMCKi536z+KrH0tic",
@@ -27,7 +27,7 @@ expression: bundle
2727
],
2828
"withheld": [
2929
{
30-
"algorithm": "m.megolm.v1.aes-sha2",
30+
"algorithm": "[algorithm]",
3131
"code": "m.unauthorised",
3232
"from_device": "BOB",
3333
"reason": "You are not authorised to read the message.",

0 commit comments

Comments
 (0)