diff options
| author | Linus Jahn <lnj@kaidan.im> | 2021-09-18 19:33:05 +0200 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2021-09-28 17:08:08 +0200 |
| commit | 6d01e3e4d7b07b7dfb11e76af1bd0585153d12af (patch) | |
| tree | 299d19443ef2aaf2f182e4eaf8a6329f6af4754c /tests | |
| parent | 8045a7ff6e389fe88794ff92c173a7e61dfaf0e2 (diff) | |
| download | qxmpp-6d01e3e4d7b07b7dfb11e76af1bd0585153d12af.tar.gz | |
tests: Add minimal unit test for SCE hooks
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/qxmppclient/tst_qxmppclient.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/qxmppclient/tst_qxmppclient.cpp b/tests/qxmppclient/tst_qxmppclient.cpp index be28cfc2..45b4bfab 100644 --- a/tests/qxmppclient/tst_qxmppclient.cpp +++ b/tests/qxmppclient/tst_qxmppclient.cpp @@ -23,6 +23,8 @@ */ #include "QXmppClient.h" +#include "QXmppE2eeExtension.h" +#include "QXmppFutureUtils_p.h" #include "QXmppLogger.h" #include "QXmppMessage.h" #include "QXmppRosterManager.h" @@ -32,6 +34,8 @@ #include "util.h" #include <QObject> +using namespace QXmpp::Private; + class tst_QXmppClient : public QObject { Q_OBJECT @@ -44,6 +48,8 @@ private slots: void testIndexOfExtension(); + void testE2eeEncryption(); + private: QXmppClient *client; }; @@ -104,5 +110,71 @@ void tst_QXmppClient::testIndexOfExtension() QCOMPARE(client->indexOfExtension<QXmppVCardManager>(), 1); } +class EncryptionExtension : public QXmppE2eeExtension +{ +public: + bool messageCalled = false; + bool iqCalled = false; + + QFuture<EncryptMessageResult> encryptMessage(QXmppMessage &&) override + { + messageCalled = true; + return makeReadyFuture<EncryptMessageResult>(QXmpp::SendError { "it's only a test", QXmpp::SendError::EncryptionError }); + } + + QFuture<IqEncryptResult> encryptIq(QXmppIq &&) override + { + iqCalled = true; + return makeReadyFuture<IqEncryptResult>(QXmpp::SendError { "it's only a test", QXmpp::SendError::EncryptionError }); + } + + QFuture<IqDecryptResult> decryptIq(const QDomElement &) override + { + return makeReadyFuture<IqDecryptResult>(QXmpp::SendError { "it's only a test", QXmpp::SendError::EncryptionError }); + } +}; + +void tst_QXmppClient::testE2eeEncryption() +{ + QXmppClient client; + EncryptionExtension encrypter; + client.setEncryptionExtension(&encrypter); + + auto result = client.send(QXmppMessage("me@qxmpp.org", "somebody@qxmpp.org", "Hello")); + QVERIFY(encrypter.messageCalled); + QVERIFY(!encrypter.iqCalled); + QCoreApplication::processEvents(); + expectFutureVariant<QXmpp::SendError>(result); + + encrypter.messageCalled = false; + result = client.send(QXmppPresence(QXmppPresence::Available)); + QVERIFY(!encrypter.messageCalled); + QVERIFY(!encrypter.iqCalled); + + auto createRequest = []() { + QXmppDiscoveryIq request; + request.setType(QXmppIq::Get); + request.setQueryType(QXmppDiscoveryIq::InfoQuery); + request.setTo("component.qxmpp.org"); + return request; + }; + + client.send(createRequest()); + QVERIFY(encrypter.iqCalled); + encrypter.iqCalled = false; + + client.sendUnencrypted(createRequest()); + QVERIFY(!encrypter.iqCalled); + encrypter.iqCalled = false; + + client.sendIq(createRequest()); + QVERIFY(!encrypter.iqCalled); + encrypter.iqCalled = false; + + client.sendSensitiveIq(createRequest()); + QVERIFY(encrypter.iqCalled); + encrypter.iqCalled = false; +} + QTEST_MAIN(tst_QXmppClient) #include "tst_qxmppclient.moc" |
