diff options
author | Carl Schwan <carl@carlschwan.eu> | 2021-06-10 19:14:54 +0200 |
---|---|---|
committer | Tobias Fella <fella@posteo.de> | 2021-12-01 21:56:11 +0100 |
commit | 8e0e3849da4f024d94c1cbfb053dfb47706e2d16 (patch) | |
tree | d9cf1bb342c39525a9453d656ce7e1ab19d1830e /autotests/testolmaccount.cpp | |
parent | fc531b625efa3f0c0ceebed3c23a3d185d398a4d (diff) | |
download | libquotient-8e0e3849da4f024d94c1cbfb053dfb47706e2d16.tar.gz libquotient-8e0e3849da4f024d94c1cbfb053dfb47706e2d16.zip |
Text: Add KeyChange test
Diffstat (limited to 'autotests/testolmaccount.cpp')
-rw-r--r-- | autotests/testolmaccount.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/autotests/testolmaccount.cpp b/autotests/testolmaccount.cpp index 192c97ac..a31f0b98 100644 --- a/autotests/testolmaccount.cpp +++ b/autotests/testolmaccount.cpp @@ -494,4 +494,47 @@ void TestOlmAccount::claimMultipleKeys() QCOMPARE(job->oneTimeKeys()[userId].size(), 3); }); } + +void TestOlmAccount::keyChange() +{ + CREATE_CONNECTION(alice, "alice", "secret", "AlicePhone") + + auto job = alice->createRoom(Connection::PublishRoom, QString(), QString(), QString(), QStringList()); + connect(job, &BaseJob::result, this, [alice, job, this] () { + // Alice syncs to get the first next_batch token. + alice->sync(); + connect(alice.get(), &Connection::syncDone, this, [alice, this] { + const auto nextBatchToken = alice->nextBatchToken(); + + // generate keys and change existing one + auto aliceOlm = alice->olmAccount(); + aliceOlm->generateOneTimeKeys(1); + auto aliceRes = aliceOlm->createUploadKeyRequest(aliceOlm->oneTimeKeys()); + connect(aliceRes, &BaseJob::result, this, [aliceRes] { + QCOMPARE(aliceRes->oneTimeKeyCounts().size(), 1); + QCOMPARE(aliceRes->oneTimeKeyCounts()["signed_curve25519"], 1); + }); + QSignalSpy spy(aliceRes, &BaseJob::result); + + alice->run(aliceRes); + QVERIFY(spy.wait(10000)); + + // The key changes should contain her username + // because of the key uploading. + + auto changeJob = alice->callApi<GetKeysChangesJob>(nextBatchToken, ""); + connect(changeJob, &BaseJob::result, this, [&changeJob, &alice] { + QCOMPARE(changeJob->changed().size(), 1); + QCOMPARE(changeJob->left().size(), 0); + QCOMPARE(changeJob->changed()[0], alice->userId()); + }); + QSignalSpy spy2(changeJob, &BaseJob::result); + QVERIFY(spy2.wait(10000)); + }); + }); + QSignalSpy spy(job, &BaseJob::result); + QVERIFY(spy.wait(10000)); +} + + QTEST_MAIN(TestOlmAccount) |