diff options
author | Carl Schwan <carl@carlschwan.eu> | 2021-01-24 20:54:30 +0100 |
---|---|---|
committer | Tobias Fella <fella@posteo.de> | 2021-12-01 21:34:52 +0100 |
commit | dca69e8326ce6fd0374123ad8c167a2b0051d8fb (patch) | |
tree | e1cfd169f36a30b957b5f9ba8a2593def0abca39 /autotests | |
parent | 723038cb3fe16c3f0078d00362fcb53c10f9eb4a (diff) | |
download | libquotient-dca69e8326ce6fd0374123ad8c167a2b0051d8fb.tar.gz libquotient-dca69e8326ce6fd0374123ad8c167a2b0051d8fb.zip |
Add group session decrypt/encrypt test and fix bug found by it
Diffstat (limited to 'autotests')
-rw-r--r-- | autotests/testgroupsession.cpp | 27 | ||||
-rw-r--r-- | autotests/testgroupsession.h | 1 |
2 files changed, 24 insertions, 4 deletions
diff --git a/autotests/testgroupsession.cpp b/autotests/testgroupsession.cpp index 1cfe38a9..a99172d7 100644 --- a/autotests/testgroupsession.cpp +++ b/autotests/testgroupsession.cpp @@ -13,13 +13,13 @@ using namespace Quotient; void TestOlmSession::groupSessionPicklingValid() { auto ogs = QOlmOutboundGroupSession::create(); - const auto ogsId = std::get<QByteArray>(ogs->sessionId()); + const auto ogsId = ogs->sessionId(); QVERIFY(QByteArray::fromBase64Encoding(ogsId).decodingStatus == QByteArray::Base64DecodingStatus::Ok); QCOMPARE(0, ogs->sessionMessageIndex()); auto ogsPickled = std::get<QByteArray>(ogs->pickle(Unencrypted {})); - auto ogs2 = std::get<std::unique_ptr<QOlmOutboundGroupSession>>(QOlmOutboundGroupSession::unpickle(ogsPickled, Unencrypted {})); - QCOMPARE(ogsId, std::get<QByteArray>(ogs2->sessionId())); + auto ogs2 = std::get<QOlmOutboundGroupSessionPtr>(QOlmOutboundGroupSession::unpickle(ogsPickled, Unencrypted {})); + QCOMPARE(ogsId, ogs2->sessionId()); auto igs = QOlmInboundGroupSession::create(std::get<QByteArray>(ogs->sessionKey())); const auto igsId = igs->sessionId(); @@ -30,9 +30,28 @@ void TestOlmSession::groupSessionPicklingValid() QCOMPARE(0, igs->firstKnownIndex()); auto igsPickled = igs->pickle(Unencrypted {}); - igs = std::get<std::unique_ptr<QOlmInboundGroupSession>>(QOlmInboundGroupSession::unpickle(igsPickled, Unencrypted {})); + igs = std::get<QOlmInboundGroupSessionPtr>(QOlmInboundGroupSession::unpickle(igsPickled, Unencrypted {})); QCOMPARE(igsId, igs->sessionId()); } +void TestOlmSession::groupSessionCryptoValid() +{ + auto ogs = QOlmOutboundGroupSession::create(); + auto igs = QOlmInboundGroupSession::create(std::get<QByteArray>(ogs->sessionKey())); + QCOMPARE(ogs->sessionId(), igs->sessionId()); + + const auto plainText = QStringLiteral("Hello world!"); + const auto ciphertext = std::get<QByteArray>(ogs->encrypt(plainText)); + qDebug() << ciphertext; + // ciphertext valid base64? + QVERIFY(QByteArray::fromBase64Encoding(ciphertext).decodingStatus == QByteArray::Base64DecodingStatus::Ok); + + const auto decryptionResult = std::get<std::pair<QString, uint32_t>>(igs->decrypt(ciphertext)); + + //// correct plaintext? + QCOMPARE(plainText, decryptionResult.first); + + QCOMPARE(0, decryptionResult.second); +} QTEST_MAIN(TestOlmSession) #endif diff --git a/autotests/testgroupsession.h b/autotests/testgroupsession.h index 28ebf4c9..c9192990 100644 --- a/autotests/testgroupsession.h +++ b/autotests/testgroupsession.h @@ -11,5 +11,6 @@ class TestOlmSession : public QObject private Q_SLOTS: void groupSessionPicklingValid(); + void groupSessionCryptoValid(); }; #endif |