|
16 | 16 | * along with this program. If not, see <https://www.gnu.org/licenses/>.
|
17 | 17 | */
|
18 | 18 |
|
| 19 | +import 'dart:io'; |
| 20 | + |
19 | 21 | import 'package:hive/hive.dart';
|
20 | 22 | import 'package:olm/olm.dart' as olm;
|
| 23 | +import 'package:test/test.dart'; |
21 | 24 |
|
22 | 25 | import 'package:matrix/matrix.dart';
|
23 | 26 | import '../test/fake_database.dart';
|
24 | 27 | import 'test_config.dart';
|
25 | 28 |
|
26 |
| -void main() => test(); |
27 | 29 | const String testMessage = 'Hello world';
|
28 | 30 | const String testMessage2 = 'Hello moon';
|
29 | 31 | const String testMessage3 = 'Hello sun';
|
30 | 32 | const String testMessage4 = 'Hello star';
|
31 | 33 | const String testMessage5 = 'Hello earth';
|
32 | 34 | const String testMessage6 = 'Hello mars';
|
33 | 35 |
|
34 |
| -void test() async { |
35 |
| - Client? testClientA, testClientB; |
| 36 | +void main() => group('Integration tests', () { |
| 37 | + test('E2EE', () async { |
| 38 | + Client? testClientA, testClientB; |
36 | 39 |
|
37 |
| - try { |
38 |
| - Hive.init(null); |
| 40 | + try { |
| 41 | + Hive.init(null); |
39 | 42 |
|
40 |
| - await olm.init(); |
41 |
| - olm.Account(); |
42 |
| - Logs().i('[LibOlm] Enabled'); |
| 43 | + await olm.init(); |
| 44 | + olm.Account(); |
| 45 | + Logs().i('[LibOlm] Enabled'); |
43 | 46 |
|
44 |
| - Logs().i('++++ Login Alice at ++++'); |
45 |
| - testClientA = Client('TestClientA', databaseBuilder: getDatabase); |
46 |
| - await testClientA.checkHomeserver(Uri.parse(TestUser.homeserver)); |
47 |
| - await testClientA.login(LoginType.mLoginPassword, |
48 |
| - identifier: |
49 |
| - AuthenticationUserIdentifier(user: TestUser.username.localpart!), |
50 |
| - password: TestUser.password); |
51 |
| - assert(testClientA.encryptionEnabled); |
| 47 | + Logs().i('++++ Login Alice at ++++'); |
| 48 | + testClientA = Client('TestClientA', databaseBuilder: getDatabase); |
| 49 | + await testClientA.checkHomeserver(Uri.parse(TestUser.homeserver)); |
| 50 | + await testClientA.login(LoginType.mLoginPassword, |
| 51 | + identifier: AuthenticationUserIdentifier( |
| 52 | + user: TestUser.username.localpart!), |
| 53 | + password: TestUser.password); |
| 54 | + expect(testClientA.encryptionEnabled, true); |
52 | 55 |
|
53 |
| - Logs().i('++++ Login Bob ++++'); |
54 |
| - testClientB = Client('TestClientB', databaseBuilder: getDatabase); |
55 |
| - await testClientB.checkHomeserver(Uri.parse(TestUser.homeserver)); |
56 |
| - await testClientB.login(LoginType.mLoginPassword, |
57 |
| - identifier: |
58 |
| - AuthenticationUserIdentifier(user: TestUser.username2.localpart!), |
59 |
| - password: TestUser.password2); |
60 |
| - assert(testClientB.encryptionEnabled); |
| 56 | + Logs().i('++++ Login Bob ++++'); |
| 57 | + testClientB = Client('TestClientB', databaseBuilder: getDatabase); |
| 58 | + await testClientB.checkHomeserver(Uri.parse(TestUser.homeserver)); |
| 59 | + await testClientB.login(LoginType.mLoginPassword, |
| 60 | + identifier: AuthenticationUserIdentifier( |
| 61 | + user: TestUser.username2.localpart!), |
| 62 | + password: TestUser.password2); |
| 63 | + expect(testClientB.encryptionEnabled, true); |
61 | 64 |
|
62 |
| - Logs().i('++++ (Alice) Leave all rooms ++++'); |
63 |
| - while (testClientA.rooms.isNotEmpty) { |
64 |
| - final room = testClientA.rooms.first; |
65 |
| - if (room.canonicalAlias.isNotEmpty) { |
66 |
| - break; |
67 |
| - } |
68 |
| - try { |
69 |
| - await room.leave(); |
70 |
| - await room.forget(); |
71 |
| - } catch (_) {} |
72 |
| - } |
| 65 | + Logs().i('++++ (Alice) Leave all rooms ++++'); |
| 66 | + while (testClientA.rooms.isNotEmpty) { |
| 67 | + final room = testClientA.rooms.first; |
| 68 | + if (room.canonicalAlias.isNotEmpty) { |
| 69 | + break; |
| 70 | + } |
| 71 | + try { |
| 72 | + await room.leave(); |
| 73 | + await room.forget(); |
| 74 | + } catch (_) {} |
| 75 | + } |
73 | 76 |
|
74 |
| - Logs().i('++++ (Bob) Leave all rooms ++++'); |
75 |
| - for (var i = 0; i < 3; i++) { |
76 |
| - if (testClientB.rooms.isNotEmpty) { |
77 |
| - final room = testClientB.rooms.first; |
78 |
| - try { |
79 |
| - await room.leave(); |
80 |
| - await room.forget(); |
81 |
| - } catch (_) {} |
82 |
| - } |
83 |
| - } |
| 77 | + Logs().i('++++ (Bob) Leave all rooms ++++'); |
| 78 | + for (var i = 0; i < 3; i++) { |
| 79 | + if (testClientB.rooms.isNotEmpty) { |
| 80 | + final room = testClientB.rooms.first; |
| 81 | + try { |
| 82 | + await room.leave(); |
| 83 | + await room.forget(); |
| 84 | + } catch (_) {} |
| 85 | + } |
| 86 | + } |
84 | 87 |
|
85 |
| - Logs().i('++++ Check if own olm device is verified by default ++++'); |
86 |
| - assert(testClientA.userDeviceKeys.containsKey(TestUser.username)); |
87 |
| - assert(testClientA.userDeviceKeys[TestUser.username]!.deviceKeys |
88 |
| - .containsKey(testClientA.deviceID)); |
89 |
| - assert(testClientA.userDeviceKeys[TestUser.username]! |
90 |
| - .deviceKeys[testClientA.deviceID!]!.verified); |
91 |
| - assert(!testClientA.userDeviceKeys[TestUser.username]! |
92 |
| - .deviceKeys[testClientA.deviceID!]!.blocked); |
93 |
| - assert(testClientB.userDeviceKeys.containsKey(TestUser.username2)); |
94 |
| - assert(testClientB.userDeviceKeys[TestUser.username2]!.deviceKeys |
95 |
| - .containsKey(testClientB.deviceID)); |
96 |
| - assert(testClientB.userDeviceKeys[TestUser.username2]! |
97 |
| - .deviceKeys[testClientB.deviceID!]!.verified); |
98 |
| - assert(!testClientB.userDeviceKeys[TestUser.username2]! |
99 |
| - .deviceKeys[testClientB.deviceID!]!.blocked); |
| 88 | + Logs().i('++++ Check if own olm device is verified by default ++++'); |
| 89 | + expect(testClientA.userDeviceKeys, contains(TestUser.username)); |
| 90 | + expect(testClientA.userDeviceKeys[TestUser.username]!.deviceKeys, |
| 91 | + contains(testClientA.deviceID)); |
| 92 | + expect( |
| 93 | + testClientA.userDeviceKeys[TestUser.username]! |
| 94 | + .deviceKeys[testClientA.deviceID!]!.verified, |
| 95 | + isTrue); |
| 96 | + expect( |
| 97 | + !testClientA.userDeviceKeys[TestUser.username]! |
| 98 | + .deviceKeys[testClientA.deviceID!]!.blocked, |
| 99 | + isTrue); |
| 100 | + expect(testClientB.userDeviceKeys, contains(TestUser.username2)); |
| 101 | + expect(testClientB.userDeviceKeys[TestUser.username2]!.deviceKeys, |
| 102 | + contains(testClientB.deviceID)); |
| 103 | + expect( |
| 104 | + testClientB.userDeviceKeys[TestUser.username2]! |
| 105 | + .deviceKeys[testClientB.deviceID!]!.verified, |
| 106 | + isTrue); |
| 107 | + expect( |
| 108 | + !testClientB.userDeviceKeys[TestUser.username2]! |
| 109 | + .deviceKeys[testClientB.deviceID!]!.blocked, |
| 110 | + isTrue); |
100 | 111 |
|
101 |
| - Logs().i('++++ (Alice) Create room and invite Bob ++++'); |
102 |
| - await testClientA.startDirectChat( |
103 |
| - TestUser.username2, |
104 |
| - enableEncryption: false, |
105 |
| - ); |
106 |
| - await Future.delayed(Duration(seconds: 1)); |
107 |
| - final room = testClientA.rooms.first; |
108 |
| - final roomId = room.id; |
| 112 | + Logs().i('++++ (Alice) Create room and invite Bob ++++'); |
| 113 | + await testClientA.startDirectChat( |
| 114 | + TestUser.username2, |
| 115 | + enableEncryption: false, |
| 116 | + ); |
| 117 | + await Future.delayed(Duration(seconds: 1)); |
| 118 | + final room = testClientA.rooms.first; |
| 119 | + final roomId = room.id; |
109 | 120 |
|
110 |
| - Logs().i('++++ (Bob) Join room ++++'); |
111 |
| - final inviteRoom = testClientB.getRoomById(roomId)!; |
112 |
| - await inviteRoom.join(); |
113 |
| - await Future.delayed(Duration(seconds: 1)); |
114 |
| - assert(inviteRoom.membership == Membership.join); |
| 121 | + Logs().i('++++ (Bob) Join room ++++'); |
| 122 | + final inviteRoom = testClientB.getRoomById(roomId)!; |
| 123 | + await inviteRoom.join(); |
| 124 | + await Future.delayed(Duration(seconds: 1)); |
| 125 | + expect(inviteRoom.membership, Membership.join); |
115 | 126 |
|
116 |
| - Logs().i('++++ (Alice) Enable encryption ++++'); |
117 |
| - assert(room.encrypted == false); |
118 |
| - await room.enableEncryption(); |
119 |
| - await Future.delayed(Duration(seconds: 5)); |
120 |
| - assert(room.encrypted == true); |
121 |
| - assert( |
122 |
| - room.client.encryption!.keyManager.getOutboundGroupSession(room.id) == |
123 |
| - null); |
| 127 | + Logs().i('++++ (Alice) Enable encryption ++++'); |
| 128 | + expect(room.encrypted, false); |
| 129 | + await room.enableEncryption(); |
| 130 | + await Future.delayed(Duration(seconds: 5)); |
| 131 | + expect(room.encrypted, isTrue); |
| 132 | + expect( |
| 133 | + room.client.encryption!.keyManager |
| 134 | + .getOutboundGroupSession(room.id), |
| 135 | + null); |
124 | 136 |
|
125 |
| - Logs().i('++++ (Alice) Check known olm devices ++++'); |
126 |
| - assert(testClientA.userDeviceKeys.containsKey(TestUser.username2)); |
127 |
| - assert(testClientA.userDeviceKeys[TestUser.username2]!.deviceKeys |
128 |
| - .containsKey(testClientB.deviceID)); |
129 |
| - assert(!testClientA.userDeviceKeys[TestUser.username2]! |
130 |
| - .deviceKeys[testClientB.deviceID!]!.verified); |
131 |
| - assert(!testClientA.userDeviceKeys[TestUser.username2]! |
132 |
| - .deviceKeys[testClientB.deviceID!]!.blocked); |
133 |
| - assert(testClientB.userDeviceKeys.containsKey(TestUser.username)); |
134 |
| - assert(testClientB.userDeviceKeys[TestUser.username]!.deviceKeys |
135 |
| - .containsKey(testClientA.deviceID)); |
136 |
| - assert(!testClientB.userDeviceKeys[TestUser.username]! |
137 |
| - .deviceKeys[testClientA.deviceID!]!.verified); |
138 |
| - assert(!testClientB.userDeviceKeys[TestUser.username]! |
139 |
| - .deviceKeys[testClientA.deviceID!]!.blocked); |
140 |
| - await Future.wait([ |
141 |
| - testClientA.updateUserDeviceKeys(), |
142 |
| - testClientB.updateUserDeviceKeys(), |
143 |
| - ]); |
144 |
| - await testClientA |
145 |
| - .userDeviceKeys[TestUser.username2]!.deviceKeys[testClientB.deviceID!]! |
146 |
| - .setVerified(true); |
| 137 | + Logs().i('++++ (Alice) Check known olm devices ++++'); |
| 138 | + expect(testClientA.userDeviceKeys, contains(TestUser.username2)); |
| 139 | + expect(testClientA.userDeviceKeys[TestUser.username2]!.deviceKeys, |
| 140 | + contains(testClientB.deviceID)); |
| 141 | + expect( |
| 142 | + testClientA.userDeviceKeys[TestUser.username2]! |
| 143 | + .deviceKeys[testClientB.deviceID!]!.verified, |
| 144 | + isFalse); |
| 145 | + expect( |
| 146 | + testClientA.userDeviceKeys[TestUser.username2]! |
| 147 | + .deviceKeys[testClientB.deviceID!]!.blocked, |
| 148 | + isFalse); |
| 149 | + expect(testClientB.userDeviceKeys, contains(TestUser.username)); |
| 150 | + expect(testClientB.userDeviceKeys[TestUser.username]!.deviceKeys, |
| 151 | + contains(testClientA.deviceID)); |
| 152 | + expect( |
| 153 | + testClientB.userDeviceKeys[TestUser.username]! |
| 154 | + .deviceKeys[testClientA.deviceID!]!.verified, |
| 155 | + isFalse); |
| 156 | + expect( |
| 157 | + testClientB.userDeviceKeys[TestUser.username]! |
| 158 | + .deviceKeys[testClientA.deviceID!]!.blocked, |
| 159 | + isFalse); |
| 160 | + await Future.wait([ |
| 161 | + testClientA.updateUserDeviceKeys(), |
| 162 | + testClientB.updateUserDeviceKeys(), |
| 163 | + ]); |
| 164 | + await testClientA.userDeviceKeys[TestUser.username2]! |
| 165 | + .deviceKeys[testClientB.deviceID!]! |
| 166 | + .setVerified(true); |
147 | 167 |
|
148 |
| - Logs().i('++++ Check if own olm device is verified by default ++++'); |
149 |
| - assert(testClientA.userDeviceKeys.containsKey(TestUser.username)); |
150 |
| - assert(testClientA.userDeviceKeys[TestUser.username]!.deviceKeys |
151 |
| - .containsKey(testClientA.deviceID)); |
152 |
| - assert(testClientA.userDeviceKeys[TestUser.username]! |
153 |
| - .deviceKeys[testClientA.deviceID!]!.verified); |
154 |
| - assert(testClientB.userDeviceKeys.containsKey(TestUser.username2)); |
155 |
| - assert(testClientB.userDeviceKeys[TestUser.username2]!.deviceKeys |
156 |
| - .containsKey(testClientB.deviceID)); |
157 |
| - assert(testClientB.userDeviceKeys[TestUser.username2]! |
158 |
| - .deviceKeys[testClientB.deviceID!]!.verified); |
| 168 | + Logs().i('++++ Check if own olm device is verified by default ++++'); |
| 169 | + expect(testClientA.userDeviceKeys, contains(TestUser.username)); |
| 170 | + expect(testClientA.userDeviceKeys[TestUser.username]!.deviceKeys, |
| 171 | + contains(testClientA.deviceID)); |
| 172 | + expect( |
| 173 | + testClientA.userDeviceKeys[TestUser.username]! |
| 174 | + .deviceKeys[testClientA.deviceID!]!.verified, |
| 175 | + isTrue); |
| 176 | + expect(testClientB.userDeviceKeys, contains(TestUser.username2)); |
| 177 | + expect(testClientB.userDeviceKeys[TestUser.username2]!.deviceKeys, |
| 178 | + contains(testClientB.deviceID)); |
| 179 | + expect( |
| 180 | + testClientB.userDeviceKeys[TestUser.username2]! |
| 181 | + .deviceKeys[testClientB.deviceID!]!.verified, |
| 182 | + isTrue); |
159 | 183 |
|
160 |
| - Logs().i("++++ (Alice) Send encrypted message: '$testMessage' ++++"); |
161 |
| - await room.sendTextEvent(testMessage); |
162 |
| - await Future.delayed(Duration(seconds: 5)); |
163 |
| - assert( |
164 |
| - room.client.encryption!.keyManager.getOutboundGroupSession(room.id) != |
165 |
| - null); |
166 |
| - var currentSessionIdA = room.client.encryption!.keyManager |
167 |
| - .getOutboundGroupSession(room.id)! |
168 |
| - .outboundGroupSession! |
169 |
| - .session_id(); |
170 |
| - /*assert(room.client.encryption.keyManager |
| 184 | + Logs().i("++++ (Alice) Send encrypted message: '$testMessage' ++++"); |
| 185 | + await room.sendTextEvent(testMessage); |
| 186 | + await Future.delayed(Duration(seconds: 5)); |
| 187 | + expect( |
| 188 | + room.client.encryption!.keyManager |
| 189 | + .getOutboundGroupSession(room.id), |
| 190 | + isNotNull); |
| 191 | + var currentSessionIdA = room.client.encryption!.keyManager |
| 192 | + .getOutboundGroupSession(room.id)! |
| 193 | + .outboundGroupSession! |
| 194 | + .session_id(); |
| 195 | + /*expect(room.client.encryption.keyManager |
171 | 196 | .getInboundGroupSession(room.id, currentSessionIdA, '') !=
|
172 | 197 | null);*/
|
173 |
| - assert(testClientA.encryption!.olmManager |
174 |
| - .olmSessions[testClientB.identityKey]!.length == |
175 |
| - 1); |
176 |
| - assert(testClientB.encryption!.olmManager |
177 |
| - .olmSessions[testClientA.identityKey]!.length == |
178 |
| - 1); |
179 |
| - assert(testClientA.encryption!.olmManager |
180 |
| - .olmSessions[testClientB.identityKey]!.first.sessionId == |
181 |
| - testClientB.encryption!.olmManager.olmSessions[testClientA.identityKey]! |
182 |
| - .first.sessionId); |
183 |
| - /*assert(inviteRoom.client.encryption.keyManager |
| 198 | + expect( |
| 199 | + testClientA.encryption!.olmManager |
| 200 | + .olmSessions[testClientB.identityKey]!.length, |
| 201 | + 1); |
| 202 | + expect( |
| 203 | + testClientB.encryption!.olmManager |
| 204 | + .olmSessions[testClientA.identityKey]!.length, |
| 205 | + 1); |
| 206 | + expect( |
| 207 | + testClientA.encryption!.olmManager |
| 208 | + .olmSessions[testClientB.identityKey]!.first.sessionId, |
| 209 | + testClientB.encryption!.olmManager |
| 210 | + .olmSessions[testClientA.identityKey]!.first.sessionId); |
| 211 | + /*expect(inviteRoom.client.encryption.keyManager |
184 | 212 | .getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') !=
|
185 | 213 | null);*/
|
186 |
| - assert(room.lastEvent!.body == testMessage); |
187 |
| - assert(inviteRoom.lastEvent!.body == testMessage); |
188 |
| - Logs().i( |
189 |
| - "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++"); |
| 214 | + expect(room.lastEvent!.body, testMessage); |
| 215 | + expect(inviteRoom.lastEvent!.body, testMessage); |
| 216 | + Logs().i( |
| 217 | + "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++"); |
190 | 218 |
|
191 |
| - Logs().i("++++ (Alice) Send again encrypted message: '$testMessage2' ++++"); |
192 |
| - await room.sendTextEvent(testMessage2); |
193 |
| - await Future.delayed(Duration(seconds: 5)); |
194 |
| - assert(testClientA.encryption!.olmManager |
195 |
| - .olmSessions[testClientB.identityKey]!.length == |
196 |
| - 1); |
197 |
| - assert(testClientB.encryption!.olmManager |
198 |
| - .olmSessions[testClientA.identityKey]!.length == |
199 |
| - 1); |
200 |
| - assert(testClientA.encryption!.olmManager |
201 |
| - .olmSessions[testClientB.identityKey]!.first.sessionId == |
202 |
| - testClientB.encryption!.olmManager.olmSessions[testClientA.identityKey]! |
203 |
| - .first.sessionId); |
| 219 | + Logs().i( |
| 220 | + "++++ (Alice) Send again encrypted message: '$testMessage2' ++++"); |
| 221 | + await room.sendTextEvent(testMessage2); |
| 222 | + await Future.delayed(Duration(seconds: 5)); |
| 223 | + expect( |
| 224 | + testClientA.encryption!.olmManager |
| 225 | + .olmSessions[testClientB.identityKey]!.length, |
| 226 | + 1); |
| 227 | + expect( |
| 228 | + testClientB.encryption!.olmManager |
| 229 | + .olmSessions[testClientA.identityKey]!.length, |
| 230 | + 1); |
| 231 | + expect( |
| 232 | + testClientA.encryption!.olmManager |
| 233 | + .olmSessions[testClientB.identityKey]!.first.sessionId, |
| 234 | + testClientB.encryption!.olmManager |
| 235 | + .olmSessions[testClientA.identityKey]!.first.sessionId); |
204 | 236 |
|
205 |
| - assert(room.client.encryption!.keyManager |
206 |
| - .getOutboundGroupSession(room.id)! |
207 |
| - .outboundGroupSession! |
208 |
| - .session_id() == |
209 |
| - currentSessionIdA); |
210 |
| - /*assert(room.client.encryption.keyManager |
| 237 | + expect( |
| 238 | + room.client.encryption!.keyManager |
| 239 | + .getOutboundGroupSession(room.id)! |
| 240 | + .outboundGroupSession! |
| 241 | + .session_id(), |
| 242 | + currentSessionIdA); |
| 243 | + /*expect(room.client.encryption.keyManager |
211 | 244 | .getInboundGroupSession(room.id, currentSessionIdA, '') !=
|
212 | 245 | null);*/
|
213 |
| - assert(room.lastEvent!.body == testMessage2); |
214 |
| - assert(inviteRoom.lastEvent!.body == testMessage2); |
215 |
| - Logs().i( |
216 |
| - "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++"); |
| 246 | + expect(room.lastEvent!.body, testMessage2); |
| 247 | + expect(inviteRoom.lastEvent!.body, testMessage2); |
| 248 | + Logs().i( |
| 249 | + "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++"); |
217 | 250 |
|
218 |
| - Logs().i("++++ (Bob) Send again encrypted message: '$testMessage3' ++++"); |
219 |
| - await inviteRoom.sendTextEvent(testMessage3); |
220 |
| - await Future.delayed(Duration(seconds: 5)); |
221 |
| - assert(testClientA.encryption!.olmManager |
222 |
| - .olmSessions[testClientB.identityKey]!.length == |
223 |
| - 1); |
224 |
| - assert(testClientB.encryption!.olmManager |
225 |
| - .olmSessions[testClientA.identityKey]!.length == |
226 |
| - 1); |
227 |
| - assert(room.client.encryption!.keyManager |
228 |
| - .getOutboundGroupSession(room.id)! |
229 |
| - .outboundGroupSession! |
230 |
| - .session_id() == |
231 |
| - currentSessionIdA); |
232 |
| - final inviteRoomOutboundGroupSession = inviteRoom |
233 |
| - .client.encryption!.keyManager |
234 |
| - .getOutboundGroupSession(inviteRoom.id)!; |
| 251 | + Logs().i( |
| 252 | + "++++ (Bob) Send again encrypted message: '$testMessage3' ++++"); |
| 253 | + await inviteRoom.sendTextEvent(testMessage3); |
| 254 | + await Future.delayed(Duration(seconds: 5)); |
| 255 | + expect( |
| 256 | + testClientA.encryption!.olmManager |
| 257 | + .olmSessions[testClientB.identityKey]!.length, |
| 258 | + 1); |
| 259 | + expect( |
| 260 | + testClientB.encryption!.olmManager |
| 261 | + .olmSessions[testClientA.identityKey]!.length, |
| 262 | + 1); |
| 263 | + expect( |
| 264 | + room.client.encryption!.keyManager |
| 265 | + .getOutboundGroupSession(room.id)! |
| 266 | + .outboundGroupSession! |
| 267 | + .session_id(), |
| 268 | + currentSessionIdA); |
| 269 | + final inviteRoomOutboundGroupSession = inviteRoom |
| 270 | + .client.encryption!.keyManager |
| 271 | + .getOutboundGroupSession(inviteRoom.id)!; |
235 | 272 |
|
236 |
| - assert(inviteRoomOutboundGroupSession.isValid); |
237 |
| - /*assert(inviteRoom.client.encryption.keyManager.getInboundGroupSession( |
| 273 | + expect(inviteRoomOutboundGroupSession.isValid, isTrue); |
| 274 | + /*expect(inviteRoom.client.encryption.keyManager.getInboundGroupSession( |
238 | 275 | inviteRoom.id,
|
239 | 276 | inviteRoomOutboundGroupSession.outboundGroupSession.session_id(),
|
240 | 277 | '') !=
|
241 | 278 | null);
|
242 |
| - assert(room.client.encryption.keyManager.getInboundGroupSession( |
| 279 | + expect(room.client.encryption.keyManager.getInboundGroupSession( |
243 | 280 | room.id,
|
244 | 281 | inviteRoomOutboundGroupSession.outboundGroupSession.session_id(),
|
245 | 282 | '') !=
|
246 | 283 | null);*/
|
247 |
| - assert(inviteRoom.lastEvent!.body == testMessage3); |
248 |
| - assert(room.lastEvent!.body == testMessage3); |
249 |
| - Logs().i( |
250 |
| - "++++ (Alice) Received decrypted message: '${room.lastEvent!.body}' ++++"); |
| 284 | + expect(inviteRoom.lastEvent!.body, testMessage3); |
| 285 | + expect(room.lastEvent!.body, testMessage3); |
| 286 | + Logs().i( |
| 287 | + "++++ (Alice) Received decrypted message: '${room.lastEvent!.body}' ++++"); |
251 | 288 |
|
252 |
| - Logs().i('++++ Login Bob in another client ++++'); |
253 |
| - final testClientC = Client('TestClientC', databaseBuilder: getDatabase); |
254 |
| - await testClientC.checkHomeserver(Uri.parse(TestUser.homeserver)); |
255 |
| - // Workaround: Logging in with displayname instead of mxid |
256 |
| - await testClientC.login(LoginType.mLoginPassword, |
257 |
| - identifier: AuthenticationUserIdentifier(user: TestUser.displayname2), |
258 |
| - password: TestUser.password2); |
259 |
| - await Future.delayed(Duration(seconds: 3)); |
| 289 | + Logs().i('++++ Login Bob in another client ++++'); |
| 290 | + final testClientC = |
| 291 | + Client('TestClientC', databaseBuilder: getDatabase); |
| 292 | + await testClientC.checkHomeserver(Uri.parse(TestUser.homeserver)); |
| 293 | + // We can't sign in using the displayname, since that breaks e2ee on dendrite: https://github.com/matrix-org/dendrite/issues/2914 |
| 294 | + await testClientC.login(LoginType.mLoginPassword, |
| 295 | + identifier: AuthenticationUserIdentifier( |
| 296 | + user: TestUser.username2.localpart!), |
| 297 | + password: TestUser.password2); |
| 298 | + await Future.delayed(Duration(seconds: 3)); |
260 | 299 |
|
261 |
| - Logs().i("++++ (Alice) Send again encrypted message: '$testMessage4' ++++"); |
262 |
| - await room.sendTextEvent(testMessage4); |
263 |
| - await Future.delayed(Duration(seconds: 5)); |
264 |
| - assert(testClientA.encryption!.olmManager |
265 |
| - .olmSessions[testClientB.identityKey]!.length == |
266 |
| - 1); |
267 |
| - assert(testClientB.encryption!.olmManager |
268 |
| - .olmSessions[testClientA.identityKey]!.length == |
269 |
| - 1); |
270 |
| - assert(testClientA.encryption!.olmManager |
271 |
| - .olmSessions[testClientB.identityKey]!.first.sessionId == |
272 |
| - testClientB.encryption!.olmManager.olmSessions[testClientA.identityKey]! |
273 |
| - .first.sessionId); |
274 |
| - assert(testClientA.encryption!.olmManager |
275 |
| - .olmSessions[testClientC.identityKey]!.length == |
276 |
| - 1); |
277 |
| - assert(testClientC.encryption!.olmManager |
278 |
| - .olmSessions[testClientA.identityKey]!.length == |
279 |
| - 1); |
280 |
| - assert(testClientA.encryption!.olmManager |
281 |
| - .olmSessions[testClientC.identityKey]!.first.sessionId == |
282 |
| - testClientC.encryption!.olmManager.olmSessions[testClientA.identityKey]! |
283 |
| - .first.sessionId); |
284 |
| - assert(room.client.encryption!.keyManager |
285 |
| - .getOutboundGroupSession(room.id)! |
286 |
| - .outboundGroupSession! |
287 |
| - .session_id() != |
288 |
| - currentSessionIdA); |
289 |
| - currentSessionIdA = room.client.encryption!.keyManager |
290 |
| - .getOutboundGroupSession(room.id)! |
291 |
| - .outboundGroupSession! |
292 |
| - .session_id(); |
293 |
| - /*assert(inviteRoom.client.encryption.keyManager |
| 300 | + Logs().i( |
| 301 | + "++++ (Alice) Send again encrypted message: '$testMessage4' ++++"); |
| 302 | + await room.sendTextEvent(testMessage4); |
| 303 | + await Future.delayed(Duration(seconds: 5)); |
| 304 | + expect( |
| 305 | + testClientA.encryption!.olmManager |
| 306 | + .olmSessions[testClientB.identityKey]!.length, |
| 307 | + 1); |
| 308 | + expect( |
| 309 | + testClientB.encryption!.olmManager |
| 310 | + .olmSessions[testClientA.identityKey]!.length, |
| 311 | + 1); |
| 312 | + expect( |
| 313 | + testClientA.encryption!.olmManager |
| 314 | + .olmSessions[testClientB.identityKey]!.first.sessionId, |
| 315 | + testClientB.encryption!.olmManager |
| 316 | + .olmSessions[testClientA.identityKey]!.first.sessionId); |
| 317 | + expect( |
| 318 | + testClientA.encryption!.olmManager |
| 319 | + .olmSessions[testClientC.identityKey]!.length, |
| 320 | + 1); |
| 321 | + expect( |
| 322 | + testClientC.encryption!.olmManager |
| 323 | + .olmSessions[testClientA.identityKey]!.length, |
| 324 | + 1); |
| 325 | + expect( |
| 326 | + testClientA.encryption!.olmManager |
| 327 | + .olmSessions[testClientC.identityKey]!.first.sessionId, |
| 328 | + testClientC.encryption!.olmManager |
| 329 | + .olmSessions[testClientA.identityKey]!.first.sessionId); |
| 330 | + expect( |
| 331 | + room.client.encryption!.keyManager |
| 332 | + .getOutboundGroupSession(room.id)! |
| 333 | + .outboundGroupSession! |
| 334 | + .session_id(), |
| 335 | + currentSessionIdA); |
| 336 | + /*expect(inviteRoom.client.encryption.keyManager |
294 | 337 | .getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') !=
|
295 | 338 | null);*/
|
296 |
| - assert(room.lastEvent!.body == testMessage4); |
297 |
| - assert(inviteRoom.lastEvent!.body == testMessage4); |
298 |
| - Logs().i( |
299 |
| - "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++"); |
| 339 | + expect(room.lastEvent!.body, testMessage4); |
| 340 | + expect(inviteRoom.lastEvent!.body, testMessage4); |
| 341 | + Logs().i( |
| 342 | + "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++"); |
| 343 | + |
| 344 | + Logs() |
| 345 | + .i('++++ Logout Bob another client ${testClientC.deviceID} ++++'); |
| 346 | + await testClientC.dispose(closeDatabase: false); |
| 347 | + await testClientC.logout(); |
| 348 | + await Future.delayed(Duration(seconds: 5)); |
300 | 349 |
|
301 |
| - Logs().i('++++ Logout Bob another client ++++'); |
302 |
| - await testClientC.dispose(closeDatabase: false); |
303 |
| - await testClientC.logout(); |
304 |
| - await Future.delayed(Duration(seconds: 5)); |
| 350 | + Logs().i( |
| 351 | + "++++ (Alice) Send again encrypted message: '$testMessage6' ++++"); |
| 352 | + await room.sendTextEvent(testMessage6); |
| 353 | + await Future.delayed(Duration(seconds: 5)); |
| 354 | + expect( |
| 355 | + testClientA.encryption!.olmManager |
| 356 | + .olmSessions[testClientB.identityKey]!.length, |
| 357 | + 1); |
| 358 | + expect( |
| 359 | + testClientB.encryption!.olmManager |
| 360 | + .olmSessions[testClientA.identityKey]!.length, |
| 361 | + 1); |
| 362 | + expect( |
| 363 | + testClientA.encryption!.olmManager |
| 364 | + .olmSessions[testClientB.identityKey]!.first.sessionId, |
| 365 | + testClientB.encryption!.olmManager |
| 366 | + .olmSessions[testClientA.identityKey]!.first.sessionId); |
305 | 367 |
|
306 |
| - Logs().i("++++ (Alice) Send again encrypted message: '$testMessage6' ++++"); |
307 |
| - await room.sendTextEvent(testMessage6); |
308 |
| - await Future.delayed(Duration(seconds: 5)); |
309 |
| - assert(testClientA.encryption!.olmManager |
310 |
| - .olmSessions[testClientB.identityKey]!.length == |
311 |
| - 1); |
312 |
| - assert(testClientB.encryption!.olmManager |
313 |
| - .olmSessions[testClientA.identityKey]!.length == |
314 |
| - 1); |
315 |
| - assert(testClientA.encryption!.olmManager |
316 |
| - .olmSessions[testClientB.identityKey]!.first.sessionId == |
317 |
| - testClientB.encryption!.olmManager.olmSessions[testClientA.identityKey]! |
318 |
| - .first.sessionId); |
319 |
| - assert(room.client.encryption!.keyManager |
320 |
| - .getOutboundGroupSession(room.id)! |
321 |
| - .outboundGroupSession! |
322 |
| - .session_id() != |
323 |
| - currentSessionIdA); |
324 |
| - currentSessionIdA = room.client.encryption!.keyManager |
325 |
| - .getOutboundGroupSession(room.id)! |
326 |
| - .outboundGroupSession! |
327 |
| - .session_id(); |
328 |
| - /*assert(inviteRoom.client.encryption.keyManager |
| 368 | + // This does not work on conduit because of a server bug: https://gitlab.com/famedly/conduit/-/issues/325 |
| 369 | + if (Platform.environment['HOMESERVER'] != 'conduit') { |
| 370 | + expect( |
| 371 | + room.client.encryption!.keyManager |
| 372 | + .getOutboundGroupSession(room.id)! |
| 373 | + .outboundGroupSession! |
| 374 | + .session_id(), |
| 375 | + isNot(currentSessionIdA)); |
| 376 | + } |
| 377 | + currentSessionIdA = room.client.encryption!.keyManager |
| 378 | + .getOutboundGroupSession(room.id)! |
| 379 | + .outboundGroupSession! |
| 380 | + .session_id(); |
| 381 | + /*expect(inviteRoom.client.encryption.keyManager |
329 | 382 | .getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') !=
|
330 | 383 | null);*/
|
331 |
| - assert(room.lastEvent!.body == testMessage6); |
332 |
| - assert(inviteRoom.lastEvent!.body == testMessage6); |
333 |
| - Logs().i( |
334 |
| - "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++"); |
| 384 | + expect(room.lastEvent!.body, testMessage6); |
| 385 | + expect(inviteRoom.lastEvent!.body, testMessage6); |
| 386 | + Logs().i( |
| 387 | + "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++"); |
335 | 388 |
|
336 |
| - await room.leave(); |
337 |
| - await room.forget(); |
338 |
| - await inviteRoom.leave(); |
339 |
| - await inviteRoom.forget(); |
340 |
| - await Future.delayed(Duration(seconds: 1)); |
341 |
| - } catch (e, s) { |
342 |
| - Logs().e('Test failed', e, s); |
343 |
| - rethrow; |
344 |
| - } finally { |
345 |
| - Logs().i('++++ Logout Alice and Bob ++++'); |
346 |
| - if (testClientA?.isLogged() ?? false) await testClientA!.logoutAll(); |
347 |
| - if (testClientA?.isLogged() ?? false) await testClientB!.logoutAll(); |
348 |
| - await testClientA?.dispose(closeDatabase: false); |
349 |
| - await testClientB?.dispose(closeDatabase: false); |
350 |
| - testClientA = null; |
351 |
| - testClientB = null; |
352 |
| - } |
353 |
| - return; |
354 |
| -} |
| 389 | + await room.leave(); |
| 390 | + await room.forget(); |
| 391 | + await inviteRoom.leave(); |
| 392 | + await inviteRoom.forget(); |
| 393 | + await Future.delayed(Duration(seconds: 1)); |
| 394 | + } catch (e, s) { |
| 395 | + Logs().e('Test failed', e, s); |
| 396 | + rethrow; |
| 397 | + } finally { |
| 398 | + Logs().i('++++ Logout Alice and Bob ++++'); |
| 399 | + if (testClientA?.isLogged() ?? false) await testClientA!.logoutAll(); |
| 400 | + if (testClientA?.isLogged() ?? false) await testClientB!.logoutAll(); |
| 401 | + await testClientA?.dispose(closeDatabase: false); |
| 402 | + await testClientB?.dispose(closeDatabase: false); |
| 403 | + testClientA = null; |
| 404 | + testClientB = null; |
| 405 | + } |
| 406 | + return; |
| 407 | + }); |
| 408 | + }, timeout: Timeout(Duration(minutes: 6))); |
0 commit comments