2019-06-09 11:57:33 +00:00
|
|
|
/*
|
2020-06-03 10:16:01 +00:00
|
|
|
* Ansible inventory script used at Famedly GmbH for managing many hosts
|
|
|
|
* Copyright (C) 2019, 2020 Famedly GmbH
|
2019-06-09 11:57:33 +00:00
|
|
|
*
|
2020-06-03 10:16:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2019-06-09 11:57:33 +00:00
|
|
|
*
|
2020-06-03 10:16:01 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2019-06-09 11:57:33 +00:00
|
|
|
*
|
2020-06-03 10:16:01 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-06-09 11:57:33 +00:00
|
|
|
*/
|
|
|
|
|
2019-07-12 09:26:07 +00:00
|
|
|
import 'dart:async';
|
2020-02-24 16:54:43 +00:00
|
|
|
import 'dart:typed_data';
|
2019-07-12 09:26:07 +00:00
|
|
|
|
2020-01-12 10:30:05 +00:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2020-06-03 10:16:01 +00:00
|
|
|
import 'package:famedlysdk/matrix_api.dart';
|
Update lib/src/client.dart, lib/src/user.dart, lib/src/timeline.dart, lib/src/room.dart, lib/src/presence.dart, lib/src/event.dart, lib/src/utils/profile.dart, lib/src/utils/receipt.dart, test/client_test.dart, test/event_test.dart, test/presence_test.dart, test/room_test.dart, test/timeline_test.dart, test/user_test.dart files
2020-01-04 17:56:17 +00:00
|
|
|
import 'package:famedlysdk/src/client.dart';
|
2020-06-03 10:16:01 +00:00
|
|
|
import 'package:famedlysdk/src/utils/event_update.dart';
|
|
|
|
import 'package:famedlysdk/src/utils/room_update.dart';
|
Update lib/src/client.dart, lib/src/user.dart, lib/src/timeline.dart, lib/src/room.dart, lib/src/presence.dart, lib/src/event.dart, lib/src/utils/profile.dart, lib/src/utils/receipt.dart, test/client_test.dart, test/event_test.dart, test/presence_test.dart, test/room_test.dart, test/timeline_test.dart, test/user_test.dart files
2020-01-04 17:56:17 +00:00
|
|
|
import 'package:famedlysdk/src/utils/matrix_file.dart';
|
2020-02-15 07:48:41 +00:00
|
|
|
import 'package:olm/olm.dart' as olm;
|
2019-10-04 09:44:32 +00:00
|
|
|
import 'package:test/test.dart';
|
2019-07-12 09:26:07 +00:00
|
|
|
|
Update lib/src/client.dart, lib/src/user.dart, lib/src/timeline.dart, lib/src/room.dart, lib/src/presence.dart, lib/src/event.dart, lib/src/utils/profile.dart, lib/src/utils/receipt.dart, test/client_test.dart, test/event_test.dart, test/presence_test.dart, test/room_test.dart, test/timeline_test.dart, test/user_test.dart files
2020-01-04 17:56:17 +00:00
|
|
|
import 'fake_matrix_api.dart';
|
2020-05-15 18:40:17 +00:00
|
|
|
import 'fake_database.dart';
|
2019-06-09 10:16:48 +00:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
Client matrix;
|
|
|
|
|
|
|
|
Future<List<RoomUpdate>> roomUpdateListFuture;
|
|
|
|
Future<List<EventUpdate>> eventUpdateListFuture;
|
2020-02-15 07:48:41 +00:00
|
|
|
Future<List<ToDeviceEvent>> toDeviceUpdateListFuture;
|
|
|
|
|
2020-06-04 15:51:49 +00:00
|
|
|
// key @test:fakeServer.notExisting
|
2020-03-30 09:08:38 +00:00
|
|
|
const pickledOlmAccount =
|
2020-06-05 08:15:36 +00:00
|
|
|
'N2v1MkIFGcl0mQpo2OCwSopxPQJ0wnl7oe7PKiT4141AijfdTIhRu+ceXzXKy3Kr00nLqXtRv7kid6hU4a+V0rfJWLL0Y51+3Rp/ORDVnQy+SSeo6Fn4FHcXrxifJEJ0djla5u98fBcJ8BSkhIDmtXRPi5/oJAvpiYn+8zMjFHobOeZUAxYR0VfQ9JzSYBsSovoQ7uFkNks1M4EDUvHtuyg3RxViwdNxs3718fyAqQ/VSwbXsY0Nl+qQbF+nlVGHenGqk5SuNl1P6e1PzZxcR0IfXA94Xij1Ob5gDv5YH4UCn9wRMG0abZsQP0YzpDM0FLaHSCyo9i5JD/vMlhH+nZWrgAzPPCTNGYewNV8/h3c+VyJh8ZTx/fVi6Yq46Fv+27Ga2ETRZ3Qn+Oyx6dLBjnBZ9iUvIhqpe2XqaGA1PopOz8iDnaZitw';
|
2020-03-30 09:08:38 +00:00
|
|
|
const identityKey = '7rvl3jORJkBiK4XX1e5TnGnqz068XfYJ0W++Ml63rgk';
|
|
|
|
const fingerprintKey = 'gjL//fyaFHADt9KBADGag8g7F8Up78B/K1zXeiEPLJo';
|
2019-06-09 10:16:48 +00:00
|
|
|
|
|
|
|
/// All Tests related to the Login
|
2020-03-30 09:08:38 +00:00
|
|
|
group('FluffyMatrix', () {
|
2019-06-09 10:16:48 +00:00
|
|
|
/// Check if all Elements get created
|
|
|
|
|
2020-06-03 10:16:01 +00:00
|
|
|
matrix = Client('testclient', debug: true, httpClient: FakeMatrixApi());
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-01-02 14:09:49 +00:00
|
|
|
roomUpdateListFuture = matrix.onRoomUpdate.stream.toList();
|
|
|
|
eventUpdateListFuture = matrix.onEvent.stream.toList();
|
2020-02-15 07:48:41 +00:00
|
|
|
toDeviceUpdateListFuture = matrix.onToDeviceEvent.stream.toList();
|
2020-03-30 09:08:38 +00:00
|
|
|
var olmEnabled = true;
|
2020-02-15 07:48:41 +00:00
|
|
|
try {
|
|
|
|
olm.init();
|
|
|
|
olm.Account();
|
|
|
|
} catch (_) {
|
|
|
|
olmEnabled = false;
|
2020-03-30 09:08:38 +00:00
|
|
|
print('[LibOlm] Failed to load LibOlm: ' + _.toString());
|
2020-02-15 07:48:41 +00:00
|
|
|
}
|
2020-03-30 09:08:38 +00:00
|
|
|
print('[LibOlm] Enabled: $olmEnabled');
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2019-06-18 09:37:06 +00:00
|
|
|
test('Login', () async {
|
2020-03-30 09:08:38 +00:00
|
|
|
var presenceCounter = 0;
|
|
|
|
var accountDataCounter = 0;
|
2020-01-04 10:29:38 +00:00
|
|
|
matrix.onPresence.stream.listen((Presence data) {
|
2019-08-08 08:31:39 +00:00
|
|
|
presenceCounter++;
|
2020-01-04 10:29:38 +00:00
|
|
|
});
|
2020-06-03 10:16:01 +00:00
|
|
|
matrix.onAccountData.stream.listen((BasicEvent data) {
|
2019-08-08 08:31:39 +00:00
|
|
|
accountDataCounter++;
|
2020-01-04 10:29:38 +00:00
|
|
|
});
|
2019-08-08 08:31:39 +00:00
|
|
|
|
2020-06-03 10:16:01 +00:00
|
|
|
expect(matrix.api.homeserver, null);
|
2019-06-18 09:37:06 +00:00
|
|
|
|
2019-12-29 10:28:33 +00:00
|
|
|
try {
|
2020-03-30 09:08:38 +00:00
|
|
|
await matrix.checkServer('https://fakeserver.wrongaddress');
|
2019-12-29 10:28:33 +00:00
|
|
|
} on FormatException catch (exception) {
|
|
|
|
expect(exception != null, true);
|
|
|
|
}
|
2020-03-30 09:08:38 +00:00
|
|
|
await matrix.checkServer('https://fakeserver.notexisting');
|
2020-06-03 10:16:01 +00:00
|
|
|
expect(
|
|
|
|
matrix.api.homeserver.toString(), 'https://fakeserver.notexisting');
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-06-03 10:16:01 +00:00
|
|
|
final resp = await matrix.api.login(
|
|
|
|
type: 'm.login.password',
|
|
|
|
user: 'test',
|
|
|
|
password: '1234',
|
|
|
|
initialDeviceDisplayName: 'Fluffy Matrix Client',
|
|
|
|
);
|
2020-01-14 15:16:24 +00:00
|
|
|
|
2020-06-03 10:16:01 +00:00
|
|
|
final available = await matrix.api.usernameAvailable('testuser');
|
|
|
|
expect(available, true);
|
2020-01-14 15:16:24 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
var loginStateFuture = matrix.onLoginStateChanged.stream.first;
|
|
|
|
var firstSyncFuture = matrix.onFirstSync.stream.first;
|
|
|
|
var syncFuture = matrix.onSync.stream.first;
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-01-02 14:09:49 +00:00
|
|
|
matrix.connect(
|
2020-06-03 10:16:01 +00:00
|
|
|
newToken: resp.accessToken,
|
|
|
|
newUserID: resp.userId,
|
|
|
|
newHomeserver: matrix.api.homeserver,
|
2020-03-30 09:08:38 +00:00
|
|
|
newDeviceName: 'Text Matrix Client',
|
2020-06-03 10:16:01 +00:00
|
|
|
newDeviceID: resp.deviceId,
|
2020-02-15 07:48:41 +00:00
|
|
|
newOlmAccount: pickledOlmAccount,
|
|
|
|
);
|
|
|
|
|
2020-01-02 14:33:26 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-06-03 10:16:01 +00:00
|
|
|
expect(matrix.api.accessToken == resp.accessToken, true);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(matrix.deviceName == 'Text Matrix Client', true);
|
2020-06-03 10:16:01 +00:00
|
|
|
expect(matrix.deviceID == resp.deviceId, true);
|
|
|
|
expect(matrix.userID == resp.userId, true);
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
var loginState = await loginStateFuture;
|
|
|
|
var firstSync = await firstSyncFuture;
|
2020-06-03 10:16:01 +00:00
|
|
|
var sync = await syncFuture;
|
2019-06-09 10:16:48 +00:00
|
|
|
|
|
|
|
expect(loginState, LoginState.logged);
|
|
|
|
expect(firstSync, true);
|
2020-02-15 07:48:41 +00:00
|
|
|
expect(matrix.encryptionEnabled, olmEnabled);
|
|
|
|
if (olmEnabled) {
|
|
|
|
expect(matrix.identityKey, identityKey);
|
|
|
|
expect(matrix.fingerprintKey, fingerprintKey);
|
|
|
|
}
|
2020-06-03 10:16:01 +00:00
|
|
|
expect(sync.nextBatch == matrix.prevBatch, true);
|
2019-08-07 10:27:02 +00:00
|
|
|
|
2019-12-04 09:58:47 +00:00
|
|
|
expect(matrix.accountData.length, 3);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(matrix.getDirectChatFromUserId('@bob:example.com'),
|
|
|
|
'!726s6s6q:example.com');
|
|
|
|
expect(matrix.rooms[1].directChatMatrixID, '@bob:example.com');
|
|
|
|
expect(matrix.directChats, matrix.accountData['m.direct'].content);
|
2019-08-08 07:58:37 +00:00
|
|
|
expect(matrix.presences.length, 1);
|
2020-01-02 14:09:49 +00:00
|
|
|
expect(matrix.rooms[1].ephemerals.length, 2);
|
|
|
|
expect(matrix.rooms[1].typingUsers.length, 1);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(matrix.rooms[1].typingUsers[0].id, '@alice:example.com');
|
2020-01-02 14:09:49 +00:00
|
|
|
expect(matrix.rooms[1].roomAccountData.length, 3);
|
2020-02-04 13:41:13 +00:00
|
|
|
expect(matrix.rooms[1].encrypted, true);
|
|
|
|
expect(matrix.rooms[1].encryptionAlgorithm,
|
|
|
|
Client.supportedGroupEncryptionAlgorithms.first);
|
2019-10-20 09:44:14 +00:00
|
|
|
expect(
|
2020-03-30 09:08:38 +00:00
|
|
|
matrix.rooms[1].roomAccountData['m.receipt']
|
|
|
|
.content['@alice:example.com']['ts'],
|
2019-10-20 09:44:14 +00:00
|
|
|
1436451550453);
|
2019-10-25 08:02:56 +00:00
|
|
|
expect(
|
2020-03-30 09:08:38 +00:00
|
|
|
matrix.rooms[1].roomAccountData['m.receipt']
|
|
|
|
.content['@alice:example.com']['event_id'],
|
|
|
|
'7365636s6r6432:example.com');
|
2020-01-02 14:09:49 +00:00
|
|
|
expect(matrix.rooms.length, 2);
|
|
|
|
expect(matrix.rooms[1].canonicalAlias,
|
2019-08-08 07:58:37 +00:00
|
|
|
"#famedlyContactDiscovery:${matrix.userID.split(":")[1]}");
|
2020-03-30 09:08:38 +00:00
|
|
|
final contacts = await matrix.loadFamedlyContacts();
|
2020-06-03 10:16:01 +00:00
|
|
|
expect(contacts.length, 2);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(contacts[0].senderId, '@alice:example.com');
|
2020-06-03 10:16:01 +00:00
|
|
|
expect(matrix.presences['@alice:example.com'].presence.presence,
|
|
|
|
PresenceType.online);
|
2019-08-08 08:31:39 +00:00
|
|
|
expect(presenceCounter, 1);
|
2019-12-04 09:58:47 +00:00
|
|
|
expect(accountDataCounter, 3);
|
2020-02-04 13:41:13 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2020-06-04 16:16:22 +00:00
|
|
|
expect(matrix.userDeviceKeys.length, 4);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(matrix.userDeviceKeys['@alice:example.com'].outdated, false);
|
2020-05-29 06:49:37 +00:00
|
|
|
expect(matrix.userDeviceKeys['@alice:example.com'].deviceKeys.length, 2);
|
2020-02-04 13:41:13 +00:00
|
|
|
expect(
|
2020-03-30 09:08:38 +00:00
|
|
|
matrix.userDeviceKeys['@alice:example.com'].deviceKeys['JLAFKJWSCS']
|
2020-02-04 13:41:13 +00:00
|
|
|
.verified,
|
|
|
|
false);
|
|
|
|
|
2020-06-03 10:16:01 +00:00
|
|
|
await matrix.handleSync(SyncUpdate.fromJson({
|
2020-03-30 09:08:38 +00:00
|
|
|
'device_lists': {
|
|
|
|
'changed': [
|
|
|
|
'@alice:example.com',
|
2020-02-04 13:41:13 +00:00
|
|
|
],
|
2020-03-30 09:08:38 +00:00
|
|
|
'left': [
|
|
|
|
'@bob:example.com',
|
2020-02-04 13:41:13 +00:00
|
|
|
],
|
|
|
|
}
|
2020-06-03 10:16:01 +00:00
|
|
|
}));
|
2020-02-04 13:41:13 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2020-06-04 16:16:22 +00:00
|
|
|
expect(matrix.userDeviceKeys.length, 3);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(matrix.userDeviceKeys['@alice:example.com'].outdated, true);
|
2019-10-14 16:50:10 +00:00
|
|
|
|
2020-06-03 10:16:01 +00:00
|
|
|
await matrix.handleSync(SyncUpdate.fromJson({
|
2020-03-30 09:08:38 +00:00
|
|
|
'rooms': {
|
|
|
|
'join': {
|
|
|
|
'!726s6s6q:example.com': {
|
|
|
|
'state': {
|
|
|
|
'events': [
|
2020-01-02 14:09:49 +00:00
|
|
|
{
|
2020-03-30 09:08:38 +00:00
|
|
|
'sender': '@alice:example.com',
|
|
|
|
'type': 'm.room.canonical_alias',
|
|
|
|
'content': {'alias': ''},
|
|
|
|
'state_key': '',
|
|
|
|
'origin_server_ts': 1417731086799,
|
|
|
|
'event_id': '66697273743033:example.com'
|
2020-01-02 14:09:49 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-03 10:16:01 +00:00
|
|
|
}));
|
2020-01-02 14:33:26 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2019-10-14 16:50:10 +00:00
|
|
|
|
|
|
|
expect(
|
2020-01-02 14:09:49 +00:00
|
|
|
matrix.getRoomByAlias(
|
2019-10-14 16:50:10 +00:00
|
|
|
"#famedlyContactDiscovery:${matrix.userID.split(":")[1]}"),
|
|
|
|
null);
|
2020-03-30 09:08:38 +00:00
|
|
|
final altContacts = await matrix.loadFamedlyContacts();
|
2020-02-04 13:41:13 +00:00
|
|
|
altContacts.forEach((u) => print(u.id));
|
2019-10-14 16:50:10 +00:00
|
|
|
expect(altContacts.length, 2);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(altContacts[0].senderId, '@alice:example.com');
|
2019-06-18 09:37:06 +00:00
|
|
|
});
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2019-06-18 09:37:06 +00:00
|
|
|
test('Logout', () async {
|
2020-06-03 10:16:01 +00:00
|
|
|
await matrix.api.logout();
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
var loginStateFuture = matrix.onLoginStateChanged.stream.first;
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-01-02 14:09:49 +00:00
|
|
|
matrix.clear();
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-06-03 10:16:01 +00:00
|
|
|
expect(matrix.api.accessToken == null, true);
|
|
|
|
expect(matrix.api.homeserver == null, true);
|
2019-06-09 10:16:48 +00:00
|
|
|
expect(matrix.userID == null, true);
|
|
|
|
expect(matrix.deviceID == null, true);
|
|
|
|
expect(matrix.deviceName == null, true);
|
|
|
|
expect(matrix.prevBatch == null, true);
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
var loginState = await loginStateFuture;
|
2019-06-09 10:16:48 +00:00
|
|
|
expect(loginState, LoginState.loggedOut);
|
|
|
|
});
|
|
|
|
|
2019-06-18 09:37:06 +00:00
|
|
|
test('Room Update Test', () async {
|
2020-01-02 14:33:26 +00:00
|
|
|
await matrix.onRoomUpdate.close();
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
var roomUpdateList = await roomUpdateListFuture;
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-06-03 10:16:01 +00:00
|
|
|
expect(roomUpdateList.length, 4);
|
2019-06-18 09:37:06 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(roomUpdateList[0].id == '!726s6s6q:example.com', true);
|
2019-07-12 09:26:07 +00:00
|
|
|
expect(roomUpdateList[0].membership == Membership.join, true);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(roomUpdateList[0].prev_batch == 't34-23535_0_0', true);
|
2019-06-18 09:37:06 +00:00
|
|
|
expect(roomUpdateList[0].limitedTimeline == true, true);
|
|
|
|
expect(roomUpdateList[0].notification_count == 2, true);
|
|
|
|
expect(roomUpdateList[0].highlight_count == 2, true);
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(roomUpdateList[1].id == '!696r7674:example.com', true);
|
2019-07-12 09:26:07 +00:00
|
|
|
expect(roomUpdateList[1].membership == Membership.invite, true);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(roomUpdateList[1].prev_batch == '', true);
|
2019-06-18 09:37:06 +00:00
|
|
|
expect(roomUpdateList[1].limitedTimeline == false, true);
|
|
|
|
expect(roomUpdateList[1].notification_count == 0, true);
|
|
|
|
expect(roomUpdateList[1].highlight_count == 0, true);
|
2019-06-09 10:16:48 +00:00
|
|
|
});
|
|
|
|
|
2019-06-18 09:37:06 +00:00
|
|
|
test('Event Update Test', () async {
|
2020-01-02 14:33:26 +00:00
|
|
|
await matrix.onEvent.close();
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
var eventUpdateList = await eventUpdateListFuture;
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-02-04 13:41:13 +00:00
|
|
|
expect(eventUpdateList.length, 13);
|
2019-08-08 08:31:39 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(eventUpdateList[0].eventType, 'm.room.member');
|
|
|
|
expect(eventUpdateList[0].roomID, '!726s6s6q:example.com');
|
|
|
|
expect(eventUpdateList[0].type, 'state');
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(eventUpdateList[1].eventType, 'm.room.canonical_alias');
|
|
|
|
expect(eventUpdateList[1].roomID, '!726s6s6q:example.com');
|
|
|
|
expect(eventUpdateList[1].type, 'state');
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(eventUpdateList[2].eventType, 'm.room.encryption');
|
|
|
|
expect(eventUpdateList[2].roomID, '!726s6s6q:example.com');
|
|
|
|
expect(eventUpdateList[2].type, 'state');
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(eventUpdateList[3].eventType, 'm.room.member');
|
|
|
|
expect(eventUpdateList[3].roomID, '!726s6s6q:example.com');
|
|
|
|
expect(eventUpdateList[3].type, 'timeline');
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(eventUpdateList[4].eventType, 'm.room.message');
|
|
|
|
expect(eventUpdateList[4].roomID, '!726s6s6q:example.com');
|
|
|
|
expect(eventUpdateList[4].type, 'timeline');
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(eventUpdateList[5].eventType, 'm.typing');
|
|
|
|
expect(eventUpdateList[5].roomID, '!726s6s6q:example.com');
|
|
|
|
expect(eventUpdateList[5].type, 'ephemeral');
|
2019-10-20 09:44:14 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(eventUpdateList[6].eventType, 'm.receipt');
|
|
|
|
expect(eventUpdateList[6].roomID, '!726s6s6q:example.com');
|
|
|
|
expect(eventUpdateList[6].type, 'ephemeral');
|
2019-10-20 09:44:14 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(eventUpdateList[7].eventType, 'm.receipt');
|
|
|
|
expect(eventUpdateList[7].roomID, '!726s6s6q:example.com');
|
|
|
|
expect(eventUpdateList[7].type, 'account_data');
|
2019-10-20 09:44:14 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(eventUpdateList[8].eventType, 'm.tag');
|
|
|
|
expect(eventUpdateList[8].roomID, '!726s6s6q:example.com');
|
|
|
|
expect(eventUpdateList[8].type, 'account_data');
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(eventUpdateList[9].eventType, 'org.example.custom.room.config');
|
|
|
|
expect(eventUpdateList[9].roomID, '!726s6s6q:example.com');
|
|
|
|
expect(eventUpdateList[9].type, 'account_data');
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(eventUpdateList[10].eventType, 'm.room.name');
|
|
|
|
expect(eventUpdateList[10].roomID, '!696r7674:example.com');
|
|
|
|
expect(eventUpdateList[10].type, 'invite_state');
|
2020-02-04 13:41:13 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(eventUpdateList[11].eventType, 'm.room.member');
|
|
|
|
expect(eventUpdateList[11].roomID, '!696r7674:example.com');
|
|
|
|
expect(eventUpdateList[11].type, 'invite_state');
|
2019-06-11 12:10:50 +00:00
|
|
|
});
|
|
|
|
|
2020-02-15 07:48:41 +00:00
|
|
|
test('To Device Update Test', () async {
|
|
|
|
await matrix.onToDeviceEvent.close();
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
var eventUpdateList = await toDeviceUpdateListFuture;
|
2020-02-15 07:48:41 +00:00
|
|
|
|
|
|
|
expect(eventUpdateList.length, 2);
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(eventUpdateList[0].type, 'm.new_device');
|
2020-06-05 11:10:53 +00:00
|
|
|
if (olmEnabled) {
|
2020-06-05 10:07:06 +00:00
|
|
|
expect(eventUpdateList[1].type, 'm.room_key');
|
|
|
|
} else {
|
|
|
|
expect(eventUpdateList[1].type, 'm.room.encrypted');
|
|
|
|
}
|
2020-02-15 07:48:41 +00:00
|
|
|
});
|
|
|
|
|
2019-06-18 09:37:06 +00:00
|
|
|
test('Login', () async {
|
2020-06-03 10:16:01 +00:00
|
|
|
matrix = Client('testclient', debug: true, httpClient: FakeMatrixApi());
|
2019-10-04 09:44:32 +00:00
|
|
|
|
2020-01-02 14:09:49 +00:00
|
|
|
roomUpdateListFuture = matrix.onRoomUpdate.stream.toList();
|
|
|
|
eventUpdateListFuture = matrix.onEvent.stream.toList();
|
2020-03-30 09:08:38 +00:00
|
|
|
final checkResp =
|
|
|
|
await matrix.checkServer('https://fakeServer.notExisting');
|
2019-06-18 09:37:06 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
final loginResp = await matrix.login('test', '1234');
|
2019-06-09 10:16:48 +00:00
|
|
|
|
2019-06-18 09:37:06 +00:00
|
|
|
expect(checkResp, true);
|
|
|
|
expect(loginResp, true);
|
|
|
|
});
|
|
|
|
|
2019-09-09 13:22:02 +00:00
|
|
|
test('setAvatar', () async {
|
2020-03-30 09:08:38 +00:00
|
|
|
final testFile =
|
|
|
|
MatrixFile(bytes: Uint8List(0), path: 'fake/path/file.jpeg');
|
2019-12-29 10:28:33 +00:00
|
|
|
await matrix.setAvatar(testFile);
|
2019-09-09 13:22:02 +00:00
|
|
|
});
|
|
|
|
|
2020-06-03 10:16:01 +00:00
|
|
|
test('setMuteAllPushNotifications', () async {
|
|
|
|
await matrix.setMuteAllPushNotifications(false);
|
2020-02-19 13:26:38 +00:00
|
|
|
});
|
|
|
|
|
2019-11-29 16:19:32 +00:00
|
|
|
test('get archive', () async {
|
2020-03-30 09:08:38 +00:00
|
|
|
var archive = await matrix.archive;
|
2019-11-29 16:19:32 +00:00
|
|
|
|
2020-01-02 14:33:26 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
2019-12-19 11:26:21 +00:00
|
|
|
expect(archive.length, 2);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(archive[0].id, '!5345234234:example.com');
|
2019-12-19 11:26:21 +00:00
|
|
|
expect(archive[0].membership, Membership.leave);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(archive[0].name, 'The room name');
|
|
|
|
expect(archive[0].lastMessage, 'This is an example text message');
|
2019-12-19 11:26:21 +00:00
|
|
|
expect(archive[0].roomAccountData.length, 1);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(archive[1].id, '!5345234235:example.com');
|
2019-12-19 11:26:21 +00:00
|
|
|
expect(archive[1].membership, Membership.leave);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(archive[1].name, 'The room name 2');
|
2019-11-29 16:19:32 +00:00
|
|
|
});
|
|
|
|
|
2019-11-30 09:36:30 +00:00
|
|
|
test('getProfileFromUserId', () async {
|
2020-05-18 11:45:49 +00:00
|
|
|
final profile = await matrix.getProfileFromUserId('@getme:example.com',
|
|
|
|
getFromRooms: false);
|
2020-04-24 07:24:06 +00:00
|
|
|
expect(profile.avatarUrl.toString(), 'mxc://test');
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(profile.displayname, 'You got me');
|
2020-05-18 11:45:49 +00:00
|
|
|
final aliceProfile =
|
|
|
|
await matrix.getProfileFromUserId('@alice:example.com');
|
|
|
|
expect(aliceProfile.avatarUrl.toString(),
|
|
|
|
'mxc://example.org/SEsfnsuifSDFSSEF');
|
|
|
|
expect(aliceProfile.displayname, 'Alice Margatroid');
|
2019-11-30 09:36:30 +00:00
|
|
|
});
|
2020-03-30 09:08:38 +00:00
|
|
|
var deviceKeys = DeviceKeys.fromJson({
|
|
|
|
'user_id': '@alice:example.com',
|
|
|
|
'device_id': 'JLAFKJWSCS',
|
|
|
|
'algorithms': ['m.olm.v1.curve25519-aes-sha2', 'm.megolm.v1.aes-sha2'],
|
|
|
|
'keys': {
|
|
|
|
'curve25519:JLAFKJWSCS': '3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI',
|
|
|
|
'ed25519:JLAFKJWSCS': 'lEuiRJBit0IG6nUf5pUzWTUEsRVVe/HJkoKuEww9ULI'
|
2020-02-15 07:48:41 +00:00
|
|
|
},
|
2020-03-30 09:08:38 +00:00
|
|
|
'signatures': {
|
|
|
|
'@alice:example.com': {
|
|
|
|
'ed25519:JLAFKJWSCS':
|
|
|
|
'dSO80A01XiigH3uBiDVx/EjzaoycHcjq9lfQX0uWsqxl2giMIiSPR8a4d291W1ihKJL/a+myXS367WT6NAIcBA'
|
2020-02-15 07:48:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
test('sendToDevice', () async {
|
|
|
|
await matrix.sendToDevice(
|
|
|
|
[deviceKeys],
|
2020-03-30 09:08:38 +00:00
|
|
|
'm.message',
|
2020-02-15 07:48:41 +00:00
|
|
|
{
|
2020-03-30 09:08:38 +00:00
|
|
|
'msgtype': 'm.text',
|
|
|
|
'body': 'Hello world',
|
2020-02-15 07:48:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
test('Test the fake store api', () async {
|
2020-06-03 10:16:01 +00:00
|
|
|
var client1 =
|
|
|
|
Client('testclient', debug: true, httpClient: FakeMatrixApi());
|
2020-05-15 18:40:17 +00:00
|
|
|
client1.database = getDatabase();
|
2020-02-15 07:48:41 +00:00
|
|
|
|
|
|
|
client1.connect(
|
2020-03-30 09:08:38 +00:00
|
|
|
newToken: 'abc123',
|
|
|
|
newUserID: '@test:fakeServer.notExisting',
|
2020-06-03 10:16:01 +00:00
|
|
|
newHomeserver: Uri.parse('https://fakeServer.notExisting'),
|
2020-03-30 09:08:38 +00:00
|
|
|
newDeviceName: 'Text Matrix Client',
|
|
|
|
newDeviceID: 'GHTYAJCE',
|
2020-02-15 07:48:41 +00:00
|
|
|
newOlmAccount: pickledOlmAccount,
|
|
|
|
);
|
|
|
|
|
|
|
|
await Future.delayed(Duration(milliseconds: 50));
|
|
|
|
|
|
|
|
expect(client1.isLogged(), true);
|
|
|
|
expect(client1.rooms.length, 2);
|
|
|
|
|
2020-06-03 10:16:01 +00:00
|
|
|
var client2 =
|
|
|
|
Client('testclient', debug: true, httpClient: FakeMatrixApi());
|
2020-05-15 18:40:17 +00:00
|
|
|
client2.database = client1.database;
|
2020-02-15 07:48:41 +00:00
|
|
|
|
2020-05-15 18:40:17 +00:00
|
|
|
client2.connect();
|
2020-02-15 07:48:41 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 100));
|
|
|
|
|
|
|
|
expect(client2.isLogged(), true);
|
2020-06-03 10:16:01 +00:00
|
|
|
expect(client2.api.accessToken, client1.api.accessToken);
|
2020-02-15 07:48:41 +00:00
|
|
|
expect(client2.userID, client1.userID);
|
2020-06-03 10:16:01 +00:00
|
|
|
expect(client2.api.homeserver, client1.api.homeserver);
|
2020-02-15 07:48:41 +00:00
|
|
|
expect(client2.deviceID, client1.deviceID);
|
|
|
|
expect(client2.deviceName, client1.deviceName);
|
|
|
|
if (client2.encryptionEnabled) {
|
2020-06-04 11:39:51 +00:00
|
|
|
expect(client2.encryption.pickledOlmAccount,
|
|
|
|
client1.encryption.pickledOlmAccount);
|
2020-02-15 07:48:41 +00:00
|
|
|
expect(client2.rooms[1].id, client1.rooms[1].id);
|
|
|
|
}
|
2020-05-19 09:28:13 +00:00
|
|
|
|
|
|
|
await client1.logout();
|
|
|
|
await client2.logout();
|
2020-02-15 07:48:41 +00:00
|
|
|
});
|
2020-06-03 10:16:01 +00:00
|
|
|
test('changePassword', () async {
|
|
|
|
await matrix.changePassword('1234', oldPassword: '123456');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('dispose', () async {
|
|
|
|
await matrix.dispose(closeDatabase: true);
|
|
|
|
});
|
2019-06-09 10:16:48 +00:00
|
|
|
});
|
|
|
|
}
|