chore: use proper matchers in integration tests

This commit is contained in:
Nicolas Werner 2022-12-12 05:23:38 +01:00
parent 90e8d5b118
commit 8c2d7d78d8
No known key found for this signature in database
3 changed files with 349 additions and 286 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@
*.swo *.swo
*.swn *.swn
*.dylib *.dylib
*.bakmacoscompat
.DS_Store .DS_Store
.atom/ .atom/
.buildlog/ .buildlog/

View File

@ -382,6 +382,14 @@ class KeyManager {
.where((e) => !e.value) .where((e) => !e.value)
.map((e) => e.key)) .map((e) => e.key))
: <String>{}; : <String>{};
// check if a device got removed
if (oldDeviceIds.difference(newDeviceIds).isNotEmpty) {
wipe = true;
break;
}
// check if any new devices need keys
final newDevices = newDeviceIds.difference(oldDeviceIds); final newDevices = newDeviceIds.difference(oldDeviceIds);
if (newDeviceIds.isNotEmpty) { if (newDeviceIds.isNotEmpty) {
devicesToReceive.addAll(newDeviceKeys.where( devicesToReceive.addAll(newDeviceKeys.where(

View File

@ -16,14 +16,16 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import 'dart:io';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:olm/olm.dart' as olm; import 'package:olm/olm.dart' as olm;
import 'package:test/test.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import '../test/fake_database.dart'; import '../test/fake_database.dart';
import 'test_config.dart'; import 'test_config.dart';
void main() => test();
const String testMessage = 'Hello world'; const String testMessage = 'Hello world';
const String testMessage2 = 'Hello moon'; const String testMessage2 = 'Hello moon';
const String testMessage3 = 'Hello sun'; const String testMessage3 = 'Hello sun';
@ -31,324 +33,376 @@ const String testMessage4 = 'Hello star';
const String testMessage5 = 'Hello earth'; const String testMessage5 = 'Hello earth';
const String testMessage6 = 'Hello mars'; const String testMessage6 = 'Hello mars';
void test() async { void main() => group('Integration tests', () {
Client? testClientA, testClientB; test('E2EE', () async {
Client? testClientA, testClientB;
try {
Hive.init(null);
await olm.init();
olm.Account();
Logs().i('[LibOlm] Enabled');
Logs().i('++++ Login Alice at ++++');
testClientA = Client('TestClientA', databaseBuilder: getDatabase);
await testClientA.checkHomeserver(Uri.parse(TestUser.homeserver));
await testClientA.login(LoginType.mLoginPassword,
identifier:
AuthenticationUserIdentifier(user: TestUser.username.localpart!),
password: TestUser.password);
assert(testClientA.encryptionEnabled);
Logs().i('++++ Login Bob ++++');
testClientB = Client('TestClientB', databaseBuilder: getDatabase);
await testClientB.checkHomeserver(Uri.parse(TestUser.homeserver));
await testClientB.login(LoginType.mLoginPassword,
identifier:
AuthenticationUserIdentifier(user: TestUser.username2.localpart!),
password: TestUser.password2);
assert(testClientB.encryptionEnabled);
Logs().i('++++ (Alice) Leave all rooms ++++');
while (testClientA.rooms.isNotEmpty) {
final room = testClientA.rooms.first;
if (room.canonicalAlias.isNotEmpty) {
break;
}
try {
await room.leave();
await room.forget();
} catch (_) {}
}
Logs().i('++++ (Bob) Leave all rooms ++++');
for (var i = 0; i < 3; i++) {
if (testClientB.rooms.isNotEmpty) {
final room = testClientB.rooms.first;
try { try {
await room.leave(); Hive.init(null);
await room.forget();
} catch (_) {}
}
}
Logs().i('++++ Check if own olm device is verified by default ++++'); await olm.init();
assert(testClientA.userDeviceKeys.containsKey(TestUser.username)); olm.Account();
assert(testClientA.userDeviceKeys[TestUser.username]!.deviceKeys Logs().i('[LibOlm] Enabled');
.containsKey(testClientA.deviceID));
assert(testClientA.userDeviceKeys[TestUser.username]!
.deviceKeys[testClientA.deviceID!]!.verified);
assert(!testClientA.userDeviceKeys[TestUser.username]!
.deviceKeys[testClientA.deviceID!]!.blocked);
assert(testClientB.userDeviceKeys.containsKey(TestUser.username2));
assert(testClientB.userDeviceKeys[TestUser.username2]!.deviceKeys
.containsKey(testClientB.deviceID));
assert(testClientB.userDeviceKeys[TestUser.username2]!
.deviceKeys[testClientB.deviceID!]!.verified);
assert(!testClientB.userDeviceKeys[TestUser.username2]!
.deviceKeys[testClientB.deviceID!]!.blocked);
Logs().i('++++ (Alice) Create room and invite Bob ++++'); Logs().i('++++ Login Alice at ++++');
await testClientA.startDirectChat( testClientA = Client('TestClientA', databaseBuilder: getDatabase);
TestUser.username2, await testClientA.checkHomeserver(Uri.parse(TestUser.homeserver));
enableEncryption: false, await testClientA.login(LoginType.mLoginPassword,
); identifier: AuthenticationUserIdentifier(
await Future.delayed(Duration(seconds: 1)); user: TestUser.username.localpart!),
final room = testClientA.rooms.first; password: TestUser.password);
final roomId = room.id; expect(testClientA.encryptionEnabled, true);
Logs().i('++++ (Bob) Join room ++++'); Logs().i('++++ Login Bob ++++');
final inviteRoom = testClientB.getRoomById(roomId)!; testClientB = Client('TestClientB', databaseBuilder: getDatabase);
await inviteRoom.join(); await testClientB.checkHomeserver(Uri.parse(TestUser.homeserver));
await Future.delayed(Duration(seconds: 1)); await testClientB.login(LoginType.mLoginPassword,
assert(inviteRoom.membership == Membership.join); identifier: AuthenticationUserIdentifier(
user: TestUser.username2.localpart!),
password: TestUser.password2);
expect(testClientB.encryptionEnabled, true);
Logs().i('++++ (Alice) Enable encryption ++++'); Logs().i('++++ (Alice) Leave all rooms ++++');
assert(room.encrypted == false); while (testClientA.rooms.isNotEmpty) {
await room.enableEncryption(); final room = testClientA.rooms.first;
await Future.delayed(Duration(seconds: 5)); if (room.canonicalAlias.isNotEmpty) {
assert(room.encrypted == true); break;
assert( }
room.client.encryption!.keyManager.getOutboundGroupSession(room.id) == try {
null); await room.leave();
await room.forget();
} catch (_) {}
}
Logs().i('++++ (Alice) Check known olm devices ++++'); Logs().i('++++ (Bob) Leave all rooms ++++');
assert(testClientA.userDeviceKeys.containsKey(TestUser.username2)); for (var i = 0; i < 3; i++) {
assert(testClientA.userDeviceKeys[TestUser.username2]!.deviceKeys if (testClientB.rooms.isNotEmpty) {
.containsKey(testClientB.deviceID)); final room = testClientB.rooms.first;
assert(!testClientA.userDeviceKeys[TestUser.username2]! try {
.deviceKeys[testClientB.deviceID!]!.verified); await room.leave();
assert(!testClientA.userDeviceKeys[TestUser.username2]! await room.forget();
.deviceKeys[testClientB.deviceID!]!.blocked); } catch (_) {}
assert(testClientB.userDeviceKeys.containsKey(TestUser.username)); }
assert(testClientB.userDeviceKeys[TestUser.username]!.deviceKeys }
.containsKey(testClientA.deviceID));
assert(!testClientB.userDeviceKeys[TestUser.username]!
.deviceKeys[testClientA.deviceID!]!.verified);
assert(!testClientB.userDeviceKeys[TestUser.username]!
.deviceKeys[testClientA.deviceID!]!.blocked);
await Future.wait([
testClientA.updateUserDeviceKeys(),
testClientB.updateUserDeviceKeys(),
]);
await testClientA
.userDeviceKeys[TestUser.username2]!.deviceKeys[testClientB.deviceID!]!
.setVerified(true);
Logs().i('++++ Check if own olm device is verified by default ++++'); Logs().i('++++ Check if own olm device is verified by default ++++');
assert(testClientA.userDeviceKeys.containsKey(TestUser.username)); expect(testClientA.userDeviceKeys, contains(TestUser.username));
assert(testClientA.userDeviceKeys[TestUser.username]!.deviceKeys expect(testClientA.userDeviceKeys[TestUser.username]!.deviceKeys,
.containsKey(testClientA.deviceID)); contains(testClientA.deviceID));
assert(testClientA.userDeviceKeys[TestUser.username]! expect(
.deviceKeys[testClientA.deviceID!]!.verified); testClientA.userDeviceKeys[TestUser.username]!
assert(testClientB.userDeviceKeys.containsKey(TestUser.username2)); .deviceKeys[testClientA.deviceID!]!.verified,
assert(testClientB.userDeviceKeys[TestUser.username2]!.deviceKeys isTrue);
.containsKey(testClientB.deviceID)); expect(
assert(testClientB.userDeviceKeys[TestUser.username2]! !testClientA.userDeviceKeys[TestUser.username]!
.deviceKeys[testClientB.deviceID!]!.verified); .deviceKeys[testClientA.deviceID!]!.blocked,
isTrue);
expect(testClientB.userDeviceKeys, contains(TestUser.username2));
expect(testClientB.userDeviceKeys[TestUser.username2]!.deviceKeys,
contains(testClientB.deviceID));
expect(
testClientB.userDeviceKeys[TestUser.username2]!
.deviceKeys[testClientB.deviceID!]!.verified,
isTrue);
expect(
!testClientB.userDeviceKeys[TestUser.username2]!
.deviceKeys[testClientB.deviceID!]!.blocked,
isTrue);
Logs().i("++++ (Alice) Send encrypted message: '$testMessage' ++++"); Logs().i('++++ (Alice) Create room and invite Bob ++++');
await room.sendTextEvent(testMessage); await testClientA.startDirectChat(
await Future.delayed(Duration(seconds: 5)); TestUser.username2,
assert( enableEncryption: false,
room.client.encryption!.keyManager.getOutboundGroupSession(room.id) != );
null); await Future.delayed(Duration(seconds: 1));
var currentSessionIdA = room.client.encryption!.keyManager final room = testClientA.rooms.first;
.getOutboundGroupSession(room.id)! final roomId = room.id;
.outboundGroupSession!
.session_id(); Logs().i('++++ (Bob) Join room ++++');
/*assert(room.client.encryption.keyManager final inviteRoom = testClientB.getRoomById(roomId)!;
await inviteRoom.join();
await Future.delayed(Duration(seconds: 1));
expect(inviteRoom.membership, Membership.join);
Logs().i('++++ (Alice) Enable encryption ++++');
expect(room.encrypted, false);
await room.enableEncryption();
await Future.delayed(Duration(seconds: 5));
expect(room.encrypted, isTrue);
expect(
room.client.encryption!.keyManager
.getOutboundGroupSession(room.id),
null);
Logs().i('++++ (Alice) Check known olm devices ++++');
expect(testClientA.userDeviceKeys, contains(TestUser.username2));
expect(testClientA.userDeviceKeys[TestUser.username2]!.deviceKeys,
contains(testClientB.deviceID));
expect(
testClientA.userDeviceKeys[TestUser.username2]!
.deviceKeys[testClientB.deviceID!]!.verified,
isFalse);
expect(
testClientA.userDeviceKeys[TestUser.username2]!
.deviceKeys[testClientB.deviceID!]!.blocked,
isFalse);
expect(testClientB.userDeviceKeys, contains(TestUser.username));
expect(testClientB.userDeviceKeys[TestUser.username]!.deviceKeys,
contains(testClientA.deviceID));
expect(
testClientB.userDeviceKeys[TestUser.username]!
.deviceKeys[testClientA.deviceID!]!.verified,
isFalse);
expect(
testClientB.userDeviceKeys[TestUser.username]!
.deviceKeys[testClientA.deviceID!]!.blocked,
isFalse);
await Future.wait([
testClientA.updateUserDeviceKeys(),
testClientB.updateUserDeviceKeys(),
]);
await testClientA.userDeviceKeys[TestUser.username2]!
.deviceKeys[testClientB.deviceID!]!
.setVerified(true);
Logs().i('++++ Check if own olm device is verified by default ++++');
expect(testClientA.userDeviceKeys, contains(TestUser.username));
expect(testClientA.userDeviceKeys[TestUser.username]!.deviceKeys,
contains(testClientA.deviceID));
expect(
testClientA.userDeviceKeys[TestUser.username]!
.deviceKeys[testClientA.deviceID!]!.verified,
isTrue);
expect(testClientB.userDeviceKeys, contains(TestUser.username2));
expect(testClientB.userDeviceKeys[TestUser.username2]!.deviceKeys,
contains(testClientB.deviceID));
expect(
testClientB.userDeviceKeys[TestUser.username2]!
.deviceKeys[testClientB.deviceID!]!.verified,
isTrue);
Logs().i("++++ (Alice) Send encrypted message: '$testMessage' ++++");
await room.sendTextEvent(testMessage);
await Future.delayed(Duration(seconds: 5));
expect(
room.client.encryption!.keyManager
.getOutboundGroupSession(room.id),
isNotNull);
var currentSessionIdA = room.client.encryption!.keyManager
.getOutboundGroupSession(room.id)!
.outboundGroupSession!
.session_id();
/*expect(room.client.encryption.keyManager
.getInboundGroupSession(room.id, currentSessionIdA, '') != .getInboundGroupSession(room.id, currentSessionIdA, '') !=
null);*/ null);*/
assert(testClientA.encryption!.olmManager expect(
.olmSessions[testClientB.identityKey]!.length == testClientA.encryption!.olmManager
1); .olmSessions[testClientB.identityKey]!.length,
assert(testClientB.encryption!.olmManager 1);
.olmSessions[testClientA.identityKey]!.length == expect(
1); testClientB.encryption!.olmManager
assert(testClientA.encryption!.olmManager .olmSessions[testClientA.identityKey]!.length,
.olmSessions[testClientB.identityKey]!.first.sessionId == 1);
testClientB.encryption!.olmManager.olmSessions[testClientA.identityKey]! expect(
.first.sessionId); testClientA.encryption!.olmManager
/*assert(inviteRoom.client.encryption.keyManager .olmSessions[testClientB.identityKey]!.first.sessionId,
testClientB.encryption!.olmManager
.olmSessions[testClientA.identityKey]!.first.sessionId);
/*expect(inviteRoom.client.encryption.keyManager
.getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') != .getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') !=
null);*/ null);*/
assert(room.lastEvent!.body == testMessage); expect(room.lastEvent!.body, testMessage);
assert(inviteRoom.lastEvent!.body == testMessage); expect(inviteRoom.lastEvent!.body, testMessage);
Logs().i( Logs().i(
"++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++"); "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++");
Logs().i("++++ (Alice) Send again encrypted message: '$testMessage2' ++++"); Logs().i(
await room.sendTextEvent(testMessage2); "++++ (Alice) Send again encrypted message: '$testMessage2' ++++");
await Future.delayed(Duration(seconds: 5)); await room.sendTextEvent(testMessage2);
assert(testClientA.encryption!.olmManager await Future.delayed(Duration(seconds: 5));
.olmSessions[testClientB.identityKey]!.length == expect(
1); testClientA.encryption!.olmManager
assert(testClientB.encryption!.olmManager .olmSessions[testClientB.identityKey]!.length,
.olmSessions[testClientA.identityKey]!.length == 1);
1); expect(
assert(testClientA.encryption!.olmManager testClientB.encryption!.olmManager
.olmSessions[testClientB.identityKey]!.first.sessionId == .olmSessions[testClientA.identityKey]!.length,
testClientB.encryption!.olmManager.olmSessions[testClientA.identityKey]! 1);
.first.sessionId); expect(
testClientA.encryption!.olmManager
.olmSessions[testClientB.identityKey]!.first.sessionId,
testClientB.encryption!.olmManager
.olmSessions[testClientA.identityKey]!.first.sessionId);
assert(room.client.encryption!.keyManager expect(
.getOutboundGroupSession(room.id)! room.client.encryption!.keyManager
.outboundGroupSession! .getOutboundGroupSession(room.id)!
.session_id() == .outboundGroupSession!
currentSessionIdA); .session_id(),
/*assert(room.client.encryption.keyManager currentSessionIdA);
/*expect(room.client.encryption.keyManager
.getInboundGroupSession(room.id, currentSessionIdA, '') != .getInboundGroupSession(room.id, currentSessionIdA, '') !=
null);*/ null);*/
assert(room.lastEvent!.body == testMessage2); expect(room.lastEvent!.body, testMessage2);
assert(inviteRoom.lastEvent!.body == testMessage2); expect(inviteRoom.lastEvent!.body, testMessage2);
Logs().i( Logs().i(
"++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++"); "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++");
Logs().i("++++ (Bob) Send again encrypted message: '$testMessage3' ++++"); Logs().i(
await inviteRoom.sendTextEvent(testMessage3); "++++ (Bob) Send again encrypted message: '$testMessage3' ++++");
await Future.delayed(Duration(seconds: 5)); await inviteRoom.sendTextEvent(testMessage3);
assert(testClientA.encryption!.olmManager await Future.delayed(Duration(seconds: 5));
.olmSessions[testClientB.identityKey]!.length == expect(
1); testClientA.encryption!.olmManager
assert(testClientB.encryption!.olmManager .olmSessions[testClientB.identityKey]!.length,
.olmSessions[testClientA.identityKey]!.length == 1);
1); expect(
assert(room.client.encryption!.keyManager testClientB.encryption!.olmManager
.getOutboundGroupSession(room.id)! .olmSessions[testClientA.identityKey]!.length,
.outboundGroupSession! 1);
.session_id() == expect(
currentSessionIdA); room.client.encryption!.keyManager
final inviteRoomOutboundGroupSession = inviteRoom .getOutboundGroupSession(room.id)!
.client.encryption!.keyManager .outboundGroupSession!
.getOutboundGroupSession(inviteRoom.id)!; .session_id(),
currentSessionIdA);
final inviteRoomOutboundGroupSession = inviteRoom
.client.encryption!.keyManager
.getOutboundGroupSession(inviteRoom.id)!;
assert(inviteRoomOutboundGroupSession.isValid); expect(inviteRoomOutboundGroupSession.isValid, isTrue);
/*assert(inviteRoom.client.encryption.keyManager.getInboundGroupSession( /*expect(inviteRoom.client.encryption.keyManager.getInboundGroupSession(
inviteRoom.id, inviteRoom.id,
inviteRoomOutboundGroupSession.outboundGroupSession.session_id(), inviteRoomOutboundGroupSession.outboundGroupSession.session_id(),
'') != '') !=
null); null);
assert(room.client.encryption.keyManager.getInboundGroupSession( expect(room.client.encryption.keyManager.getInboundGroupSession(
room.id, room.id,
inviteRoomOutboundGroupSession.outboundGroupSession.session_id(), inviteRoomOutboundGroupSession.outboundGroupSession.session_id(),
'') != '') !=
null);*/ null);*/
assert(inviteRoom.lastEvent!.body == testMessage3); expect(inviteRoom.lastEvent!.body, testMessage3);
assert(room.lastEvent!.body == testMessage3); expect(room.lastEvent!.body, testMessage3);
Logs().i( Logs().i(
"++++ (Alice) Received decrypted message: '${room.lastEvent!.body}' ++++"); "++++ (Alice) Received decrypted message: '${room.lastEvent!.body}' ++++");
Logs().i('++++ Login Bob in another client ++++'); Logs().i('++++ Login Bob in another client ++++');
final testClientC = Client('TestClientC', databaseBuilder: getDatabase); final testClientC =
await testClientC.checkHomeserver(Uri.parse(TestUser.homeserver)); Client('TestClientC', databaseBuilder: getDatabase);
// Workaround: Logging in with displayname instead of mxid await testClientC.checkHomeserver(Uri.parse(TestUser.homeserver));
await testClientC.login(LoginType.mLoginPassword, // We can't sign in using the displayname, since that breaks e2ee on dendrite: https://github.com/matrix-org/dendrite/issues/2914
identifier: AuthenticationUserIdentifier(user: TestUser.displayname2), await testClientC.login(LoginType.mLoginPassword,
password: TestUser.password2); identifier: AuthenticationUserIdentifier(
await Future.delayed(Duration(seconds: 3)); user: TestUser.username2.localpart!),
password: TestUser.password2);
await Future.delayed(Duration(seconds: 3));
Logs().i("++++ (Alice) Send again encrypted message: '$testMessage4' ++++"); Logs().i(
await room.sendTextEvent(testMessage4); "++++ (Alice) Send again encrypted message: '$testMessage4' ++++");
await Future.delayed(Duration(seconds: 5)); await room.sendTextEvent(testMessage4);
assert(testClientA.encryption!.olmManager await Future.delayed(Duration(seconds: 5));
.olmSessions[testClientB.identityKey]!.length == expect(
1); testClientA.encryption!.olmManager
assert(testClientB.encryption!.olmManager .olmSessions[testClientB.identityKey]!.length,
.olmSessions[testClientA.identityKey]!.length == 1);
1); expect(
assert(testClientA.encryption!.olmManager testClientB.encryption!.olmManager
.olmSessions[testClientB.identityKey]!.first.sessionId == .olmSessions[testClientA.identityKey]!.length,
testClientB.encryption!.olmManager.olmSessions[testClientA.identityKey]! 1);
.first.sessionId); expect(
assert(testClientA.encryption!.olmManager testClientA.encryption!.olmManager
.olmSessions[testClientC.identityKey]!.length == .olmSessions[testClientB.identityKey]!.first.sessionId,
1); testClientB.encryption!.olmManager
assert(testClientC.encryption!.olmManager .olmSessions[testClientA.identityKey]!.first.sessionId);
.olmSessions[testClientA.identityKey]!.length == expect(
1); testClientA.encryption!.olmManager
assert(testClientA.encryption!.olmManager .olmSessions[testClientC.identityKey]!.length,
.olmSessions[testClientC.identityKey]!.first.sessionId == 1);
testClientC.encryption!.olmManager.olmSessions[testClientA.identityKey]! expect(
.first.sessionId); testClientC.encryption!.olmManager
assert(room.client.encryption!.keyManager .olmSessions[testClientA.identityKey]!.length,
.getOutboundGroupSession(room.id)! 1);
.outboundGroupSession! expect(
.session_id() != testClientA.encryption!.olmManager
currentSessionIdA); .olmSessions[testClientC.identityKey]!.first.sessionId,
currentSessionIdA = room.client.encryption!.keyManager testClientC.encryption!.olmManager
.getOutboundGroupSession(room.id)! .olmSessions[testClientA.identityKey]!.first.sessionId);
.outboundGroupSession! expect(
.session_id(); room.client.encryption!.keyManager
/*assert(inviteRoom.client.encryption.keyManager .getOutboundGroupSession(room.id)!
.outboundGroupSession!
.session_id(),
currentSessionIdA);
/*expect(inviteRoom.client.encryption.keyManager
.getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') != .getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') !=
null);*/ null);*/
assert(room.lastEvent!.body == testMessage4); expect(room.lastEvent!.body, testMessage4);
assert(inviteRoom.lastEvent!.body == testMessage4); expect(inviteRoom.lastEvent!.body, testMessage4);
Logs().i( Logs().i(
"++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++"); "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++");
Logs().i('++++ Logout Bob another client ++++'); Logs()
await testClientC.dispose(closeDatabase: false); .i('++++ Logout Bob another client ${testClientC.deviceID} ++++');
await testClientC.logout(); await testClientC.dispose(closeDatabase: false);
await Future.delayed(Duration(seconds: 5)); await testClientC.logout();
await Future.delayed(Duration(seconds: 5));
Logs().i("++++ (Alice) Send again encrypted message: '$testMessage6' ++++"); Logs().i(
await room.sendTextEvent(testMessage6); "++++ (Alice) Send again encrypted message: '$testMessage6' ++++");
await Future.delayed(Duration(seconds: 5)); await room.sendTextEvent(testMessage6);
assert(testClientA.encryption!.olmManager await Future.delayed(Duration(seconds: 5));
.olmSessions[testClientB.identityKey]!.length == expect(
1); testClientA.encryption!.olmManager
assert(testClientB.encryption!.olmManager .olmSessions[testClientB.identityKey]!.length,
.olmSessions[testClientA.identityKey]!.length == 1);
1); expect(
assert(testClientA.encryption!.olmManager testClientB.encryption!.olmManager
.olmSessions[testClientB.identityKey]!.first.sessionId == .olmSessions[testClientA.identityKey]!.length,
testClientB.encryption!.olmManager.olmSessions[testClientA.identityKey]! 1);
.first.sessionId); expect(
assert(room.client.encryption!.keyManager testClientA.encryption!.olmManager
.getOutboundGroupSession(room.id)! .olmSessions[testClientB.identityKey]!.first.sessionId,
.outboundGroupSession! testClientB.encryption!.olmManager
.session_id() != .olmSessions[testClientA.identityKey]!.first.sessionId);
currentSessionIdA);
currentSessionIdA = room.client.encryption!.keyManager // This does not work on conduit because of a server bug: https://gitlab.com/famedly/conduit/-/issues/325
.getOutboundGroupSession(room.id)! if (Platform.environment['HOMESERVER'] != 'conduit') {
.outboundGroupSession! expect(
.session_id(); room.client.encryption!.keyManager
/*assert(inviteRoom.client.encryption.keyManager .getOutboundGroupSession(room.id)!
.outboundGroupSession!
.session_id(),
isNot(currentSessionIdA));
}
currentSessionIdA = room.client.encryption!.keyManager
.getOutboundGroupSession(room.id)!
.outboundGroupSession!
.session_id();
/*expect(inviteRoom.client.encryption.keyManager
.getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') != .getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') !=
null);*/ null);*/
assert(room.lastEvent!.body == testMessage6); expect(room.lastEvent!.body, testMessage6);
assert(inviteRoom.lastEvent!.body == testMessage6); expect(inviteRoom.lastEvent!.body, testMessage6);
Logs().i( Logs().i(
"++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++"); "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent!.body}' ++++");
await room.leave(); await room.leave();
await room.forget(); await room.forget();
await inviteRoom.leave(); await inviteRoom.leave();
await inviteRoom.forget(); await inviteRoom.forget();
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
} catch (e, s) { } catch (e, s) {
Logs().e('Test failed', e, s); Logs().e('Test failed', e, s);
rethrow; rethrow;
} finally { } finally {
Logs().i('++++ Logout Alice and Bob ++++'); Logs().i('++++ Logout Alice and Bob ++++');
if (testClientA?.isLogged() ?? false) await testClientA!.logoutAll(); if (testClientA?.isLogged() ?? false) await testClientA!.logoutAll();
if (testClientA?.isLogged() ?? false) await testClientB!.logoutAll(); if (testClientA?.isLogged() ?? false) await testClientB!.logoutAll();
await testClientA?.dispose(closeDatabase: false); await testClientA?.dispose(closeDatabase: false);
await testClientB?.dispose(closeDatabase: false); await testClientB?.dispose(closeDatabase: false);
testClientA = null; testClientA = null;
testClientB = null; testClientB = null;
} }
return; return;
} });
}, timeout: Timeout(Duration(minutes: 6)));