aboutsummaryrefslogtreecommitdiff
path: root/autotests/testolmaccount.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'autotests/testolmaccount.cpp')
-rw-r--r--autotests/testolmaccount.cpp85
1 files changed, 42 insertions, 43 deletions
diff --git a/autotests/testolmaccount.cpp b/autotests/testolmaccount.cpp
index 3b19e7c8..505bdc5f 100644
--- a/autotests/testolmaccount.cpp
+++ b/autotests/testolmaccount.cpp
@@ -10,7 +10,7 @@
#include <e2ee/qolmaccount.h>
#include <e2ee/qolmutility.h>
#include <events/encryptionevent.h>
-#include <events/encryptedfile.h>
+#include <events/filesourceinfo.h>
#include <networkaccessmanager.h>
#include <room.h>
@@ -156,8 +156,7 @@ void TestOlmAccount::encryptedFile()
"sha256": "fdSLu/YkRx3Wyh3KQabP3rd6+SFiKg5lsJZQHtkSAYA"
}})");
- EncryptedFile file;
- JsonObjectConverter<EncryptedFile>::fillFrom(doc.object(), file);
+ const auto file = fromJson<EncryptedFileMetadata>(doc);
QCOMPARE(file.v, "v2");
QCOMPARE(file.iv, "w+sE15fzSc0AAAAAAAAAAA");
@@ -373,47 +372,47 @@ void TestOlmAccount::claimKeys()
// Alice retrieves bob's keys & claims one signed one-time key.
QHash<QString, QStringList> deviceKeys;
deviceKeys[bob->userId()] = QStringList();
- auto job = alice->callApi<QueryKeysJob>(deviceKeys);
- connect(job, &BaseJob::result, this, [bob, alice, job, this] {
- const auto& bobDevices = job->deviceKeys().value(bob->userId());
- QVERIFY(!bobDevices.empty());
-
- // Retrieve the identity key for the current device.
- const auto& bobEd25519 =
- bobDevices.value(bob->deviceId()).keys["ed25519:" + bob->deviceId()];
-
- const auto currentDevice = bobDevices[bob->deviceId()];
-
- // Verify signature.
- QVERIFY(verifyIdentitySignature(currentDevice, bob->deviceId(),
- bob->userId()));
-
- QHash<QString, QHash<QString, QString>> oneTimeKeys;
- oneTimeKeys[bob->userId()] = QHash<QString, QString>();
- oneTimeKeys[bob->userId()][bob->deviceId()] = SignedCurve25519Key;
-
- auto job = alice->callApi<ClaimKeysJob>(oneTimeKeys);
- connect(job, &BaseJob::result, this, [bob, bobEd25519, job] {
- const auto userId = bob->userId();
- const auto deviceId = bob->deviceId();
-
- // The device exists.
- QCOMPARE(job->oneTimeKeys().size(), 1);
- QCOMPARE(job->oneTimeKeys().value(userId).size(), 1);
-
- // The key is the one bob sent.
- const auto& oneTimeKey =
- job->oneTimeKeys().value(userId).value(deviceId);
- QVERIFY(oneTimeKey.canConvert<QVariantMap>());
-
- const auto varMap = oneTimeKey.toMap();
- QVERIFY(std::any_of(varMap.constKeyValueBegin(),
- varMap.constKeyValueEnd(), [](const auto& kv) {
- return kv.first.startsWith(
- SignedCurve25519Key);
- }));
- });
+ auto queryKeysJob = alice->callApi<QueryKeysJob>(deviceKeys);
+ QSignalSpy requestSpy2(queryKeysJob, &BaseJob::result);
+ QVERIFY(requestSpy2.wait(10000));
+
+ const auto& bobDevices = queryKeysJob->deviceKeys().value(bob->userId());
+ QVERIFY(!bobDevices.empty());
+
+ const auto currentDevice = bobDevices[bob->deviceId()];
+
+ // Verify signature.
+ QVERIFY(verifyIdentitySignature(currentDevice, bob->deviceId(),
+ bob->userId()));
+ // Retrieve the identity key for the current device.
+ const auto& bobEd25519 =
+ bobDevices.value(bob->deviceId()).keys["ed25519:" + bob->deviceId()];
+
+ QHash<QString, QHash<QString, QString>> oneTimeKeys;
+ oneTimeKeys[bob->userId()] = QHash<QString, QString>();
+ oneTimeKeys[bob->userId()][bob->deviceId()] = SignedCurve25519Key;
+
+ auto claimKeysJob = alice->callApi<ClaimKeysJob>(oneTimeKeys);
+ connect(claimKeysJob, &BaseJob::result, this, [bob, bobEd25519, claimKeysJob] {
+ const auto userId = bob->userId();
+ const auto deviceId = bob->deviceId();
+
+ // The device exists.
+ QCOMPARE(claimKeysJob->oneTimeKeys().size(), 1);
+ QCOMPARE(claimKeysJob->oneTimeKeys().value(userId).size(), 1);
+
+ // The key is the one bob sent.
+ const auto& oneTimeKeys =
+ claimKeysJob->oneTimeKeys().value(userId).value(deviceId);
+ for (auto it = oneTimeKeys.begin(); it != oneTimeKeys.end(); ++it) {
+ if (it.key().startsWith(SignedCurve25519Key)
+ && it.value().isObject())
+ return;
+ }
+ QFAIL("The claimed one time key is not in /claim response");
});
+ QSignalSpy completionSpy(claimKeysJob, &BaseJob::result);
+ QVERIFY(completionSpy.wait(10000));
}
void TestOlmAccount::claimMultipleKeys()