@@ -12,6 +12,7 @@ use assign::assign;
12
12
use matrix_sdk:: {
13
13
Client , ClientBuilder , Room ,
14
14
config:: { RequestConfig , SyncSettings } ,
15
+ crypto:: { CollectStrategy , DecryptionSettings } ,
15
16
encryption:: EncryptionSettings ,
16
17
ruma:: {
17
18
RoomId ,
@@ -22,6 +23,7 @@ use matrix_sdk::{
22
23
sync:: SyncResponse ,
23
24
timeout:: ElapsedError ,
24
25
} ;
26
+ use matrix_sdk_base:: crypto:: TrustRequirement ;
25
27
use once_cell:: sync:: Lazy ;
26
28
use rand:: Rng as _;
27
29
use tempfile:: { TempDir , tempdir} ;
@@ -39,6 +41,8 @@ enum SqlitePath {
39
41
pub struct TestClientBuilder {
40
42
username : String ,
41
43
use_sqlite_dir : Option < SqlitePath > ,
44
+ decryption_settings : Option < DecryptionSettings > ,
45
+ room_key_recipient_strategy : CollectStrategy ,
42
46
encryption_settings : EncryptionSettings ,
43
47
enable_share_history_on_invite : bool ,
44
48
http_proxy : Option < String > ,
@@ -56,7 +60,9 @@ impl TestClientBuilder {
56
60
Self {
57
61
username,
58
62
use_sqlite_dir : None ,
63
+ decryption_settings : None ,
59
64
encryption_settings : Default :: default ( ) ,
65
+ room_key_recipient_strategy : Default :: default ( ) ,
60
66
enable_share_history_on_invite : false ,
61
67
http_proxy : None ,
62
68
cross_process_store_locks_holder_name : None ,
@@ -87,6 +93,21 @@ impl TestClientBuilder {
87
93
self
88
94
}
89
95
96
+ /// Simulate the behaviour of the clients when the "exclude insecure
97
+ /// devices" (MSC4153) labs flag is enabled.
98
+ pub fn exclude_insecure_devices ( mut self , exclude_insecure_devices : bool ) -> Self {
99
+ let ( sender_device_trust_requirement, room_key_recipient_strategy) =
100
+ if exclude_insecure_devices {
101
+ ( TrustRequirement :: CrossSignedOrLegacy , CollectStrategy :: IdentityBasedStrategy )
102
+ } else {
103
+ ( TrustRequirement :: Untrusted , CollectStrategy :: AllDevices )
104
+ } ;
105
+ self . decryption_settings = Some ( DecryptionSettings { sender_device_trust_requirement } ) ;
106
+ self . room_key_recipient_strategy = room_key_recipient_strategy;
107
+
108
+ self
109
+ }
110
+
90
111
pub fn http_proxy ( mut self , url : String ) -> Self {
91
112
self . http_proxy = Some ( url) ;
92
113
self
@@ -106,9 +127,14 @@ impl TestClientBuilder {
106
127
. homeserver_url ( homeserver_url)
107
128
. sliding_sync_version_builder ( VersionBuilder :: Native )
108
129
. with_encryption_settings ( self . encryption_settings )
130
+ . with_room_key_recipient_strategy ( self . room_key_recipient_strategy . clone ( ) )
109
131
. with_enable_share_history_on_invite ( self . enable_share_history_on_invite )
110
132
. request_config ( RequestConfig :: short_retry ( ) ) ;
111
133
134
+ if let Some ( decryption_settings) = & self . decryption_settings {
135
+ client_builder = client_builder. with_decryption_settings ( decryption_settings. clone ( ) )
136
+ }
137
+
112
138
if let Some ( holder_name) = & self . cross_process_store_locks_holder_name {
113
139
client_builder =
114
140
client_builder. cross_process_store_locks_holder_name ( holder_name. clone ( ) ) ;
0 commit comments