feat: Allow serialising and deserialising OmemoSessionManager
This commit is contained in:
@@ -9,17 +9,7 @@ void main() {
|
||||
final serialised = await oldDevice.toJson();
|
||||
|
||||
final newDevice = Device.fromJson(serialised);
|
||||
expect(oldDevice.id, newDevice.id);
|
||||
expect(await oldDevice.ik.equals(newDevice.ik), true);
|
||||
expect(await oldDevice.spk.equals(newDevice.spk), true);
|
||||
expect(listsEqual(oldDevice.spkSignature, newDevice.spkSignature), true);
|
||||
expect(oldDevice.spkId, newDevice.spkId);
|
||||
|
||||
// Check the Ontime-Prekeys
|
||||
expect(oldDevice.opks.length, newDevice.opks.length);
|
||||
for (final entry in oldDevice.opks.entries) {
|
||||
expect(await newDevice.opks[entry.key]!.equals(entry.value), true);
|
||||
}
|
||||
expect(await oldDevice.equals(newDevice), true);
|
||||
});
|
||||
|
||||
test('Test serialising and deserialising the OmemoDoubleRatchet', () async {
|
||||
@@ -45,26 +35,35 @@ void main() {
|
||||
final aliceSerialised = await aliceOld.toJson();
|
||||
final aliceNew = OmemoDoubleRatchet.fromJson(aliceSerialised);
|
||||
|
||||
expect(await aliceOld.dhs.equals(aliceNew.dhs), true);
|
||||
if (aliceOld.dhr == null) {
|
||||
expect(aliceNew.dhr, null);
|
||||
} else {
|
||||
expect(await aliceOld.dhr!.equals(aliceNew.dhr!), true);
|
||||
expect(await aliceOld.equals(aliceNew), true);
|
||||
});
|
||||
|
||||
test('Test serialising and deserialising the OmemoSessionManager', () async {
|
||||
// Generate a random session
|
||||
final oldSession = await OmemoSessionManager.generateNewIdentity(opkAmount: 4);
|
||||
final bobSession = await OmemoSessionManager.generateNewIdentity(opkAmount: 4);
|
||||
await oldSession.addSessionFromBundle(
|
||||
'bob@localhost',
|
||||
(await bobSession.getDevice()).id,
|
||||
await (await bobSession.getDevice()).toBundle(),
|
||||
);
|
||||
|
||||
// Serialise and deserialise
|
||||
final serialised = await oldSession.toJson();
|
||||
final newSession = OmemoSessionManager.fromJson(serialised);
|
||||
|
||||
final oldDevice = await oldSession.getDevice();
|
||||
final newDevice = await newSession.getDevice();
|
||||
expect(await oldDevice.equals(newDevice), true);
|
||||
expect(oldSession.getDeviceMap(), newSession.getDeviceMap());
|
||||
|
||||
expect(oldSession.getRatchetMap().length, newSession.getRatchetMap().length);
|
||||
for (final session in oldSession.getRatchetMap().entries) {
|
||||
expect(newSession.getRatchetMap().containsKey(session.key), true);
|
||||
|
||||
final oldRatchet = oldSession.getRatchetMap()[session.key]!;
|
||||
final newRatchet = newSession.getRatchetMap()[session.key]!;
|
||||
expect(await oldRatchet.equals(newRatchet), true);
|
||||
}
|
||||
expect(listsEqual(aliceOld.rk, aliceNew.rk), true);
|
||||
if (aliceOld.cks == null) {
|
||||
expect(aliceNew.cks, null);
|
||||
} else {
|
||||
expect(listsEqual(aliceOld.cks!, aliceNew.cks!), true);
|
||||
}
|
||||
if (aliceOld.ckr == null) {
|
||||
expect(aliceNew.ckr, null);
|
||||
} else {
|
||||
expect(listsEqual(aliceOld.ckr!, aliceNew.ckr!), true);
|
||||
}
|
||||
expect(aliceOld.ns, aliceNew.ns);
|
||||
expect(aliceOld.nr, aliceNew.nr);
|
||||
expect(aliceOld.pn, aliceNew.pn);
|
||||
expect(listsEqual(aliceOld.sessionAd, aliceNew.sessionAd), true);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user