2020-02-04 13:41:13 +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
|
|
|
|
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
/// All Tests related to device keys
|
2020-03-30 09:08:38 +00:00
|
|
|
group('Device keys', () {
|
|
|
|
test('fromJson', () async {
|
|
|
|
var rawJson = <String, dynamic>{
|
|
|
|
'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-04 13:41:13 +00:00
|
|
|
},
|
2020-03-30 09:08:38 +00:00
|
|
|
'signatures': {
|
|
|
|
'@alice:example.com': {
|
|
|
|
'ed25519:JLAFKJWSCS':
|
|
|
|
'dSO80A01XiigH3uBiDVx/EjzaoycHcjq9lfQX0uWsqxl2giMIiSPR8a4d291W1ihKJL/a+myXS367WT6NAIcBA'
|
2020-02-04 13:41:13 +00:00
|
|
|
}
|
|
|
|
},
|
2020-03-30 09:08:38 +00:00
|
|
|
'unsigned': {'device_display_name': "Alice's mobile phone"},
|
|
|
|
'verified': false,
|
|
|
|
'blocked': true,
|
2020-02-04 13:41:13 +00:00
|
|
|
};
|
2020-03-30 09:08:38 +00:00
|
|
|
var rawListJson = <String, dynamic>{
|
|
|
|
'user_id': '@alice:example.com',
|
|
|
|
'outdated': true,
|
|
|
|
'device_keys': {'JLAFKJWSCS': rawJson},
|
2020-02-04 13:41:13 +00:00
|
|
|
};
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
var userDeviceKeys = <String, DeviceKeysList>{
|
2020-05-21 13:32:06 +00:00
|
|
|
'@alice:example.com': DeviceKeysList.fromJson(rawListJson, null),
|
2020-02-04 13:41:13 +00:00
|
|
|
};
|
2020-03-30 09:08:38 +00:00
|
|
|
var userDeviceKeyRaw = <String, dynamic>{
|
|
|
|
'@alice:example.com': rawListJson,
|
2020-02-04 13:41:13 +00:00
|
|
|
};
|
|
|
|
|
2020-05-22 09:13:58 +00:00
|
|
|
final key = DeviceKeys.fromJson(rawJson, null);
|
|
|
|
rawJson.remove('verified');
|
|
|
|
rawJson.remove('blocked');
|
|
|
|
expect(json.encode(key.toJson()),
|
2020-02-04 13:41:13 +00:00
|
|
|
json.encode(rawJson));
|
2020-05-22 09:13:58 +00:00
|
|
|
expect(key.verified, false);
|
|
|
|
expect(key.blocked, true);
|
2020-05-21 13:32:06 +00:00
|
|
|
expect(json.encode(DeviceKeysList.fromJson(rawListJson, null).toJson()),
|
2020-02-04 13:41:13 +00:00
|
|
|
json.encode(rawListJson));
|
|
|
|
|
2020-03-30 09:08:38 +00:00
|
|
|
var mapFromRaw = <String, DeviceKeysList>{};
|
2020-02-04 13:41:13 +00:00
|
|
|
for (final rawListEntry in userDeviceKeyRaw.entries) {
|
|
|
|
mapFromRaw[rawListEntry.key] =
|
2020-05-21 13:32:06 +00:00
|
|
|
DeviceKeysList.fromJson(rawListEntry.value, null);
|
2020-02-04 13:41:13 +00:00
|
|
|
}
|
|
|
|
expect(mapFromRaw.toString(), userDeviceKeys.toString());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|