diff options
-rwxr-xr-x | autotests/run-tests.sh | 16 | ||||
-rw-r--r-- | autotests/testolmaccount.cpp | 79 | ||||
-rw-r--r-- | autotests/testolmaccount.h | 1 |
3 files changed, 31 insertions, 65 deletions
diff --git a/autotests/run-tests.sh b/autotests/run-tests.sh index 0d0a4ca3..74a8c544 100755 --- a/autotests/run-tests.sh +++ b/autotests/run-tests.sh @@ -1,5 +1,6 @@ mkdir -p data chmod 0777 data +rm ~/.local/share/testolmaccount -rf docker run -v `pwd`/data:/data --rm \ -e SYNAPSE_SERVER_NAME=localhost -e SYNAPSE_REPORT_STATS=no matrixdotorg/synapse:v1.24.0 generate ./.ci/adjust-config.sh @@ -14,9 +15,20 @@ trap "rm -rf ./data/*; docker rm -f synapse 2>&1 >/dev/null; trap - EXIT" EXIT echo Waiting for synapse to start... until curl -s -f -k https://localhost:1234/_matrix/client/versions; do echo "Checking ..."; sleep 2; done echo Register alice -docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u alice -p secret -c /data/homeserver.yaml https://localhost:8008' +docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u alice1 -p secret -c /data/homeserver.yaml https://localhost:8008' +docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u alice2 -p secret -c /data/homeserver.yaml https://localhost:8008' +docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u alice3 -p secret -c /data/homeserver.yaml https://localhost:8008' +docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u alice4 -p secret -c /data/homeserver.yaml https://localhost:8008' +docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u alice5 -p secret -c /data/homeserver.yaml https://localhost:8008' +docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u alice6 -p secret -c /data/homeserver.yaml https://localhost:8008' +docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u alice7 -p secret -c /data/homeserver.yaml https://localhost:8008' +docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u alice8 -p secret -c /data/homeserver.yaml https://localhost:8008' +docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u alice9 -p secret -c /data/homeserver.yaml https://localhost:8008' echo Register bob -docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u bob -p secret -c /data/homeserver.yaml https://localhost:8008' +docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u bob1 -p secret -c /data/homeserver.yaml https://localhost:8008' +docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u bob2 -p secret -c /data/homeserver.yaml https://localhost:8008' +docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u bob3 -p secret -c /data/homeserver.yaml https://localhost:8008' +docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u bob4 -p secret -c /data/homeserver.yaml https://localhost:8008' echo Register carl docker exec synapse /bin/sh -c 'register_new_matrix_user --admin -u carl -p secret -c /data/homeserver.yaml https://localhost:8008' diff --git a/autotests/testolmaccount.cpp b/autotests/testolmaccount.cpp index 36f10f2e..033fff32 100644 --- a/autotests/testolmaccount.cpp +++ b/autotests/testolmaccount.cpp @@ -192,7 +192,7 @@ void TestOlmAccount::encryptedFile() void TestOlmAccount::uploadIdentityKey() { - CREATE_CONNECTION(conn, "alice", "secret", "AlicePhone") + CREATE_CONNECTION(conn, "alice1", "secret", "AlicePhone") auto olmAccount = conn->olmAccount(); auto idKeys = olmAccount->identityKeys(); @@ -214,7 +214,7 @@ void TestOlmAccount::uploadIdentityKey() void TestOlmAccount::uploadOneTimeKeys() { - CREATE_CONNECTION(conn, "alice", "secret", "AlicePhone") + CREATE_CONNECTION(conn, "alice2", "secret", "AlicePhone") auto olmAccount = conn->olmAccount(); auto nKeys = olmAccount->generateOneTimeKeys(5); @@ -242,7 +242,7 @@ void TestOlmAccount::uploadOneTimeKeys() void TestOlmAccount::uploadSignedOneTimeKeys() { - CREATE_CONNECTION(conn, "alice", "secret", "AlicePhone") + CREATE_CONNECTION(conn, "alice3", "secret", "AlicePhone") auto olmAccount = conn->olmAccount(); auto nKeys = olmAccount->generateOneTimeKeys(5); QCOMPARE(nKeys, 5); @@ -270,7 +270,7 @@ void TestOlmAccount::uploadSignedOneTimeKeys() void TestOlmAccount::uploadKeys() { - CREATE_CONNECTION(conn, "alice", "secret", "AlicePhone") + CREATE_CONNECTION(conn, "alice4", "secret", "AlicePhone") auto olmAccount = conn->olmAccount(); auto idks = olmAccount->identityKeys(); olmAccount->generateOneTimeKeys(1); @@ -290,8 +290,8 @@ void TestOlmAccount::uploadKeys() void TestOlmAccount::queryTest() { - CREATE_CONNECTION(alice, "alice", "secret", "AlicePhone") - CREATE_CONNECTION(bob, "bob", "secret", "BobPhone") + CREATE_CONNECTION(alice, "alice5", "secret", "AlicePhone") + CREATE_CONNECTION(bob, "bob1", "secret", "BobPhone") // Create and upload keys for both users. auto aliceOlm = alice->olmAccount(); @@ -360,8 +360,8 @@ void TestOlmAccount::queryTest() void TestOlmAccount::claimKeys() { - CREATE_CONNECTION(alice, "alice", "secret", "AlicePhone") - CREATE_CONNECTION(bob, "bob", "secret", "BobPhone") + CREATE_CONNECTION(alice, "alice6", "secret", "AlicePhone") + CREATE_CONNECTION(bob, "bob2", "secret", "BobPhone") // Bob uploads his keys. auto *bobOlm = bob->olmAccount(); @@ -426,9 +426,9 @@ void TestOlmAccount::claimKeys() void TestOlmAccount::claimMultipleKeys() { // Login with alice multiple times - CREATE_CONNECTION(alice, "alice", "secret", "AlicePhone") - CREATE_CONNECTION(alice1, "alice", "secret", "AlicePhone") - CREATE_CONNECTION(alice2, "alice", "secret", "AlicePhone") + CREATE_CONNECTION(alice, "alice7", "secret", "AlicePhone") + CREATE_CONNECTION(alice1, "alice7", "secret", "AlicePhone") + CREATE_CONNECTION(alice2, "alice7", "secret", "AlicePhone") auto olm = alice->olmAccount(); olm->generateOneTimeKeys(10); @@ -465,7 +465,7 @@ void TestOlmAccount::claimMultipleKeys() QVERIFY(spy2.wait(1000)); // TODO this is failing even with 10000 // Bob will claim all keys from alice - CREATE_CONNECTION(bob, "bob", "secret", "BobPhone") + CREATE_CONNECTION(bob, "bob3", "secret", "BobPhone") QStringList devices_; devices_ << alice->deviceId() @@ -487,50 +487,10 @@ void TestOlmAccount::claimMultipleKeys() }); } -void TestOlmAccount::keyChange() -{ - CREATE_CONNECTION(alice, "alice", "secret", "AlicePhone") - - auto job = alice->createRoom(Connection::PublishRoom, {}, {}, {}, {}); - connect(job, &BaseJob::result, this, [alice, job, this] { - QVERIFY(job->status().good()); - // 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()); - 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().cbegin(), alice->userId()); - }); - QSignalSpy spy2(changeJob, &BaseJob::result); - QVERIFY(spy2.wait(10000)); - }); - QSignalSpy spy2(alice.get(), &Connection::syncDone); - QVERIFY(spy2.wait(10000)); - }); - QSignalSpy spy(job, &BaseJob::result); - QVERIFY(spy.wait(10000)); -} - void TestOlmAccount::enableEncryption() { - CREATE_CONNECTION(alice, "alice", "secret", "AlicePhone") - CREATE_CONNECTION(bob, "bob", "secret", "BobPhone") + CREATE_CONNECTION(alice, "alice9", "secret", "AlicePhone") + CREATE_CONNECTION(bob, "bob4", "secret", "BobPhone") QString joinedRoomId; @@ -547,7 +507,7 @@ void TestOlmAccount::enableEncryption() QVERIFY(spy.wait(10000)); QVERIFY(spy1.wait(10000)); }); - + alice->sync(); QSignalSpy spy(job, &BaseJob::result); QVERIFY(spy.wait(10000)); @@ -558,14 +518,9 @@ void TestOlmAccount::enableEncryption() bool hasEncryption = false; for (auto it = events.rbegin(); it != events.rend(); ++it) { const auto& event = it->event(); - if (eventCast<const EncryptedEvent>(event)) { + if (is<EncryptionEvent>(*event)) { hasEncryption = true; - } else { - qDebug() << event->matrixType() << typeId<EncryptedEvent>() - << event->type(); - if (is<EncryptionEvent>(*event)) { - qDebug() << event->contentJson(); - } + break; } } QVERIFY(bob->room(joinedRoomId)->usesEncryption()); diff --git a/autotests/testolmaccount.h b/autotests/testolmaccount.h index f1f80454..367092f6 100644 --- a/autotests/testolmaccount.h +++ b/autotests/testolmaccount.h @@ -28,6 +28,5 @@ private Q_SLOTS: void queryTest(); void claimKeys(); void claimMultipleKeys(); - void keyChange(); void enableEncryption(); }; |