@@ -27,6 +27,7 @@ use tracing::{debug, instrument, trace};
27
27
use super :: OutboundGroupSession ;
28
28
use crate :: {
29
29
error:: { OlmResult , SessionRecipientCollectionError } ,
30
+ olm:: ShareInfo ,
30
31
store:: Store ,
31
32
DeviceData , EncryptionSettings , LocalTrust , OlmError , OwnUserIdentityData , UserIdentityData ,
32
33
} ;
@@ -433,7 +434,11 @@ fn is_session_overshared_for_user(
433
434
} ;
434
435
435
436
// Devices that received this session
436
- let shared: BTreeSet < & DeviceId > = shared. keys ( ) . map ( |d| d. as_ref ( ) ) . collect ( ) ;
437
+ let shared: BTreeSet < & DeviceId > = shared
438
+ . iter ( )
439
+ . filter ( |( _, info) | matches ! ( info, ShareInfo :: Shared ( _) ) )
440
+ . map ( |( d, _) | d. as_ref ( ) )
441
+ . collect ( ) ;
437
442
438
443
// The set difference between
439
444
//
@@ -2095,9 +2100,55 @@ mod tests {
2095
2100
let machine = test_machine ( ) . await ;
2096
2101
import_known_users_to_test_machine ( & machine) . await ;
2097
2102
2098
- let fake_room_id = room_id ! ( "!roomid:localhost" ) ;
2099
2103
let encryption_settings = all_devices_strategy_settings ( ) ;
2104
+ let group_session = create_test_outbound_group_session ( & machine, & encryption_settings) ;
2105
+ let sender_key = machine. identity_keys ( ) . curve25519 ;
2106
+
2107
+ group_session
2108
+ . mark_shared_with (
2109
+ KeyDistributionTestData :: dan_id ( ) ,
2110
+ KeyDistributionTestData :: dan_signed_device_id ( ) ,
2111
+ sender_key,
2112
+ )
2113
+ . await ;
2114
+ group_session
2115
+ . mark_shared_with (
2116
+ KeyDistributionTestData :: dan_id ( ) ,
2117
+ KeyDistributionTestData :: dan_unsigned_device_id ( ) ,
2118
+ sender_key,
2119
+ )
2120
+ . await ;
2121
+
2122
+ // Try to share again after dan has removed one of his devices
2123
+ let keys_query = KeyDistributionTestData :: dan_keys_query_response_device_loggedout ( ) ;
2124
+ machine. mark_request_as_sent ( & TransactionId :: new ( ) , & keys_query) . await . unwrap ( ) ;
2100
2125
2126
+ // share again
2127
+ let share_result = collect_session_recipients (
2128
+ machine. store ( ) ,
2129
+ vec ! [ KeyDistributionTestData :: dan_id( ) ] . into_iter ( ) ,
2130
+ & encryption_settings,
2131
+ & group_session,
2132
+ )
2133
+ . await
2134
+ . unwrap ( ) ;
2135
+
2136
+ assert ! ( share_result. should_rotate) ;
2137
+ }
2138
+
2139
+ /// Test that the session is not rotated if a devices is removed
2140
+ /// but was already withheld from receiving the session.
2141
+ #[ async_test]
2142
+ async fn test_should_not_rotate_if_keys_were_withheld ( ) {
2143
+ let machine = test_machine ( ) . await ;
2144
+ import_known_users_to_test_machine ( & machine) . await ;
2145
+
2146
+ let encryption_settings = all_devices_strategy_settings ( ) ;
2147
+ let group_session = create_test_outbound_group_session ( & machine, & encryption_settings) ;
2148
+ let fake_room_id = group_session. room_id ( ) ;
2149
+
2150
+ // Because we don't have Olm sessions initialized, this will contain
2151
+ // withheld requests for both of Dan's devices
2101
2152
let requests = machine
2102
2153
. share_room_key (
2103
2154
fake_room_id,
@@ -2115,13 +2166,11 @@ mod tests {
2115
2166
. await
2116
2167
. unwrap ( ) ;
2117
2168
}
2169
+
2118
2170
// Try to share again after dan has removed one of his devices
2119
2171
let keys_query = KeyDistributionTestData :: dan_keys_query_response_device_loggedout ( ) ;
2120
- let txn_id = TransactionId :: new ( ) ;
2121
- machine. mark_request_as_sent ( & txn_id, & keys_query) . await . unwrap ( ) ;
2172
+ machine. mark_request_as_sent ( & TransactionId :: new ( ) , & keys_query) . await . unwrap ( ) ;
2122
2173
2123
- let group_session =
2124
- machine. store ( ) . get_outbound_group_session ( fake_room_id) . await . unwrap ( ) . unwrap ( ) ;
2125
2174
// share again
2126
2175
let share_result = collect_session_recipients (
2127
2176
machine. store ( ) ,
@@ -2132,7 +2181,7 @@ mod tests {
2132
2181
. await
2133
2182
. unwrap ( ) ;
2134
2183
2135
- assert ! ( share_result. should_rotate) ;
2184
+ assert ! ( ! share_result. should_rotate) ;
2136
2185
}
2137
2186
2138
2187
/// Common setup for tests which require a verified user to have unsigned
0 commit comments