@@ -1717,17 +1717,22 @@ impl matrix_sdk_common::cross_process_lock::TryLock for LockableCryptoStore {
17171717mod tests {
17181718 use std:: pin:: pin;
17191719
1720+ use assert_matches2:: assert_matches;
17201721 use futures_util:: StreamExt ;
17211722 use insta:: { _macro_support:: Content , assert_json_snapshot, internals:: ContentPath } ;
17221723 use matrix_sdk_test:: async_test;
1723- use ruma:: { device_id, room_id, user_id, RoomId } ;
1724+ use ruma:: { device_id, owned_device_id, room_id, user_id, RoomId } ;
1725+ use serde_json:: json;
17241726 use vodozemac:: megolm:: SessionKey ;
17251727
17261728 use crate :: {
17271729 machine:: test_helpers:: get_machine_pair,
17281730 olm:: { InboundGroupSession , SenderData } ,
1729- store:: types:: DehydratedDeviceKey ,
1730- types:: EventEncryptionAlgorithm ,
1731+ store:: types:: { DehydratedDeviceKey , RoomKeyWithheldEntry } ,
1732+ types:: {
1733+ events:: room_key_withheld:: { MegolmV1AesSha2WithheldContent , RoomKeyWithheldContent } ,
1734+ EventEncryptionAlgorithm ,
1735+ } ,
17311736 OlmMachine ,
17321737 } ;
17331738
@@ -1969,6 +1974,50 @@ mod tests {
19691974 } ) ;
19701975 }
19711976
1977+ /// Tests that the new store format introduced in [#5737][#5737] does not
1978+ /// conflict with items already in the store that were serialised with the
1979+ /// older format.
1980+ ///
1981+ /// [#5737]: https://github.com/matrix-org/matrix-rust-sdk/pull/5737
1982+ #[ async_test]
1983+ async fn test_deserialize_room_key_withheld_entry_from_to_device_event ( ) {
1984+ let entry: RoomKeyWithheldEntry = serde_json:: from_value ( json ! (
1985+ {
1986+ "content" : {
1987+ "algorithm" : "m.megolm.v1.aes-sha2" ,
1988+ "code" : "m.unauthorised" ,
1989+ "from_device" : "ALICE" ,
1990+ "reason" : "You are not authorised to read the message." ,
1991+ "room_id" : "!roomid:s.co" ,
1992+ "sender_key" : "7hIcOrEroXYdzjtCBvBjUiqvT0Me7g+ymeXqoc65RS0" ,
1993+ "session_id" : "session123"
1994+ } ,
1995+ "sender" : "@alice:s.co" ,
1996+ "type" : "m.room_key.withheld"
1997+ }
1998+ ) )
1999+ . unwrap ( ) ;
2000+
2001+ assert_matches ! (
2002+ entry,
2003+ RoomKeyWithheldEntry {
2004+ sender,
2005+ content: RoomKeyWithheldContent :: MegolmV1AesSha2 (
2006+ MegolmV1AesSha2WithheldContent :: Unauthorised ( withheld_content, )
2007+ ) ,
2008+ }
2009+ ) ;
2010+
2011+ assert_eq ! ( sender, "@alice:s.co" ) ;
2012+ assert_eq ! ( withheld_content. room_id, "!roomid:s.co" ) ;
2013+ assert_eq ! ( withheld_content. session_id, "session123" ) ;
2014+ assert_eq ! (
2015+ withheld_content. sender_key. to_base64( ) ,
2016+ "7hIcOrEroXYdzjtCBvBjUiqvT0Me7g+ymeXqoc65RS0"
2017+ ) ;
2018+ assert_eq ! ( withheld_content. from_device, Some ( owned_device_id!( "ALICE" ) ) ) ;
2019+ }
2020+
19722021 /// Create an inbound Megolm session for the given room.
19732022 ///
19742023 /// `olm_machine` is used to set the `sender_key` and `signing_key`
0 commit comments