From b69acdd936ae23428ddc0f1bcab7e3e7ff871a76 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Thu, 15 Sep 2022 23:31:56 +0200 Subject: [PATCH] fix: Fix replaceOnetimePrekey mutating the device's id --- lib/src/omemo/device.dart | 2 +- test/omemo_test.dart | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/src/omemo/device.dart b/lib/src/omemo/device.dart index 7c26081..e2533de 100644 --- a/lib/src/omemo/device.dart +++ b/lib/src/omemo/device.dart @@ -140,7 +140,7 @@ class Device { return Device( jid, - id, + this.id, ik, spk, spkId, diff --git a/test/omemo_test.dart b/test/omemo_test.dart index e0a5792..35d2432 100644 --- a/test/omemo_test.dart +++ b/test/omemo_test.dart @@ -12,6 +12,36 @@ void main() { print('${record.level.name}: ${record.message}'); }); + test('Test replacing a onetime prekey', () async { + const aliceJid = 'alice@server.example'; + final device = await Device.generateNewDevice(aliceJid, opkAmount: 1); + + final newDevice = await device.replaceOnetimePrekey(0); + + expect(device.jid, newDevice.jid); + expect(device.id, newDevice.id); + + var opksMatch = true; + if (newDevice.opks.length != device.opks.length) { + opksMatch = false; + } else { + for (final entry in device.opks.entries) { + final m = await newDevice.opks[entry.key]?.equals(entry.value) ?? false; + if (!m) opksMatch = false; + } + } + + expect(opksMatch, true); + expect(await device.ik.equals(newDevice.ik), true); + expect(await device.spk.equals(newDevice.spk), true); + + final oldSpkMatch = device.oldSpk != null ? + await device.oldSpk!.equals(newDevice.oldSpk!) : + newDevice.oldSpk == null; + expect(oldSpkMatch, true); + expect(listsEqual(device.spkSignature, newDevice.spkSignature), true); + }); + test('Test using OMEMO sessions with only one device per user', () async { const aliceJid = 'alice@server.example'; const bobJid = 'bob@other.server.example';