2020-06-03 10:16:01 +00:00
|
|
|
/*
|
|
|
|
* Ansible inventory script used at Famedly GmbH for managing many hosts
|
2020-06-04 15:51:49 +00:00
|
|
|
* Copyright (C) 2020 Famedly GmbH
|
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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2020-06-04 11:39:51 +00:00
|
|
|
import 'package:famedlysdk/encryption.dart';
|
2020-06-03 10:16:01 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
import 'package:olm/olm.dart' as olm;
|
|
|
|
|
2020-06-05 07:59:37 +00:00
|
|
|
import '../fake_client.dart';
|
2020-06-03 10:16:01 +00:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
/// All Tests related to the ChatTime
|
|
|
|
group('Key Verification', () {
|
|
|
|
var olmEnabled = true;
|
|
|
|
try {
|
|
|
|
olm.init();
|
|
|
|
olm.Account();
|
|
|
|
} catch (_) {
|
|
|
|
olmEnabled = false;
|
|
|
|
print('[LibOlm] Failed to load LibOlm: ' + _.toString());
|
|
|
|
}
|
|
|
|
print('[LibOlm] Enabled: $olmEnabled');
|
|
|
|
|
2020-06-05 07:59:37 +00:00
|
|
|
if (!olmEnabled) return;
|
|
|
|
|
|
|
|
Client client;
|
|
|
|
Room room;
|
2020-06-03 10:16:01 +00:00
|
|
|
var updateCounter = 0;
|
2020-06-04 11:39:51 +00:00
|
|
|
KeyVerification keyVerification;
|
2020-06-03 10:16:01 +00:00
|
|
|
|
2020-06-04 11:39:51 +00:00
|
|
|
test('setupClient', () async {
|
2020-06-05 07:59:37 +00:00
|
|
|
client = await getClient();
|
|
|
|
room = Room(id: '!localpart:server.abc', client: client);
|
2020-06-04 11:39:51 +00:00
|
|
|
keyVerification = KeyVerification(
|
|
|
|
encryption: client.encryption,
|
|
|
|
room: room,
|
|
|
|
userId: '@alice:example.com',
|
|
|
|
deviceId: 'ABCD',
|
|
|
|
onUpdate: () => updateCounter++,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-06-03 10:16:01 +00:00
|
|
|
test('acceptSas', () async {
|
|
|
|
await keyVerification.acceptSas();
|
|
|
|
});
|
|
|
|
test('acceptVerification', () async {
|
|
|
|
await keyVerification.acceptVerification();
|
|
|
|
});
|
|
|
|
test('cancel', () async {
|
|
|
|
await keyVerification.cancel('m.cancelcode');
|
|
|
|
expect(keyVerification.canceled, true);
|
|
|
|
expect(keyVerification.canceledCode, 'm.cancelcode');
|
|
|
|
expect(keyVerification.canceledReason, null);
|
|
|
|
});
|
|
|
|
test('handlePayload', () async {
|
|
|
|
await keyVerification.handlePayload('m.key.verification.request', {
|
|
|
|
'from_device': 'AliceDevice2',
|
|
|
|
'methods': ['m.sas.v1'],
|
|
|
|
'timestamp': 1559598944869,
|
|
|
|
'transaction_id': 'S0meUniqueAndOpaqueString'
|
|
|
|
});
|
|
|
|
await keyVerification.handlePayload('m.key.verification.start', {
|
|
|
|
'from_device': 'BobDevice1',
|
|
|
|
'method': 'm.sas.v1',
|
|
|
|
'transaction_id': 'S0meUniqueAndOpaqueString'
|
|
|
|
});
|
|
|
|
await keyVerification.handlePayload('m.key.verification.cancel', {
|
|
|
|
'code': 'm.user',
|
|
|
|
'reason': 'User rejected the key verification request',
|
|
|
|
'transaction_id': 'S0meUniqueAndOpaqueString'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
test('rejectSas', () async {
|
|
|
|
await keyVerification.rejectSas();
|
|
|
|
});
|
|
|
|
test('rejectVerification', () async {
|
|
|
|
await keyVerification.rejectVerification();
|
|
|
|
});
|
|
|
|
test('start', () async {
|
|
|
|
await keyVerification.start();
|
|
|
|
});
|
|
|
|
test('verifyActivity', () async {
|
|
|
|
final verified = await keyVerification.verifyActivity();
|
|
|
|
expect(verified, true);
|
2020-06-04 11:39:51 +00:00
|
|
|
keyVerification?.dispose();
|
2020-06-03 10:16:01 +00:00
|
|
|
});
|
2020-06-05 09:32:02 +00:00
|
|
|
|
|
|
|
test('dispose client', () async {
|
|
|
|
await client.dispose(closeDatabase: true);
|
|
|
|
});
|
2020-06-03 10:16:01 +00:00
|
|
|
});
|
|
|
|
}
|