From ffe43b5b9caa2641f471fbcc983b1615dd603588 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Sun, 1 Sep 2024 16:21:58 +0200 Subject: [PATCH] Fixes --- autotests/testolmaccount.cpp | 70 +++++++++++++++++------------------- autotests/testolmutility.cpp | 22 ------------ 2 files changed, 33 insertions(+), 59 deletions(-) diff --git a/autotests/testolmaccount.cpp b/autotests/testolmaccount.cpp index 6f692279..44177bbf 100644 --- a/autotests/testolmaccount.cpp +++ b/autotests/testolmaccount.cpp @@ -21,11 +21,10 @@ using namespace Quotient; void TestOlmAccount::pickleUnpickledTest() { auto olmAccount = QOlmAccount::newAccount(this, QStringLiteral("@foo:bar.com"), QStringLiteral("QuotientTestDevice")); + auto picklingKey = PicklingKey::generate(); auto identityKeys = olmAccount->identityKeys(); - auto key = PicklingKey::generate(); - auto pickled = olmAccount->pickle(key); - auto olmAccount2 = QOlmAccount::unpickle(std::move(pickled), key, QStringLiteral("@foo:bar.com"), QStringLiteral("QuotientTestDevice"), nullptr); - + auto pickled = olmAccount->pickle(picklingKey); + auto olmAccount2 = QOlmAccount::unpickle(std::move(pickled), picklingKey, QStringLiteral("@foo:bar.com"), QStringLiteral("QuotientTestDevice"), nullptr); auto identityKeys2 = olmAccount2->identityKeys(); QCOMPARE(identityKeys.curve25519, identityKeys2.curve25519); QCOMPARE(identityKeys.ed25519, identityKeys2.ed25519); @@ -33,9 +32,6 @@ void TestOlmAccount::pickleUnpickledTest() void TestOlmAccount::identityKeysValid() { - QOlmAccount olmAccount(u"@foo:bar.com"_s, u"QuotientTestDevice"_s); - olmAccount.setupNewAccount(); - const auto identityKeys = olmAccount.identityKeys(); auto olmAccount = QOlmAccount::newAccount(this, QStringLiteral("@foo:bar.com"), QStringLiteral("QuotientTestDevice")); const auto identityKeys = olmAccount->identityKeys(); const auto curve25519 = identityKeys.curve25519; @@ -65,8 +61,8 @@ void TestOlmAccount::signatureValid() void TestOlmAccount::oneTimeKeysValid() { auto olmAccount = QOlmAccount::newAccount(this, QStringLiteral("@foo:bar.com"), QStringLiteral("QuotientTestDevice")); - const auto maxNumberOfOneTimeKeys = olmAccount->maxNumberOfOneTimeKeys(); - QCOMPARE(50, maxNumberOfOneTimeKeys); + const auto numberOfOneTimeKeysToGenerate = olmAccount->maxNumberOfOneTimeKeys(); + QCOMPARE(50, numberOfOneTimeKeysToGenerate); const auto oneTimeKeysEmpty = olmAccount->oneTimeKeys(); QVERIFY(oneTimeKeysEmpty.keys.isEmpty()); @@ -80,20 +76,20 @@ void TestOlmAccount::deviceKeys() { // copied from mtxclient DeviceKeys device1; - device1.userId = "@alice:example.com"_L1; - device1.deviceId = "JLAFKJWSCS"_L1; - device1.keys = {{"curve25519:JLAFKJWSCS"_L1, "3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI"_L1}, - {"ed25519:JLAFKJWSCS"_L1, "lEuiRJBit0IG6nUf5pUzWTUEsRVVe/HJkoKuEww9ULI"_L1}}; + device1.userId = "@alice:example.com"_ls; + device1.deviceId = "JLAFKJWSCS"_ls; + device1.keys = {{"curve25519:JLAFKJWSCS"_ls, "3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI"_ls}, + {"ed25519:JLAFKJWSCS"_ls, "lEuiRJBit0IG6nUf5pUzWTUEsRVVe/HJkoKuEww9ULI"_ls}}; // TODO that should be the default value device1.algorithms = QStringList { OlmV1Curve25519AesSha2AlgoKey, MegolmV1AesSha2AlgoKey }; device1.signatures = { - {"@alice:example.com"_L1, - {{"ed25519:JLAFKJWSCS"_L1, + {"@alice:example.com"_ls, + {{"ed25519:JLAFKJWSCS"_ls, "dSO80A01XiigH3uBiDVx/EjzaoycHcjq9lfQX0uWsqxl2giMIiSPR8a4d291W1ihKJL/" - "a+myXS367WT6NAIcBA"_L1}}}}; + "a+myXS367WT6NAIcBA"_ls}}}}; QJsonObject j; JsonObjectConverter::dumpTo(j, device1); @@ -159,19 +155,19 @@ void TestOlmAccount::encryptedFile() const auto file = fromJson(doc); - QCOMPARE(file.v, "v2"_L1); - QCOMPARE(file.iv, "w+sE15fzSc0AAAAAAAAAAA"_L1); - QCOMPARE(file.hashes["sha256"_L1], "fdSLu/YkRx3Wyh3KQabP3rd6+SFiKg5lsJZQHtkSAYA"_L1); - QCOMPARE(file.key.alg, "A256CTR"_L1); + QCOMPARE(file.v, "v2"_ls); + QCOMPARE(file.iv, "w+sE15fzSc0AAAAAAAAAAA"_ls); + QCOMPARE(file.hashes["sha256"_ls], "fdSLu/YkRx3Wyh3KQabP3rd6+SFiKg5lsJZQHtkSAYA"_ls); + QCOMPARE(file.key.alg, "A256CTR"_ls); QCOMPARE(file.key.ext, true); - QCOMPARE(file.key.k, "aWF6-32KGYaC3A_FEUCk1Bt0JA37zP0wrStgmdCaW-0"_L1); + QCOMPARE(file.key.k, "aWF6-32KGYaC3A_FEUCk1Bt0JA37zP0wrStgmdCaW-0"_ls); QCOMPARE(file.key.keyOps.size(), 2); - QCOMPARE(file.key.kty, "oct"_L1); + QCOMPARE(file.key.kty, "oct"_ls); } void TestOlmAccount::uploadIdentityKey() { - CREATE_CONNECTION(conn, "alice1"_L1, "secret"_L1, "AlicePhone"_L1) + CREATE_CONNECTION(conn, "alice1"_ls, "secret"_ls, "AlicePhone"_ls) auto olmAccount = conn->olmAccount(); auto idKeys = olmAccount->identityKeys(); @@ -196,7 +192,7 @@ void TestOlmAccount::uploadIdentityKey() void TestOlmAccount::uploadOneTimeKeys() { - CREATE_CONNECTION(conn, "alice2"_L1, "secret"_L1, "AlicePhone"_L1) + CREATE_CONNECTION(conn, "alice2"_ls, "secret"_ls, "AlicePhone"_ls) auto olmAccount = conn->olmAccount(); olmAccount->generateOneTimeKeys(5); @@ -220,7 +216,7 @@ void TestOlmAccount::uploadOneTimeKeys() void TestOlmAccount::uploadSignedOneTimeKeys() { - CREATE_CONNECTION(conn, "alice3"_L1, "secret"_L1, "AlicePhone"_L1) + CREATE_CONNECTION(conn, "alice3"_ls, "secret"_ls, "AlicePhone"_ls) auto olmAccount = conn->olmAccount(); olmAccount->generateOneTimeKeys(5); @@ -239,7 +235,7 @@ void TestOlmAccount::uploadSignedOneTimeKeys() void TestOlmAccount::uploadKeys() { - CREATE_CONNECTION(conn, "alice4"_L1, "secret"_L1, "AlicePhone"_L1) + CREATE_CONNECTION(conn, "alice4"_ls, "secret"_ls, "AlicePhone"_ls) auto olmAccount = conn->olmAccount(); auto idks = olmAccount->identityKeys(); olmAccount->generateOneTimeKeys(1); @@ -257,8 +253,8 @@ void TestOlmAccount::uploadKeys() void TestOlmAccount::queryTest() { - CREATE_CONNECTION(alice, "alice5"_L1, "secret"_L1, "AlicePhone"_L1) - CREATE_CONNECTION(bob, "bob1"_L1, "secret"_L1, "BobPhone"_L1) + CREATE_CONNECTION(alice, "alice5"_ls, "secret"_ls, "AlicePhone"_ls) + CREATE_CONNECTION(bob, "bob1"_ls, "secret"_ls, "BobPhone"_ls) // Create and upload keys for both users. auto aliceOlm = alice->olmAccount(); @@ -325,8 +321,8 @@ void TestOlmAccount::queryTest() void TestOlmAccount::claimKeys() { - CREATE_CONNECTION(alice, "alice6"_L1, "secret"_L1, "AlicePhone"_L1) - CREATE_CONNECTION(bob, "bob2"_L1, "secret"_L1, "BobPhone"_L1) + CREATE_CONNECTION(alice, "alice6"_ls, "secret"_ls, "AlicePhone"_ls) + CREATE_CONNECTION(bob, "bob2"_ls, "secret"_ls, "BobPhone"_ls) // Bob uploads his keys. auto *bobOlm = bob->olmAccount(); @@ -354,8 +350,8 @@ void TestOlmAccount::claimKeys() bob->deviceId(), bob->userId())); // Retrieve the identity key for the current device to check after claiming - const auto& bobEd25519 = - bobDevices.value(bob->deviceId()).keys.value("ed25519:"_L1 + bob->deviceId()); + const auto& bobEd25519 = bobDevices.value(bob->deviceId()) + .keys.value("ed25519:%1"_ls.arg(bob->deviceId())); const QHash> oneTimeKeys{ { bob->userId(), { { bob->deviceId(), SignedCurve25519Key } } } @@ -383,9 +379,9 @@ void TestOlmAccount::claimKeys() void TestOlmAccount::claimMultipleKeys() { // Login with alice multiple times - CREATE_CONNECTION(alice, "alice7"_L1, "secret"_L1, "AlicePhone"_L1) - CREATE_CONNECTION(alice1, "alice7"_L1, "secret"_L1, "AlicePhone"_L1) - CREATE_CONNECTION(alice2, "alice7"_L1, "secret"_L1, "AlicePhone"_L1) + CREATE_CONNECTION(alice, "alice7"_ls, "secret"_ls, "AlicePhone"_ls) + CREATE_CONNECTION(alice1, "alice7"_ls, "secret"_ls, "AlicePhone"_ls) + CREATE_CONNECTION(alice2, "alice7"_ls, "secret"_ls, "AlicePhone"_ls) auto olm = alice->olmAccount(); olm->generateOneTimeKeys(10); @@ -418,7 +414,7 @@ void TestOlmAccount::claimMultipleKeys() QVERIFY(spy2.wait(10000)); // Bob will claim all keys from alice - CREATE_CONNECTION(bob, "bob3"_L1, "secret"_L1, "BobPhone"_L1) + CREATE_CONNECTION(bob, "bob3"_ls, "secret"_ls, "BobPhone"_ls) QStringList devices_; devices_ << alice->deviceId() @@ -440,7 +436,7 @@ void TestOlmAccount::claimMultipleKeys() void TestOlmAccount::enableEncryption() { - CREATE_CONNECTION(alice, "alice9"_L1, "secret"_L1, "AlicePhone"_L1) + CREATE_CONNECTION(alice, "alice9"_ls, "secret"_ls, "AlicePhone"_ls) auto job = alice->createRoom(Connection::PublishRoom, {}, {}, {}, {}); QSignalSpy createRoomSpy(job, &BaseJob::success); diff --git a/autotests/testolmutility.cpp b/autotests/testolmutility.cpp index 8ff2d42e..5d49a92c 100644 --- a/autotests/testolmutility.cpp +++ b/autotests/testolmutility.cpp @@ -92,27 +92,6 @@ void TestOlmUtility::validUploadKeysRequest() auto idSig = alice->signIdentityKeys(); const QJsonObject body{ -<<<<<<< HEAD - { "algorithms"_L1, toJson(SupportedAlgorithms) }, - { "user_id"_L1, userId }, - { "device_id"_L1, deviceId }, - { "keys"_L1, QJsonObject{ { "curve25519:"_L1 + deviceId, alice.identityKeys().curve25519 }, - { "ed25519:"_L1 + deviceId, alice.identityKeys().ed25519 } } }, - { "signatures"_L1, QJsonObject{ { userId, QJsonObject{ { "ed25519:"_L1 + deviceId, - QString::fromLatin1(idSig) } } } } } -||||||| parent of 4d89474e (libOlm is dead, long live vodozemac) - { "algorithms"_ls, toJson(SupportedAlgorithms) }, - { "user_id"_ls, userId }, - { "device_id"_ls, deviceId }, - { "keys"_ls, - QJsonObject{ - { "curve25519:"_ls + deviceId, alice.identityKeys().curve25519 }, - { "ed25519:"_ls + deviceId, alice.identityKeys().ed25519 } } }, - { "signatures"_ls, - QJsonObject{ - { userId, QJsonObject{ { "ed25519:"_ls + deviceId, - QString::fromLatin1(idSig) } } } } } -======= { "algorithms"_ls, toJson(SupportedAlgorithms) }, { "user_id"_ls, userId }, { "device_id"_ls, deviceId }, @@ -124,7 +103,6 @@ void TestOlmUtility::validUploadKeysRequest() QJsonObject{ { userId, QJsonObject{ { "ed25519:"_ls + deviceId, QString::fromLatin1(idSig) } } } } } ->>>>>>> 4d89474e (libOlm is dead, long live vodozemac) }; const auto deviceKeys = alice->deviceKeys();