2019-06-11 10:21:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Zender & Kurtz GbR.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Christian Pauly <krille@famedly.com>
|
|
|
|
* Marcel Radzio <mtrnord@famedly.com>
|
|
|
|
*
|
|
|
|
* This file is part of famedlysdk.
|
|
|
|
*
|
|
|
|
* famedlysdk is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* famedlysdk 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-06-21 12:38:07 +00:00
|
|
|
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
|
2019-06-11 10:21:45 +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 'package:famedlysdk/src/client.dart';
|
|
|
|
import 'package:famedlysdk/src/event.dart';
|
|
|
|
import 'package:famedlysdk/src/room.dart';
|
|
|
|
import 'package:famedlysdk/src/user.dart';
|
|
|
|
import 'package:famedlysdk/src/utils/matrix_file.dart';
|
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';
|
2019-06-11 10:21:45 +00:00
|
|
|
|
2020-02-24 16:54:43 +00:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
2019-06-11 10:21:45 +00:00
|
|
|
void main() {
|
2019-06-18 10:06:55 +00:00
|
|
|
Client matrix;
|
|
|
|
Room room;
|
|
|
|
|
2019-06-11 10:21:45 +00:00
|
|
|
/// All Tests related to the Event
|
2020-03-30 09:08:38 +00:00
|
|
|
group('Room', () {
|
2019-06-18 10:06:55 +00:00
|
|
|
test('Login', () async {
|
2020-03-30 09:08:38 +00:00
|
|
|
matrix = Client('testclient', debug: true);
|
2020-01-02 14:09:49 +00:00
|
|
|
matrix.httpClient = FakeMatrixApi();
|
2019-06-11 10:21:45 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
final checkResp =
|
|
|
|
await matrix.checkServer('https://fakeServer.notExisting');
|
2019-06-18 10:06:55 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
final loginResp = await matrix.login('test', '1234');
|
2019-06-18 10:06:55 +00:00
|
|
|
|
|
|
|
expect(checkResp, true);
|
|
|
|
expect(loginResp, true);
|
|
|
|
});
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('Create from json', () async {
|
|
|
|
final id = '!localpart:server.abc';
|
|
|
|
final membership = Membership.join;
|
|
|
|
final notificationCount = 2;
|
|
|
|
final highlightCount = 1;
|
|
|
|
final heroes = [
|
|
|
|
'@alice:matrix.org',
|
|
|
|
'@bob:example.com',
|
|
|
|
'@charley:example.org'
|
2019-08-06 09:47:09 +00:00
|
|
|
];
|
2019-06-11 10:21:45 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
var jsonObj = <String, dynamic>{
|
|
|
|
'room_id': id,
|
|
|
|
'membership': membership.toString().split('.').last,
|
|
|
|
'avatar_url': '',
|
|
|
|
'notification_count': notificationCount,
|
|
|
|
'highlight_count': highlightCount,
|
|
|
|
'prev_batch': '',
|
|
|
|
'joined_member_count': notificationCount,
|
|
|
|
'invited_member_count': notificationCount,
|
|
|
|
'heroes': heroes.join(','),
|
2019-06-11 10:21:45 +00:00
|
|
|
};
|
|
|
|
|
2020-01-04 14:43:53 +00:00
|
|
|
Function states = () async => [
|
|
|
|
{
|
2020-03-30 09:08:38 +00:00
|
|
|
'content': {'join_rule': 'public'},
|
|
|
|
'event_id': '143273582443PhrSn:example.org',
|
|
|
|
'origin_server_ts': 1432735824653,
|
|
|
|
'room_id': id,
|
|
|
|
'sender': '@example:example.org',
|
|
|
|
'state_key': '',
|
|
|
|
'type': 'm.room.join_rules',
|
|
|
|
'unsigned': {'age': 1234}
|
2020-01-04 14:43:53 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
Function roomAccountData = () async => [
|
|
|
|
{
|
2020-03-30 09:08:38 +00:00
|
|
|
'content': {'foo': 'bar'},
|
|
|
|
'room_id': id,
|
|
|
|
'type': 'com.test.foo'
|
2020-01-04 14:43:53 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
room = await Room.getRoomFromTableRow(
|
|
|
|
jsonObj,
|
|
|
|
matrix,
|
|
|
|
states: states(),
|
|
|
|
roomAccountData: roomAccountData(),
|
|
|
|
);
|
2019-06-11 10:21:45 +00:00
|
|
|
|
2019-06-12 06:40:43 +00:00
|
|
|
expect(room.id, id);
|
2019-06-12 10:30:22 +00:00
|
|
|
expect(room.membership, membership);
|
2019-06-12 06:40:43 +00:00
|
|
|
expect(room.notificationCount, notificationCount);
|
|
|
|
expect(room.highlightCount, highlightCount);
|
2019-08-06 09:47:09 +00:00
|
|
|
expect(room.mJoinedMemberCount, notificationCount);
|
|
|
|
expect(room.mInvitedMemberCount, notificationCount);
|
|
|
|
expect(room.mHeroes, heroes);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(room.displayname, 'alice, bob, charley');
|
|
|
|
expect(room.getState('m.room.join_rules').content['join_rule'], 'public');
|
|
|
|
expect(room.roomAccountData['com.test.foo'].content['foo'], 'bar');
|
2019-08-08 09:41:42 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
room.states['m.room.canonical_alias'] = Event(
|
|
|
|
senderId: '@test:example.com',
|
|
|
|
typeKey: 'm.room.canonical_alias',
|
2019-08-08 09:41:42 +00:00
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
2020-03-30 09:08:38 +00:00
|
|
|
eventId: '123',
|
|
|
|
content: {'alias': '#testalias:example.com'},
|
|
|
|
stateKey: '');
|
|
|
|
expect(room.displayname, 'testalias');
|
|
|
|
expect(room.canonicalAlias, '#testalias:example.com');
|
|
|
|
|
|
|
|
room.states['m.room.name'] = Event(
|
|
|
|
senderId: '@test:example.com',
|
|
|
|
typeKey: 'm.room.name',
|
2019-08-08 09:41:42 +00:00
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
2020-03-30 09:08:38 +00:00
|
|
|
eventId: '123',
|
|
|
|
content: {'name': 'testname'},
|
|
|
|
stateKey: '');
|
|
|
|
expect(room.displayname, 'testname');
|
|
|
|
|
|
|
|
expect(room.topic, '');
|
|
|
|
room.states['m.room.topic'] = Event(
|
|
|
|
senderId: '@test:example.com',
|
|
|
|
typeKey: 'm.room.topic',
|
2019-08-08 09:41:42 +00:00
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
2020-03-30 09:08:38 +00:00
|
|
|
eventId: '123',
|
|
|
|
content: {'topic': 'testtopic'},
|
|
|
|
stateKey: '');
|
|
|
|
expect(room.topic, 'testtopic');
|
|
|
|
|
|
|
|
expect(room.avatar.mxc, '');
|
|
|
|
room.states['m.room.avatar'] = Event(
|
|
|
|
senderId: '@test:example.com',
|
|
|
|
typeKey: 'm.room.avatar',
|
2019-08-08 09:41:42 +00:00
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
2020-03-30 09:08:38 +00:00
|
|
|
eventId: '123',
|
|
|
|
content: {'url': 'mxc://testurl'},
|
|
|
|
stateKey: '');
|
|
|
|
expect(room.avatar.mxc, 'mxc://testurl');
|
|
|
|
room.states['m.room.message'] = Event(
|
|
|
|
senderId: '@test:example.com',
|
|
|
|
typeKey: 'm.room.message',
|
2019-08-08 09:41:42 +00:00
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
2020-03-30 09:08:38 +00:00
|
|
|
eventId: '12345',
|
2020-01-02 14:09:49 +00:00
|
|
|
time: DateTime.now(),
|
2020-03-30 09:08:38 +00:00
|
|
|
content: {'msgtype': 'm.text', 'body': 'test'},
|
|
|
|
stateKey: '');
|
|
|
|
expect(room.lastEvent.eventId, '12345');
|
|
|
|
expect(room.lastMessage, 'test');
|
2019-08-08 09:41:42 +00:00
|
|
|
expect(room.timeCreated, room.lastEvent.time);
|
2019-06-11 10:21:45 +00:00
|
|
|
});
|
2019-06-18 10:06:55 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('sendReadReceipt', () async {
|
|
|
|
await room.sendReadReceipt('§1234:fakeServer.notExisting');
|
2019-06-18 10:06:55 +00:00
|
|
|
});
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('requestParticipants', () async {
|
|
|
|
final participants = await room.requestParticipants();
|
2019-06-18 10:06:55 +00:00
|
|
|
expect(participants.length, 1);
|
2020-03-30 09:08:38 +00:00
|
|
|
var user = participants[0];
|
|
|
|
expect(user.id, '@alice:example.org');
|
|
|
|
expect(user.displayName, 'Alice Margatroid');
|
2019-07-12 09:26:07 +00:00
|
|
|
expect(user.membership, Membership.join);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(user.avatarUrl.mxc, 'mxc://example.org/SEsfnsuifSDFSSEF');
|
|
|
|
expect(user.room.id, '!localpart:server.abc');
|
2019-06-18 10:06:55 +00:00
|
|
|
});
|
2019-06-28 08:59:00 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('getEventByID', () async {
|
|
|
|
final event = await room.getEventById('1234');
|
|
|
|
expect(event.eventId, '143273582443PhrSn:example.org');
|
2019-06-28 08:59:00 +00:00
|
|
|
});
|
2019-08-08 09:41:42 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('setName', () async {
|
|
|
|
final eventId = await room.setName('Testname');
|
|
|
|
expect(eventId, '42');
|
2019-08-08 09:41:42 +00:00
|
|
|
});
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('setDescription', () async {
|
|
|
|
final eventId = await room.setDescription('Testname');
|
|
|
|
expect(eventId, '42');
|
2019-08-08 09:41:42 +00:00
|
|
|
});
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('kick', () async {
|
|
|
|
await room.kick('Testname');
|
2019-08-08 09:41:42 +00:00
|
|
|
});
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('ban', () async {
|
|
|
|
await room.ban('Testname');
|
2019-08-08 09:41:42 +00:00
|
|
|
});
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('unban', () async {
|
|
|
|
await room.unban('Testname');
|
2019-08-08 09:41:42 +00:00
|
|
|
});
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('PowerLevels', () async {
|
|
|
|
room.states['m.room.power_levels'] = Event(
|
|
|
|
senderId: '@test:example.com',
|
|
|
|
typeKey: 'm.room.power_levels',
|
2019-08-08 09:41:42 +00:00
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
2020-03-30 09:08:38 +00:00
|
|
|
eventId: '123',
|
2019-08-08 09:41:42 +00:00
|
|
|
content: {
|
2020-03-30 09:08:38 +00:00
|
|
|
'ban': 50,
|
|
|
|
'events': {'m.room.name': 100, 'm.room.power_levels': 100},
|
|
|
|
'events_default': 0,
|
|
|
|
'invite': 50,
|
|
|
|
'kick': 50,
|
|
|
|
'notifications': {'room': 20},
|
|
|
|
'redact': 50,
|
|
|
|
'state_default': 50,
|
|
|
|
'users': {'@test:fakeServer.notExisting': 100},
|
|
|
|
'users_default': 10
|
2019-08-08 09:41:42 +00:00
|
|
|
},
|
2020-03-30 09:08:38 +00:00
|
|
|
stateKey: '');
|
2019-08-08 09:41:42 +00:00
|
|
|
expect(room.ownPowerLevel, 100);
|
|
|
|
expect(room.getPowerLevelByUserId(matrix.userID), room.ownPowerLevel);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(room.getPowerLevelByUserId('@nouser:example.com'), 10);
|
2019-11-26 06:38:44 +00:00
|
|
|
expect(room.ownPowerLevel, 100);
|
|
|
|
expect(room.canBan, true);
|
|
|
|
expect(room.canInvite, true);
|
|
|
|
expect(room.canKick, true);
|
|
|
|
expect(room.canRedact, true);
|
|
|
|
expect(room.canSendDefaultMessages, true);
|
|
|
|
expect(room.canSendDefaultStates, true);
|
|
|
|
expect(room.canChangePowerLevel, true);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(room.canSendEvent('m.room.name'), true);
|
|
|
|
expect(room.canSendEvent('m.room.power_levels'), true);
|
|
|
|
expect(room.canSendEvent('m.room.member'), true);
|
2019-08-08 09:41:42 +00:00
|
|
|
expect(room.powerLevels,
|
2020-03-30 09:08:38 +00:00
|
|
|
room.states['m.room.power_levels'].content['users']);
|
2019-11-26 06:38:44 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
room.states['m.room.power_levels'] = Event(
|
|
|
|
senderId: '@test:example.com',
|
|
|
|
typeKey: 'm.room.power_levels',
|
2019-11-26 06:38:44 +00:00
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
2020-03-30 09:08:38 +00:00
|
|
|
eventId: '123abc',
|
2019-11-26 06:38:44 +00:00
|
|
|
content: {
|
2020-03-30 09:08:38 +00:00
|
|
|
'ban': 50,
|
|
|
|
'events': {'m.room.name': 0, 'm.room.power_levels': 100},
|
|
|
|
'events_default': 0,
|
|
|
|
'invite': 50,
|
|
|
|
'kick': 50,
|
|
|
|
'notifications': {'room': 20},
|
|
|
|
'redact': 50,
|
|
|
|
'state_default': 50,
|
|
|
|
'users': {},
|
|
|
|
'users_default': 0
|
2019-11-26 06:38:44 +00:00
|
|
|
},
|
2020-03-30 09:08:38 +00:00
|
|
|
stateKey: '');
|
2019-11-26 06:38:44 +00:00
|
|
|
expect(room.ownPowerLevel, 0);
|
|
|
|
expect(room.canBan, false);
|
|
|
|
expect(room.canInvite, false);
|
|
|
|
expect(room.canKick, false);
|
|
|
|
expect(room.canRedact, false);
|
|
|
|
expect(room.canSendDefaultMessages, true);
|
|
|
|
expect(room.canSendDefaultStates, false);
|
|
|
|
expect(room.canChangePowerLevel, false);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(room.canSendEvent('m.room.name'), true);
|
|
|
|
expect(room.canSendEvent('m.room.power_levels'), false);
|
|
|
|
expect(room.canSendEvent('m.room.member'), false);
|
|
|
|
expect(room.canSendEvent('m.room.message'), true);
|
|
|
|
final resp = await room.setPower('@test:fakeServer.notExisting', 90);
|
|
|
|
expect(resp, '42');
|
2019-08-08 09:41:42 +00:00
|
|
|
});
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('invite', () async {
|
|
|
|
await room.invite('Testname');
|
2019-08-08 09:41:42 +00:00
|
|
|
});
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('getParticipants', () async {
|
2020-01-02 14:09:49 +00:00
|
|
|
room.setState(Event(
|
2020-03-30 09:08:38 +00:00
|
|
|
senderId: '@alice:test.abc',
|
|
|
|
typeKey: 'm.room.member',
|
2019-09-02 10:09:30 +00:00
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
2020-03-30 09:08:38 +00:00
|
|
|
eventId: '12345',
|
2020-01-02 14:09:49 +00:00
|
|
|
time: DateTime.now(),
|
2020-03-30 09:08:38 +00:00
|
|
|
content: {'displayname': 'alice'},
|
|
|
|
stateKey: '@alice:test.abc'));
|
|
|
|
final userList = room.getParticipants();
|
2020-02-04 13:41:13 +00:00
|
|
|
expect(userList.length, 5);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(userList[3].displayName, 'Alice Margatroid');
|
2019-09-02 10:09:30 +00:00
|
|
|
});
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('addToDirectChat', () async {
|
|
|
|
await room.addToDirectChat('Testname');
|
2019-08-08 09:41:42 +00:00
|
|
|
});
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('getTimeline', () async {
|
|
|
|
final timeline = await room.getTimeline();
|
2019-08-08 09:54:39 +00:00
|
|
|
expect(timeline.events, []);
|
|
|
|
});
|
2019-08-08 09:41:42 +00:00
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
test('getUserByMXID', () async {
|
2019-12-29 10:28:33 +00:00
|
|
|
User user;
|
|
|
|
try {
|
2020-03-30 09:08:38 +00:00
|
|
|
user = await room.getUserByMXID('@getme:example.com');
|
2019-12-29 10:28:33 +00:00
|
|
|
} catch (_) {}
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(user.stateKey, '@getme:example.com');
|
|
|
|
expect(user.calcDisplayname(), 'You got me');
|
2019-08-08 09:54:39 +00:00
|
|
|
});
|
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-09-09 13:22:02 +00:00
|
|
|
final dynamic resp = await room.setAvatar(testFile);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(resp, 'YUwRidLecu:example.com');
|
2019-09-09 13:22:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('sendEvent', () async {
|
|
|
|
final dynamic resp = await room.sendEvent(
|
2020-03-30 09:08:38 +00:00
|
|
|
{'msgtype': 'm.text', 'body': 'hello world'},
|
|
|
|
txid: 'testtxid');
|
|
|
|
expect(resp, '42');
|
2019-09-09 13:22:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('sendEvent', () async {
|
|
|
|
final dynamic resp =
|
2020-03-30 09:08:38 +00:00
|
|
|
await room.sendTextEvent('Hello world', txid: 'testtxid');
|
|
|
|
expect(resp, '42');
|
2019-09-09 13:22:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Not working because there is no real file to test it...
|
2019-09-30 12:03:34 +00:00
|
|
|
/*test('sendImageEvent', () async {
|
2019-09-09 13:22:02 +00:00
|
|
|
final File testFile = File.fromUri(Uri.parse("fake/path/file.jpeg"));
|
|
|
|
final dynamic resp =
|
|
|
|
await room.sendImageEvent(testFile, txid: "testtxid");
|
|
|
|
expect(resp, "42");
|
2019-09-30 12:03:34 +00:00
|
|
|
});*/
|
2019-09-09 13:22:02 +00:00
|
|
|
|
|
|
|
test('sendFileEvent', () async {
|
2020-03-30 09:08:38 +00:00
|
|
|
final testFile =
|
|
|
|
MatrixFile(bytes: Uint8List(0), path: 'fake/path/file.jpeg');
|
2019-12-18 11:46:25 +00:00
|
|
|
final dynamic resp = await room.sendFileEvent(testFile,
|
2020-03-30 09:08:38 +00:00
|
|
|
msgType: 'm.file', txid: 'testtxid');
|
|
|
|
expect(resp, 'mxc://example.com/AQwafuaFswefuhsfAFAgsw');
|
2019-09-09 13:22:02 +00:00
|
|
|
});
|
2019-12-04 09:58:47 +00:00
|
|
|
|
|
|
|
test('pushRuleState', () async {
|
|
|
|
expect(room.pushRuleState, PushRuleState.mentions_only);
|
2020-03-30 09:08:38 +00:00
|
|
|
matrix.accountData['m.push_rules'].content['global']['override']
|
|
|
|
.add(matrix.accountData['m.push_rules'].content['global']['room'][0]);
|
2019-12-04 09:58:47 +00:00
|
|
|
expect(room.pushRuleState, PushRuleState.dont_notify);
|
|
|
|
});
|
2020-02-15 07:48:41 +00:00
|
|
|
|
|
|
|
test('Enable encryption', () async {
|
|
|
|
room.setState(
|
|
|
|
Event(
|
2020-03-30 09:08:38 +00:00
|
|
|
senderId: '@alice:test.abc',
|
|
|
|
typeKey: 'm.room.encryption',
|
2020-02-15 07:48:41 +00:00
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
2020-03-30 09:08:38 +00:00
|
|
|
eventId: '12345',
|
2020-02-15 07:48:41 +00:00
|
|
|
time: DateTime.now(),
|
|
|
|
content: {
|
2020-03-30 09:08:38 +00:00
|
|
|
'algorithm': 'm.megolm.v1.aes-sha2',
|
|
|
|
'rotation_period_ms': 604800000,
|
|
|
|
'rotation_period_msgs': 100
|
2020-02-15 07:48:41 +00:00
|
|
|
},
|
2020-03-30 09:08:38 +00:00
|
|
|
stateKey: ''),
|
2020-02-15 07:48:41 +00:00
|
|
|
);
|
|
|
|
expect(room.encrypted, true);
|
2020-03-30 09:08:38 +00:00
|
|
|
expect(room.encryptionAlgorithm, 'm.megolm.v1.aes-sha2');
|
2020-02-15 07:48:41 +00:00
|
|
|
expect(room.outboundGroupSession, null);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('createOutboundGroupSession', () async {
|
|
|
|
if (!room.client.encryptionEnabled) return;
|
|
|
|
await room.createOutboundGroupSession();
|
|
|
|
expect(room.outboundGroupSession != null, true);
|
|
|
|
expect(room.outboundGroupSession.session_id().isNotEmpty, true);
|
|
|
|
expect(
|
|
|
|
room.sessionKeys.containsKey(room.outboundGroupSession.session_id()),
|
|
|
|
true);
|
|
|
|
expect(
|
|
|
|
room.sessionKeys[room.outboundGroupSession.session_id()]
|
2020-03-30 09:08:38 +00:00
|
|
|
.content['session_key'],
|
2020-02-15 07:48:41 +00:00
|
|
|
room.outboundGroupSession.session_key());
|
|
|
|
expect(
|
|
|
|
room.sessionKeys[room.outboundGroupSession.session_id()].indexes
|
|
|
|
.length,
|
|
|
|
0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('clearOutboundGroupSession', () async {
|
|
|
|
if (!room.client.encryptionEnabled) return;
|
2020-02-27 08:41:49 +00:00
|
|
|
await room.clearOutboundGroupSession(wipe: true);
|
2020-02-15 07:48:41 +00:00
|
|
|
expect(room.outboundGroupSession == null, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('encryptGroupMessagePayload and decryptGroupMessage', () async {
|
|
|
|
if (!room.client.encryptionEnabled) return;
|
2020-03-30 09:08:38 +00:00
|
|
|
final payload = {
|
|
|
|
'msgtype': 'm.text',
|
|
|
|
'body': 'Hello world',
|
2020-02-15 07:48:41 +00:00
|
|
|
};
|
2020-03-30 09:08:38 +00:00
|
|
|
final encryptedPayload = await room.encryptGroupMessagePayload(payload);
|
|
|
|
expect(encryptedPayload['algorithm'], 'm.megolm.v1.aes-sha2');
|
|
|
|
expect(encryptedPayload['ciphertext'].isNotEmpty, true);
|
|
|
|
expect(encryptedPayload['device_id'], room.client.deviceID);
|
|
|
|
expect(encryptedPayload['sender_key'], room.client.identityKey);
|
|
|
|
expect(encryptedPayload['session_id'],
|
2020-02-15 07:48:41 +00:00
|
|
|
room.outboundGroupSession.session_id());
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
var encryptedEvent = Event(
|
2020-02-15 07:48:41 +00:00
|
|
|
content: encryptedPayload,
|
2020-03-30 09:08:38 +00:00
|
|
|
typeKey: 'm.room.encrypted',
|
2020-02-15 07:48:41 +00:00
|
|
|
senderId: room.client.userID,
|
2020-03-30 09:08:38 +00:00
|
|
|
eventId: '1234',
|
2020-02-15 07:48:41 +00:00
|
|
|
roomId: room.id,
|
|
|
|
room: room,
|
|
|
|
time: DateTime.now(),
|
|
|
|
);
|
2020-03-30 09:08:38 +00:00
|
|
|
var decryptedEvent = room.decryptGroupMessage(encryptedEvent);
|
|
|
|
expect(decryptedEvent.typeKey, 'm.room.message');
|
2020-02-15 07:48:41 +00:00
|
|
|
expect(decryptedEvent.content, payload);
|
|
|
|
});
|
2019-06-11 10:21:45 +00:00
|
|
|
});
|
|
|
|
}
|