@@ -52,7 +52,7 @@ macro_rules! cryptostore_integration_tests {
5252 } ,
5353 store:: {
5454 BackupDecryptionKey , Changes , CryptoStore , DehydratedDeviceKey , DeviceChanges , GossipRequest ,
55- IdentityChanges , PendingChanges , RoomSettings ,
55+ IdentityChanges , PendingChanges , RoomSettings , StoredRoomKeyBundleData ,
5656 } ,
5757 testing:: { get_device, get_other_identity, get_own_identity} ,
5858 types:: {
@@ -64,6 +64,7 @@ macro_rules! cryptostore_integration_tests {
6464 CommonWithheldCodeContent , MegolmV1AesSha2WithheldContent ,
6565 RoomKeyWithheldContent ,
6666 } ,
67+ room_key_bundle:: RoomKeyBundleContent ,
6768 secret_send:: SecretSendContent ,
6869 ToDeviceEvent ,
6970 } ,
@@ -1276,6 +1277,57 @@ macro_rules! cryptostore_integration_tests {
12761277 assert_eq!( None , loaded_2) ;
12771278 }
12781279
1280+ #[ async_test]
1281+ #[ ignore] // not yet implemented for all stores
1282+ async fn test_received_room_key_bundle( ) {
1283+ let store = get_store( "received_room_key_bundle" , None , true ) . await ;
1284+ let test_room = room_id!( "!room:example.org" ) ;
1285+
1286+ fn make_bundle_data( sender_user: & UserId , bundle_uri: & str ) -> StoredRoomKeyBundleData {
1287+ let jwk = ruma:: events:: room:: JsonWebKeyInit {
1288+ kty: "oct" . to_owned( ) ,
1289+ key_ops: vec![ "encrypt" . to_owned( ) , "decrypt" . to_owned( ) ] ,
1290+ alg: "A256CTR" . to_owned( ) ,
1291+ k: ruma:: serde:: Base64 :: new( vec![ 0u8 ; 0 ] ) ,
1292+ ext: true ,
1293+ } . into( ) ;
1294+
1295+ let file = ruma:: events:: room:: EncryptedFileInit {
1296+ url: ruma:: OwnedMxcUri :: from( bundle_uri) ,
1297+ key: jwk,
1298+ iv: ruma:: serde:: Base64 :: new( vec![ 0u8 ; 0 ] ) ,
1299+ hashes: Default :: default ( ) ,
1300+ v: "" . to_owned( ) ,
1301+ } . into( ) ;
1302+
1303+ StoredRoomKeyBundleData {
1304+ sender_user: sender_user. to_owned( ) ,
1305+ sender_data: SenderData :: unknown( ) ,
1306+ bundle_data: RoomKeyBundleContent {
1307+ room_id: room_id!( "!room:example.org" ) . to_owned( ) ,
1308+ file,
1309+ } ,
1310+ }
1311+ }
1312+
1313+ // Add three entries
1314+ let changes = Changes {
1315+ received_room_key_bundles: vec![
1316+ make_bundle_data( user_id!( "@alice:example.com" ) , "alice1" ) ,
1317+ make_bundle_data( user_id!( "@bob:example.com" ) , "bob1" ) ,
1318+ make_bundle_data( user_id!( "@alice:example.com" ) , "alice2" ) ,
1319+ ] ,
1320+ ..Default :: default ( )
1321+ } ;
1322+ store. save_changes( changes) . await . unwrap( ) ;
1323+
1324+ // Check we get the right one
1325+ let bundle = store. get_received_room_key_bundle_data(
1326+ test_room, user_id!( "@alice:example.com" )
1327+ ) . await . unwrap( ) . expect( "Did not get any bundle data" ) ;
1328+ assert_eq!( bundle. bundle_data. file. url. to_string( ) , "alice2" ) ;
1329+ }
1330+
12791331 fn session_info( session: & InboundGroupSession ) -> ( & RoomId , & str ) {
12801332 ( & session. room_id( ) , & session. session_id( ) )
12811333 }
0 commit comments