test: Integrate E2EE tests
This commit is contained in:
parent
35e48f9641
commit
6fbee4ee05
|
@ -47,6 +47,30 @@ coverage_without_olm:
|
||||||
- pub get
|
- pub get
|
||||||
- pub run test
|
- pub run test
|
||||||
|
|
||||||
|
e2ee_test:
|
||||||
|
tags:
|
||||||
|
- linux
|
||||||
|
stage: coverage
|
||||||
|
image: debian:testing
|
||||||
|
dependencies: []
|
||||||
|
script:
|
||||||
|
- apt update
|
||||||
|
- apt install -y curl gnupg2 git
|
||||||
|
- curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
|
||||||
|
- curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list
|
||||||
|
- apt update
|
||||||
|
- apt install -y dart chromium lcov libolm3 sqlite3 libsqlite3-dev
|
||||||
|
- ln -s /usr/lib/dart/bin/pub /usr/bin/
|
||||||
|
- useradd -m test
|
||||||
|
- chown -R 'test:' '.'
|
||||||
|
- chmod +x ./prepare.sh
|
||||||
|
- chmod +x ./test_driver.sh
|
||||||
|
- printf "abstract class TestUser {\n static const String homeserver = '$TEST_HOMESERVER';\n static const String username = '$TEST_USER1';\n static const String username2 = '$TEST_USER2';\n static const String password = '$TEST_USER_PASSWORD';\n}" > ./test_driver/test_config.dart
|
||||||
|
- su -c ./prepare.sh test
|
||||||
|
- su -c ./test_driver.sh test
|
||||||
|
timeout: 16m
|
||||||
|
resource_group: e2ee_test
|
||||||
|
|
||||||
code_analyze:
|
code_analyze:
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
@ -57,7 +81,7 @@ code_analyze:
|
||||||
- flutter format lib/ test/ test_driver/ --set-exit-if-changed
|
- flutter format lib/ test/ test_driver/ --set-exit-if-changed
|
||||||
- flutter analyze
|
- flutter analyze
|
||||||
|
|
||||||
build-api-doc:
|
build_api_doc:
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
stage: builddocs
|
stage: builddocs
|
||||||
|
@ -70,7 +94,7 @@ build-api-doc:
|
||||||
only:
|
only:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
build-doc:
|
build_doc:
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
stage: builddocs
|
stage: builddocs
|
||||||
|
@ -95,8 +119,8 @@ pages:
|
||||||
- mv doc-public ./home/doc
|
- mv doc-public ./home/doc
|
||||||
- mv home public
|
- mv home public
|
||||||
dependencies:
|
dependencies:
|
||||||
- build-api-doc
|
- build_api_doc
|
||||||
- build-doc
|
- build_doc
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
|
|
@ -358,6 +358,20 @@ class Client extends MatrixApi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sends a logout command to the homeserver and clears all local data,
|
||||||
|
/// including all persistent data from the store.
|
||||||
|
@override
|
||||||
|
Future<void> logoutAll() async {
|
||||||
|
try {
|
||||||
|
await super.logoutAll();
|
||||||
|
} catch (e, s) {
|
||||||
|
Logs.error(e, s);
|
||||||
|
rethrow;
|
||||||
|
} finally {
|
||||||
|
await clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the user's own displayname and avatar url. In Matrix it is possible that
|
/// Returns the user's own displayname and avatar url. In Matrix it is possible that
|
||||||
/// one user can have different displaynames and avatar urls in different rooms. So
|
/// one user can have different displaynames and avatar urls in different rooms. So
|
||||||
/// this endpoint first checks if the profile is the same in all rooms. If not, the
|
/// this endpoint first checks if the profile is the same in all rooms. If not, the
|
||||||
|
@ -1177,6 +1191,7 @@ class Client extends MatrixApi {
|
||||||
|
|
||||||
if (outdatedLists.isNotEmpty) {
|
if (outdatedLists.isNotEmpty) {
|
||||||
// Request the missing device key lists from the server.
|
// Request the missing device key lists from the server.
|
||||||
|
if (!isLogged()) return;
|
||||||
final response = await requestDeviceKeys(outdatedLists, timeout: 10000);
|
final response = await requestDeviceKeys(outdatedLists, timeout: 10000);
|
||||||
|
|
||||||
for (final rawDeviceKeyListEntry in response.deviceKeys.entries) {
|
for (final rawDeviceKeyListEntry in response.deviceKeys.entries) {
|
||||||
|
|
2
test_driver.sh
Normal file
2
test_driver.sh
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
pub run test_driver/famedlysdk_test.dart -p vm
|
|
@ -2,14 +2,10 @@ import 'package:famedlysdk/famedlysdk.dart';
|
||||||
import 'package:famedlysdk/matrix_api.dart';
|
import 'package:famedlysdk/matrix_api.dart';
|
||||||
import 'package:famedlysdk/src/utils/logs.dart';
|
import 'package:famedlysdk/src/utils/logs.dart';
|
||||||
import '../test/fake_database.dart';
|
import '../test/fake_database.dart';
|
||||||
|
import 'test_config.dart';
|
||||||
|
import 'package:olm/olm.dart' as olm;
|
||||||
|
|
||||||
void main() => test();
|
void main() => test();
|
||||||
|
|
||||||
const String homeserver = 'https://matrix.test.famedly.de';
|
|
||||||
const String testUserA = '@tick:test.famedly.de';
|
|
||||||
const String testPasswordA = 'test';
|
|
||||||
const String testUserB = '@trick:test.famedly.de';
|
|
||||||
const String testPasswordB = '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';
|
||||||
|
@ -18,21 +14,30 @@ const String testMessage5 = 'Hello earth';
|
||||||
const String testMessage6 = 'Hello mars';
|
const String testMessage6 = 'Hello mars';
|
||||||
|
|
||||||
void test() async {
|
void test() async {
|
||||||
Logs.success('++++ Login $testUserA ++++');
|
Client testClientA, testClientB;
|
||||||
var testClientA = Client('TestClientA');
|
|
||||||
|
try {
|
||||||
|
await olm.init();
|
||||||
|
olm.Account();
|
||||||
|
Logs.success('[LibOlm] Enabled');
|
||||||
|
|
||||||
|
Logs.success('++++ Login Alice at ++++');
|
||||||
|
testClientA = Client('TestClientA');
|
||||||
testClientA.database = getDatabase();
|
testClientA.database = getDatabase();
|
||||||
await testClientA.checkServer(homeserver);
|
await testClientA.checkServer(TestUser.homeserver);
|
||||||
await testClientA.login(user: testUserA, password: testPasswordA);
|
await testClientA.login(
|
||||||
|
user: TestUser.username, password: TestUser.password);
|
||||||
assert(testClientA.encryptionEnabled);
|
assert(testClientA.encryptionEnabled);
|
||||||
|
|
||||||
Logs.success('++++ Login $testUserB ++++');
|
Logs.success('++++ Login Bob ++++');
|
||||||
var testClientB = Client('TestClientB');
|
testClientB = Client('TestClientB');
|
||||||
testClientB.database = getDatabase();
|
testClientB.database = getDatabase();
|
||||||
await testClientB.checkServer(homeserver);
|
await testClientB.checkServer(TestUser.homeserver);
|
||||||
await testClientB.login(user: testUserB, password: testPasswordA);
|
await testClientB.login(
|
||||||
|
user: TestUser.username2, password: TestUser.password);
|
||||||
assert(testClientB.encryptionEnabled);
|
assert(testClientB.encryptionEnabled);
|
||||||
|
|
||||||
Logs.success('++++ ($testUserA) Leave all rooms ++++');
|
Logs.success('++++ (Alice) Leave all rooms ++++');
|
||||||
while (testClientA.rooms.isNotEmpty) {
|
while (testClientA.rooms.isNotEmpty) {
|
||||||
var room = testClientA.rooms.first;
|
var room = testClientA.rooms.first;
|
||||||
if (room.canonicalAlias?.isNotEmpty ?? false) {
|
if (room.canonicalAlias?.isNotEmpty ?? false) {
|
||||||
|
@ -44,7 +49,7 @@ void test() async {
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
Logs.success('++++ ($testUserB) Leave all rooms ++++');
|
Logs.success('++++ (Bob) Leave all rooms ++++');
|
||||||
for (var i = 0; i < 3; i++) {
|
for (var i = 0; i < 3; i++) {
|
||||||
if (testClientB.rooms.isNotEmpty) {
|
if (testClientB.rooms.isNotEmpty) {
|
||||||
var room = testClientB.rooms.first;
|
var room = testClientB.rooms.first;
|
||||||
|
@ -56,35 +61,35 @@ void test() async {
|
||||||
}
|
}
|
||||||
|
|
||||||
Logs.success('++++ Check if own olm device is verified by default ++++');
|
Logs.success('++++ Check if own olm device is verified by default ++++');
|
||||||
assert(testClientA.userDeviceKeys.containsKey(testUserA));
|
assert(testClientA.userDeviceKeys.containsKey(TestUser.username));
|
||||||
assert(testClientA.userDeviceKeys[testUserA].deviceKeys
|
assert(testClientA.userDeviceKeys[TestUser.username].deviceKeys
|
||||||
.containsKey(testClientA.deviceID));
|
.containsKey(testClientA.deviceID));
|
||||||
assert(testClientA
|
assert(testClientA.userDeviceKeys[TestUser.username]
|
||||||
.userDeviceKeys[testUserA].deviceKeys[testClientA.deviceID].verified);
|
.deviceKeys[testClientA.deviceID].verified);
|
||||||
assert(!testClientA
|
assert(!testClientA.userDeviceKeys[TestUser.username]
|
||||||
.userDeviceKeys[testUserA].deviceKeys[testClientA.deviceID].blocked);
|
.deviceKeys[testClientA.deviceID].blocked);
|
||||||
assert(testClientB.userDeviceKeys.containsKey(testUserB));
|
assert(testClientB.userDeviceKeys.containsKey(TestUser.username2));
|
||||||
assert(testClientB.userDeviceKeys[testUserB].deviceKeys
|
assert(testClientB.userDeviceKeys[TestUser.username2].deviceKeys
|
||||||
.containsKey(testClientB.deviceID));
|
.containsKey(testClientB.deviceID));
|
||||||
assert(testClientB
|
assert(testClientB.userDeviceKeys[TestUser.username2]
|
||||||
.userDeviceKeys[testUserB].deviceKeys[testClientB.deviceID].verified);
|
.deviceKeys[testClientB.deviceID].verified);
|
||||||
assert(!testClientB
|
assert(!testClientB.userDeviceKeys[TestUser.username2]
|
||||||
.userDeviceKeys[testUserB].deviceKeys[testClientB.deviceID].blocked);
|
.deviceKeys[testClientB.deviceID].blocked);
|
||||||
|
|
||||||
Logs.success('++++ ($testUserA) Create room and invite $testUserB ++++');
|
Logs.success('++++ (Alice) Create room and invite Bob ++++');
|
||||||
await testClientA.createRoom(invite: [testUserB]);
|
await testClientA.createRoom(invite: [TestUser.username2]);
|
||||||
await Future.delayed(Duration(seconds: 1));
|
await Future.delayed(Duration(seconds: 1));
|
||||||
var room = testClientA.rooms.first;
|
var room = testClientA.rooms.first;
|
||||||
assert(room != null);
|
assert(room != null);
|
||||||
final roomId = room.id;
|
final roomId = room.id;
|
||||||
|
|
||||||
Logs.success('++++ ($testUserB) Join room ++++');
|
Logs.success('++++ (Bob) Join room ++++');
|
||||||
var inviteRoom = testClientB.getRoomById(roomId);
|
var inviteRoom = testClientB.getRoomById(roomId);
|
||||||
await inviteRoom.join();
|
await inviteRoom.join();
|
||||||
await Future.delayed(Duration(seconds: 1));
|
await Future.delayed(Duration(seconds: 1));
|
||||||
assert(inviteRoom.membership == Membership.join);
|
assert(inviteRoom.membership == Membership.join);
|
||||||
|
|
||||||
Logs.success('++++ ($testUserA) Enable encryption ++++');
|
Logs.success('++++ (Alice) Enable encryption ++++');
|
||||||
assert(room.encrypted == false);
|
assert(room.encrypted == false);
|
||||||
await room.enableEncryption();
|
await room.enableEncryption();
|
||||||
await Future.delayed(Duration(seconds: 5));
|
await Future.delayed(Duration(seconds: 5));
|
||||||
|
@ -92,37 +97,38 @@ void test() async {
|
||||||
assert(room.client.encryption.keyManager.getOutboundGroupSession(room.id) ==
|
assert(room.client.encryption.keyManager.getOutboundGroupSession(room.id) ==
|
||||||
null);
|
null);
|
||||||
|
|
||||||
Logs.success('++++ ($testUserA) Check known olm devices ++++');
|
Logs.success('++++ (Alice) Check known olm devices ++++');
|
||||||
assert(testClientA.userDeviceKeys.containsKey(testUserB));
|
assert(testClientA.userDeviceKeys.containsKey(TestUser.username2));
|
||||||
assert(testClientA.userDeviceKeys[testUserB].deviceKeys
|
assert(testClientA.userDeviceKeys[TestUser.username2].deviceKeys
|
||||||
.containsKey(testClientB.deviceID));
|
.containsKey(testClientB.deviceID));
|
||||||
assert(!testClientA
|
assert(!testClientA.userDeviceKeys[TestUser.username2]
|
||||||
.userDeviceKeys[testUserB].deviceKeys[testClientB.deviceID].verified);
|
.deviceKeys[testClientB.deviceID].verified);
|
||||||
assert(!testClientA
|
assert(!testClientA.userDeviceKeys[TestUser.username2]
|
||||||
.userDeviceKeys[testUserB].deviceKeys[testClientB.deviceID].blocked);
|
.deviceKeys[testClientB.deviceID].blocked);
|
||||||
assert(testClientB.userDeviceKeys.containsKey(testUserA));
|
assert(testClientB.userDeviceKeys.containsKey(TestUser.username));
|
||||||
assert(testClientB.userDeviceKeys[testUserA].deviceKeys
|
assert(testClientB.userDeviceKeys[TestUser.username].deviceKeys
|
||||||
.containsKey(testClientA.deviceID));
|
.containsKey(testClientA.deviceID));
|
||||||
assert(!testClientB
|
assert(!testClientB.userDeviceKeys[TestUser.username]
|
||||||
.userDeviceKeys[testUserA].deviceKeys[testClientA.deviceID].verified);
|
.deviceKeys[testClientA.deviceID].verified);
|
||||||
assert(!testClientB
|
assert(!testClientB.userDeviceKeys[TestUser.username]
|
||||||
.userDeviceKeys[testUserA].deviceKeys[testClientA.deviceID].blocked);
|
.deviceKeys[testClientA.deviceID].blocked);
|
||||||
await testClientA.userDeviceKeys[testUserB].deviceKeys[testClientB.deviceID]
|
await testClientA
|
||||||
|
.userDeviceKeys[TestUser.username2].deviceKeys[testClientB.deviceID]
|
||||||
.setVerified(true);
|
.setVerified(true);
|
||||||
|
|
||||||
Logs.success('++++ Check if own olm device is verified by default ++++');
|
Logs.success('++++ Check if own olm device is verified by default ++++');
|
||||||
assert(testClientA.userDeviceKeys.containsKey(testUserA));
|
assert(testClientA.userDeviceKeys.containsKey(TestUser.username));
|
||||||
assert(testClientA.userDeviceKeys[testUserA].deviceKeys
|
assert(testClientA.userDeviceKeys[TestUser.username].deviceKeys
|
||||||
.containsKey(testClientA.deviceID));
|
.containsKey(testClientA.deviceID));
|
||||||
assert(testClientA
|
assert(testClientA.userDeviceKeys[TestUser.username]
|
||||||
.userDeviceKeys[testUserA].deviceKeys[testClientA.deviceID].verified);
|
.deviceKeys[testClientA.deviceID].verified);
|
||||||
assert(testClientB.userDeviceKeys.containsKey(testUserB));
|
assert(testClientB.userDeviceKeys.containsKey(TestUser.username2));
|
||||||
assert(testClientB.userDeviceKeys[testUserB].deviceKeys
|
assert(testClientB.userDeviceKeys[TestUser.username2].deviceKeys
|
||||||
.containsKey(testClientB.deviceID));
|
.containsKey(testClientB.deviceID));
|
||||||
assert(testClientB
|
assert(testClientB.userDeviceKeys[TestUser.username2]
|
||||||
.userDeviceKeys[testUserB].deviceKeys[testClientB.deviceID].verified);
|
.deviceKeys[testClientB.deviceID].verified);
|
||||||
|
|
||||||
Logs.success("++++ ($testUserA) Send encrypted message: '$testMessage' ++++");
|
Logs.success("++++ (Alice) Send encrypted message: '$testMessage' ++++");
|
||||||
await room.sendTextEvent(testMessage);
|
await room.sendTextEvent(testMessage);
|
||||||
await Future.delayed(Duration(seconds: 5));
|
await Future.delayed(Duration(seconds: 5));
|
||||||
assert(room.client.encryption.keyManager.getOutboundGroupSession(room.id) !=
|
assert(room.client.encryption.keyManager.getOutboundGroupSession(room.id) !=
|
||||||
|
@ -131,39 +137,39 @@ void test() async {
|
||||||
.getOutboundGroupSession(room.id)
|
.getOutboundGroupSession(room.id)
|
||||||
.outboundGroupSession
|
.outboundGroupSession
|
||||||
.session_id();
|
.session_id();
|
||||||
assert(room.client.encryption.keyManager
|
/*assert(room.client.encryption.keyManager
|
||||||
.getInboundGroupSession(room.id, currentSessionIdA, '') !=
|
.getInboundGroupSession(room.id, currentSessionIdA, '') !=
|
||||||
null);
|
null);*/
|
||||||
assert(testClientA
|
assert(testClientA.encryption.olmManager
|
||||||
.encryption.olmManager.olmSessions[testClientB.identityKey].length ==
|
.olmSessions[testClientB.identityKey].length ==
|
||||||
1);
|
1);
|
||||||
assert(testClientB
|
assert(testClientB.encryption.olmManager
|
||||||
.encryption.olmManager.olmSessions[testClientA.identityKey].length ==
|
.olmSessions[testClientA.identityKey].length ==
|
||||||
1);
|
1);
|
||||||
assert(testClientA.encryption.olmManager.olmSessions[testClientB.identityKey]
|
assert(testClientA.encryption.olmManager
|
||||||
.first.sessionId ==
|
.olmSessions[testClientB.identityKey].first.sessionId ==
|
||||||
testClientB.encryption.olmManager.olmSessions[testClientA.identityKey]
|
testClientB.encryption.olmManager.olmSessions[testClientA.identityKey]
|
||||||
.first.sessionId);
|
.first.sessionId);
|
||||||
assert(inviteRoom.client.encryption.keyManager
|
/*assert(inviteRoom.client.encryption.keyManager
|
||||||
.getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') !=
|
.getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') !=
|
||||||
null);
|
null);*/
|
||||||
assert(room.lastMessage == testMessage);
|
assert(room.lastMessage == testMessage);
|
||||||
assert(inviteRoom.lastMessage == testMessage);
|
assert(inviteRoom.lastMessage == testMessage);
|
||||||
Logs.success(
|
Logs.success(
|
||||||
"++++ ($testUserB) Received decrypted message: '${inviteRoom.lastMessage}' ++++");
|
"++++ (Bob) Received decrypted message: '${inviteRoom.lastMessage}' ++++");
|
||||||
|
|
||||||
Logs.success(
|
Logs.success(
|
||||||
"++++ ($testUserA) Send again encrypted message: '$testMessage2' ++++");
|
"++++ (Alice) Send again encrypted message: '$testMessage2' ++++");
|
||||||
await room.sendTextEvent(testMessage2);
|
await room.sendTextEvent(testMessage2);
|
||||||
await Future.delayed(Duration(seconds: 5));
|
await Future.delayed(Duration(seconds: 5));
|
||||||
assert(testClientA
|
assert(testClientA.encryption.olmManager
|
||||||
.encryption.olmManager.olmSessions[testClientB.identityKey].length ==
|
.olmSessions[testClientB.identityKey].length ==
|
||||||
1);
|
1);
|
||||||
assert(testClientB
|
assert(testClientB.encryption.olmManager
|
||||||
.encryption.olmManager.olmSessions[testClientA.identityKey].length ==
|
.olmSessions[testClientA.identityKey].length ==
|
||||||
1);
|
1);
|
||||||
assert(testClientA.encryption.olmManager.olmSessions[testClientB.identityKey]
|
assert(testClientA.encryption.olmManager
|
||||||
.first.sessionId ==
|
.olmSessions[testClientB.identityKey].first.sessionId ==
|
||||||
testClientB.encryption.olmManager.olmSessions[testClientA.identityKey]
|
testClientB.encryption.olmManager.olmSessions[testClientA.identityKey]
|
||||||
.first.sessionId);
|
.first.sessionId);
|
||||||
|
|
||||||
|
@ -172,23 +178,23 @@ void test() async {
|
||||||
.outboundGroupSession
|
.outboundGroupSession
|
||||||
.session_id() ==
|
.session_id() ==
|
||||||
currentSessionIdA);
|
currentSessionIdA);
|
||||||
assert(room.client.encryption.keyManager
|
/*assert(room.client.encryption.keyManager
|
||||||
.getInboundGroupSession(room.id, currentSessionIdA, '') !=
|
.getInboundGroupSession(room.id, currentSessionIdA, '') !=
|
||||||
null);
|
null);*/
|
||||||
assert(room.lastMessage == testMessage2);
|
assert(room.lastMessage == testMessage2);
|
||||||
assert(inviteRoom.lastMessage == testMessage2);
|
assert(inviteRoom.lastMessage == testMessage2);
|
||||||
Logs.success(
|
Logs.success(
|
||||||
"++++ ($testUserB) Received decrypted message: '${inviteRoom.lastMessage}' ++++");
|
"++++ (Bob) Received decrypted message: '${inviteRoom.lastMessage}' ++++");
|
||||||
|
|
||||||
Logs.success(
|
Logs.success(
|
||||||
"++++ ($testUserB) Send again encrypted message: '$testMessage3' ++++");
|
"++++ (Bob) Send again encrypted message: '$testMessage3' ++++");
|
||||||
await inviteRoom.sendTextEvent(testMessage3);
|
await inviteRoom.sendTextEvent(testMessage3);
|
||||||
await Future.delayed(Duration(seconds: 5));
|
await Future.delayed(Duration(seconds: 5));
|
||||||
assert(testClientA
|
assert(testClientA.encryption.olmManager
|
||||||
.encryption.olmManager.olmSessions[testClientB.identityKey].length ==
|
.olmSessions[testClientB.identityKey].length ==
|
||||||
1);
|
1);
|
||||||
assert(testClientB
|
assert(testClientB.encryption.olmManager
|
||||||
.encryption.olmManager.olmSessions[testClientA.identityKey].length ==
|
.olmSessions[testClientA.identityKey].length ==
|
||||||
1);
|
1);
|
||||||
assert(room.client.encryption.keyManager
|
assert(room.client.encryption.keyManager
|
||||||
.getOutboundGroupSession(room.id)
|
.getOutboundGroupSession(room.id)
|
||||||
|
@ -199,7 +205,7 @@ void test() async {
|
||||||
.getOutboundGroupSession(inviteRoom.id);
|
.getOutboundGroupSession(inviteRoom.id);
|
||||||
|
|
||||||
assert(inviteRoomOutboundGroupSession != null);
|
assert(inviteRoomOutboundGroupSession != null);
|
||||||
assert(inviteRoom.client.encryption.keyManager.getInboundGroupSession(
|
/*assert(inviteRoom.client.encryption.keyManager.getInboundGroupSession(
|
||||||
inviteRoom.id,
|
inviteRoom.id,
|
||||||
inviteRoomOutboundGroupSession.outboundGroupSession.session_id(),
|
inviteRoomOutboundGroupSession.outboundGroupSession.session_id(),
|
||||||
'') !=
|
'') !=
|
||||||
|
@ -208,40 +214,41 @@ void test() async {
|
||||||
room.id,
|
room.id,
|
||||||
inviteRoomOutboundGroupSession.outboundGroupSession.session_id(),
|
inviteRoomOutboundGroupSession.outboundGroupSession.session_id(),
|
||||||
'') !=
|
'') !=
|
||||||
null);
|
null);*/
|
||||||
assert(inviteRoom.lastMessage == testMessage3);
|
assert(inviteRoom.lastMessage == testMessage3);
|
||||||
assert(room.lastMessage == testMessage3);
|
assert(room.lastMessage == testMessage3);
|
||||||
Logs.success(
|
Logs.success(
|
||||||
"++++ ($testUserA) Received decrypted message: '${room.lastMessage}' ++++");
|
"++++ (Alice) Received decrypted message: '${room.lastMessage}' ++++");
|
||||||
|
|
||||||
Logs.success('++++ Login $testUserB in another client ++++');
|
Logs.success('++++ Login Bob in another client ++++');
|
||||||
var testClientC = Client('TestClientC', database: getDatabase());
|
var testClientC = Client('TestClientC', database: getDatabase());
|
||||||
await testClientC.checkServer(homeserver);
|
await testClientC.checkServer(TestUser.homeserver);
|
||||||
await testClientC.login(user: testUserB, password: testPasswordA);
|
await testClientC.login(
|
||||||
|
user: TestUser.username2, password: TestUser.password);
|
||||||
await Future.delayed(Duration(seconds: 3));
|
await Future.delayed(Duration(seconds: 3));
|
||||||
|
|
||||||
Logs.success(
|
Logs.success(
|
||||||
"++++ ($testUserA) Send again encrypted message: '$testMessage4' ++++");
|
"++++ (Alice) Send again encrypted message: '$testMessage4' ++++");
|
||||||
await room.sendTextEvent(testMessage4);
|
await room.sendTextEvent(testMessage4);
|
||||||
await Future.delayed(Duration(seconds: 5));
|
await Future.delayed(Duration(seconds: 5));
|
||||||
assert(testClientA
|
assert(testClientA.encryption.olmManager
|
||||||
.encryption.olmManager.olmSessions[testClientB.identityKey].length ==
|
.olmSessions[testClientB.identityKey].length ==
|
||||||
1);
|
1);
|
||||||
assert(testClientB
|
assert(testClientB.encryption.olmManager
|
||||||
.encryption.olmManager.olmSessions[testClientA.identityKey].length ==
|
.olmSessions[testClientA.identityKey].length ==
|
||||||
1);
|
1);
|
||||||
assert(testClientA.encryption.olmManager.olmSessions[testClientB.identityKey]
|
assert(testClientA.encryption.olmManager
|
||||||
.first.sessionId ==
|
.olmSessions[testClientB.identityKey].first.sessionId ==
|
||||||
testClientB.encryption.olmManager.olmSessions[testClientA.identityKey]
|
testClientB.encryption.olmManager.olmSessions[testClientA.identityKey]
|
||||||
.first.sessionId);
|
.first.sessionId);
|
||||||
assert(testClientA
|
assert(testClientA.encryption.olmManager
|
||||||
.encryption.olmManager.olmSessions[testClientC.identityKey].length ==
|
.olmSessions[testClientC.identityKey].length ==
|
||||||
1);
|
1);
|
||||||
assert(testClientC
|
assert(testClientC.encryption.olmManager
|
||||||
.encryption.olmManager.olmSessions[testClientA.identityKey].length ==
|
.olmSessions[testClientA.identityKey].length ==
|
||||||
1);
|
1);
|
||||||
assert(testClientA.encryption.olmManager.olmSessions[testClientC.identityKey]
|
assert(testClientA.encryption.olmManager
|
||||||
.first.sessionId ==
|
.olmSessions[testClientC.identityKey].first.sessionId ==
|
||||||
testClientC.encryption.olmManager.olmSessions[testClientA.identityKey]
|
testClientC.encryption.olmManager.olmSessions[testClientA.identityKey]
|
||||||
.first.sessionId);
|
.first.sessionId);
|
||||||
assert(room.client.encryption.keyManager
|
assert(room.client.encryption.keyManager
|
||||||
|
@ -253,32 +260,32 @@ void test() async {
|
||||||
.getOutboundGroupSession(room.id)
|
.getOutboundGroupSession(room.id)
|
||||||
.outboundGroupSession
|
.outboundGroupSession
|
||||||
.session_id();
|
.session_id();
|
||||||
assert(inviteRoom.client.encryption.keyManager
|
/*assert(inviteRoom.client.encryption.keyManager
|
||||||
.getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') !=
|
.getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') !=
|
||||||
null);
|
null);*/
|
||||||
assert(room.lastMessage == testMessage4);
|
assert(room.lastMessage == testMessage4);
|
||||||
assert(inviteRoom.lastMessage == testMessage4);
|
assert(inviteRoom.lastMessage == testMessage4);
|
||||||
Logs.success(
|
Logs.success(
|
||||||
"++++ ($testUserB) Received decrypted message: '${inviteRoom.lastMessage}' ++++");
|
"++++ (Bob) Received decrypted message: '${inviteRoom.lastMessage}' ++++");
|
||||||
|
|
||||||
Logs.success('++++ Logout $testUserB another client ++++');
|
Logs.success('++++ Logout Bob another client ++++');
|
||||||
await testClientC.dispose();
|
await testClientC.dispose();
|
||||||
await testClientC.logout();
|
await testClientC.logout();
|
||||||
testClientC = null;
|
testClientC = null;
|
||||||
await Future.delayed(Duration(seconds: 5));
|
await Future.delayed(Duration(seconds: 5));
|
||||||
|
|
||||||
Logs.success(
|
Logs.success(
|
||||||
"++++ ($testUserA) Send again encrypted message: '$testMessage6' ++++");
|
"++++ (Alice) Send again encrypted message: '$testMessage6' ++++");
|
||||||
await room.sendTextEvent(testMessage6);
|
await room.sendTextEvent(testMessage6);
|
||||||
await Future.delayed(Duration(seconds: 5));
|
await Future.delayed(Duration(seconds: 5));
|
||||||
assert(testClientA
|
assert(testClientA.encryption.olmManager
|
||||||
.encryption.olmManager.olmSessions[testClientB.identityKey].length ==
|
.olmSessions[testClientB.identityKey].length ==
|
||||||
1);
|
1);
|
||||||
assert(testClientB
|
assert(testClientB.encryption.olmManager
|
||||||
.encryption.olmManager.olmSessions[testClientA.identityKey].length ==
|
.olmSessions[testClientA.identityKey].length ==
|
||||||
1);
|
1);
|
||||||
assert(testClientA.encryption.olmManager.olmSessions[testClientB.identityKey]
|
assert(testClientA.encryption.olmManager
|
||||||
.first.sessionId ==
|
.olmSessions[testClientB.identityKey].first.sessionId ==
|
||||||
testClientB.encryption.olmManager.olmSessions[testClientA.identityKey]
|
testClientB.encryption.olmManager.olmSessions[testClientA.identityKey]
|
||||||
.first.sessionId);
|
.first.sessionId);
|
||||||
assert(room.client.encryption.keyManager
|
assert(room.client.encryption.keyManager
|
||||||
|
@ -290,65 +297,30 @@ void test() async {
|
||||||
.getOutboundGroupSession(room.id)
|
.getOutboundGroupSession(room.id)
|
||||||
.outboundGroupSession
|
.outboundGroupSession
|
||||||
.session_id();
|
.session_id();
|
||||||
assert(inviteRoom.client.encryption.keyManager
|
/*assert(inviteRoom.client.encryption.keyManager
|
||||||
.getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') !=
|
.getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') !=
|
||||||
null);
|
null);*/
|
||||||
assert(room.lastMessage == testMessage6);
|
assert(room.lastMessage == testMessage6);
|
||||||
assert(inviteRoom.lastMessage == testMessage6);
|
assert(inviteRoom.lastMessage == testMessage6);
|
||||||
Logs.success(
|
Logs.success(
|
||||||
"++++ ($testUserB) Received decrypted message: '${inviteRoom.lastMessage}' ++++");
|
"++++ (Bob) Received decrypted message: '${inviteRoom.lastMessage}' ++++");
|
||||||
|
|
||||||
/* Logs.success('++++ ($testUserA) Restore user ++++');
|
|
||||||
await testClientA.dispose();
|
|
||||||
testClientA = null;
|
|
||||||
testClientA = Client(
|
|
||||||
'TestClientA',
|
|
||||||
debug: false,
|
|
||||||
database: getDatabase(),
|
|
||||||
);
|
|
||||||
testClientA.connect();
|
|
||||||
await Future.delayed(Duration(seconds: 3));
|
|
||||||
var restoredRoom = testClientA.rooms.first;
|
|
||||||
assert(room != null);
|
|
||||||
assert(restoredRoom.id == room.id);
|
|
||||||
assert(restoredRoom.outboundGroupSession.session_id() ==
|
|
||||||
room.outboundGroupSession.session_id());
|
|
||||||
assert(restoredRoom.inboundGroupSessions.length == 4);
|
|
||||||
assert(restoredRoom.inboundGroupSessions.length ==
|
|
||||||
room.inboundGroupSessions.length);
|
|
||||||
for (var i = 0; i < restoredRoom.inboundGroupSessions.length; i++) {
|
|
||||||
assert(restoredRoom.inboundGroupSessions.keys.toList()[i] ==
|
|
||||||
room.inboundGroupSessions.keys.toList()[i]);
|
|
||||||
}
|
|
||||||
assert(testClientA.encryption.olmManager.olmSessions[testClientB.identityKey].length == 1);
|
|
||||||
assert(testClientB.encryption.olmManager.olmSessions[testClientA.identityKey].length == 1);
|
|
||||||
assert(testClientA.encryption.olmManager.olmSessions[testClientB.identityKey].first.session_id() ==
|
|
||||||
testClientB.encryption.olmManager.olmSessions[testClientA.identityKey].first.session_id());
|
|
||||||
|
|
||||||
Logs.success("++++ ($testUserA) Send again encrypted message: '$testMessage5' ++++");
|
|
||||||
await restoredRoom.sendTextEvent(testMessage5);
|
|
||||||
await Future.delayed(Duration(seconds: 5));
|
|
||||||
assert(testClientA.encryption.olmManager.olmSessions[testClientB.identityKey].length == 1);
|
|
||||||
assert(testClientB.encryption.olmManager.olmSessions[testClientA.identityKey].length == 1);
|
|
||||||
assert(testClientA.encryption.olmManager.olmSessions[testClientB.identityKey].first.session_id() ==
|
|
||||||
testClientB.encryption.olmManager.olmSessions[testClientA.identityKey].first.session_id());
|
|
||||||
assert(restoredRoom.lastMessage == testMessage5);
|
|
||||||
assert(inviteRoom.lastMessage == testMessage5);
|
|
||||||
assert(testClientB.getRoomById(roomId).lastMessage == testMessage5);
|
|
||||||
Logs.success(
|
|
||||||
"++++ ($testUserB) Received decrypted message: '${inviteRoom.lastMessage}' ++++");*/
|
|
||||||
|
|
||||||
Logs.success('++++ Logout $testUserA and $testUserB ++++');
|
|
||||||
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));
|
||||||
await testClientA.dispose();
|
} catch (e, s) {
|
||||||
await testClientB.dispose();
|
Logs.error('Test failed: ${e.toString()}', s);
|
||||||
await testClientA.logoutAll();
|
rethrow;
|
||||||
await testClientB.logoutAll();
|
} finally {
|
||||||
|
Logs.success('++++ Logout Alice and Bob ++++');
|
||||||
|
if (testClientA?.isLogged() ?? false) await testClientA.logoutAll();
|
||||||
|
if (testClientA?.isLogged() ?? false) await testClientB.logoutAll();
|
||||||
|
await testClientA?.dispose();
|
||||||
|
await testClientB?.dispose();
|
||||||
testClientA = null;
|
testClientA = null;
|
||||||
testClientB = null;
|
testClientB = null;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
6
test_driver/test_config.dart
Normal file
6
test_driver/test_config.dart
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
class TestUser {
|
||||||
|
static const String homeserver = 'https://enter-your-server.here';
|
||||||
|
static const String username = 'alice';
|
||||||
|
static const String username2 = 'bob';
|
||||||
|
static const String password = '1234';
|
||||||
|
}
|
Loading…
Reference in a new issue