diff options
author | Carl Schwan <carl@carlschwan.eu> | 2021-06-10 21:47:46 +0200 |
---|---|---|
committer | Tobias Fella <fella@posteo.de> | 2021-12-01 21:56:11 +0100 |
commit | 429dbc5670b3f9eba44221395a75221b8306c068 (patch) | |
tree | 8b652453782ea2648c03a06554c53d46539665cf /autotests/testolmaccount.cpp | |
parent | 8e0e3849da4f024d94c1cbfb053dfb47706e2d16 (diff) | |
download | libquotient-429dbc5670b3f9eba44221395a75221b8306c068.tar.gz libquotient-429dbc5670b3f9eba44221395a75221b8306c068.zip |
Add a test (now failing)
Diffstat (limited to 'autotests/testolmaccount.cpp')
-rw-r--r-- | autotests/testolmaccount.cpp | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/autotests/testolmaccount.cpp b/autotests/testolmaccount.cpp index a31f0b98..4ab21a8a 100644 --- a/autotests/testolmaccount.cpp +++ b/autotests/testolmaccount.cpp @@ -4,11 +4,20 @@ // SPDX-License-Identifier: LGPL-2.1-or-later #include "testolmaccount.h" -#include "crypto/qolmaccount.h" -#include "crypto/qolmutility.h" -#include "connection.h" -#include "events/encryptedfile.h" -#include "networkaccessmanager.h" +#include <crypto/qolmaccount.h> +#include <crypto/qolmutility.h> +#include <connection.h> +#include <events/encryptedfile.h> +#include <networkaccessmanager.h> +#include <room.h> +#include <csapi/joining.h> + +// for sleep +#ifdef _WIN32 +#include <Windows.h> +#else +#include <unistd.h> +#endif using namespace Quotient; @@ -531,10 +540,46 @@ void TestOlmAccount::keyChange() 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") + + QString joinedRoom; + + auto job = alice->createRoom(Connection::PublishRoom, QString(), QString(), QString(), {"@bob:localhost"}); + connect(alice.get(), &Connection::newRoom, this, [alice, bob, &joinedRoom, this] (Quotient::Room *room) { + room->activateEncryption(); // TODO we should also wait for it + joinedRoom = room->id(); + sleep(1); + auto job = bob->joinRoom(room->id()); + QSignalSpy spy(job, &BaseJob::result); + QVERIFY(spy.wait(10000)); + }); + QSignalSpy spy(job, &BaseJob::result); + QVERIFY(spy.wait(10000)); + + bob->sync(); + connect(bob.get(), &Connection::syncDone, this, [bob, &joinedRoom, this] { + auto &events = bob->room(joinedRoom)->messageEvents(); + bool hasEncryption = false; + for (auto it = events.rbegin(); it != events.rend(); ++it) { + auto event = it->event(); + if (eventCast<const EncryptedEvent>(event)) { + hasEncryption = true; + } + } + QVERIFY(hasEncryption); + }); + QSignalSpy spy2(bob.get(), &Connection::syncDone); + QVERIFY(spy2.wait(10000)); +} QTEST_MAIN(TestOlmAccount) |