aboutsummaryrefslogtreecommitdiff
path: root/autotests
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-05-27 19:09:26 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-05-29 08:22:35 +0200
commit0f8335a32debc4c61d9fc9875c79c0ba6ba05357 (patch)
treefb78230a898754b2df982b890a4129839937f110 /autotests
parent64797165f04a16d290dd27c2f962060b40f85be3 (diff)
downloadlibquotient-0f8335a32debc4c61d9fc9875c79c0ba6ba05357.tar.gz
libquotient-0f8335a32debc4c61d9fc9875c79c0ba6ba05357.zip
Move some Meg/Olm session logic from Room::Private to Connection::Private
Functions (Room::Private::)createOlmSession, payloadForUserDevice and sendRoomKeyToDevices don't have a lot to do with the given Room object but deal with quite a few things stored in Connection. This commit moves them to Connection::Private, exposing sendSessionKeyToDevices (the new name for sendRoomKeyToDevices) in Connection so that Room could call it from Room::P::sendMegolmSession(). While moving these over, a few additional things were adjusted: - more functions marked as const - a few functions could be moved now from Connection to Connection::Private - false slots in Connection (such as picklingMode) are moved out of the slots block - keys.yml in Matrix CS API definitions has been adjusted to match the real structure of `/claim` response (see quotient-im/matrix-spec repo); csapi/keys.h has been regenerated accordingly.
Diffstat (limited to 'autotests')
-rw-r--r--autotests/testolmaccount.cpp80
1 files changed, 40 insertions, 40 deletions
diff --git a/autotests/testolmaccount.cpp b/autotests/testolmaccount.cpp
index b509d12f..3fb8ac24 100644
--- a/autotests/testolmaccount.cpp
+++ b/autotests/testolmaccount.cpp
@@ -378,47 +378,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()