[network/ruqola] src/core/autotests: Clean up

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 25de3f0f38995a671d5442c646588610b0d3b634 by Laurent Montel.
Committed on 07/08/2026 at 10:56.
Pushed by mlaurent into branch 'master'.

Clean up

M  +1    -122  src/core/autotests/sessionkeydistributiontest.cpp
M  +0    -30   src/core/autotests/sessionkeydistributiontest.h

https://invent.kde.org/network/ruqola/-/commit/25de3f0f38995a671d5442c646588610b0d3b634

diff --git a/src/core/autotests/sessionkeydistributiontest.cpp b/src/core/autotests/sessionkeydistributiontest.cpp
index ff29ee73a4..3508125b29 100644
--- a/src/core/autotests/sessionkeydistributiontest.cpp
+++ b/src/core/autotests/sessionkeydistributiontest.cpp
@@ -5,13 +5,8 @@
 */
 
 #include "sessionkeydistributiontest.h"
-#include "e2e/acceptsuggestedgroupkeyjob.h"
 #include "e2e/provideuserswithsuggestedgroupkeysjob.h"
-#include "e2e/rejectsuggestedgroupkeyjob.h"
-#include "encryption/encryptionutils.h"
 #include "restapimethod.h"
-// #include "loginmanager.h"
-// #include "uploaddownloadrsakeypair.h"
 #include <QCoreApplication>
 #include <QJsonArray>
 #include <QJsonDocument>
@@ -24,122 +19,6 @@ SessionKeyDistributionTest::SessionKeyDistributionTest(QObject *parent)
 {
 }
 
-/* void SessionKeyDistributionTest::testSessionKeyDistribution()
-{
-    const auto app = QCoreApplication::instance();
-    const auto networkManager = new QNetworkAccessManager(app);
-    const auto url = QStringLiteral("http://localhost:3000");
-    const auto password = QStringLiteral("mypassword123");
-    const auto roomId = QStringLiteral("123"); // Replace with a real room ID
-
-    // Step 1: Login as two user
-    const auto loginManager0 = new LoginManager(app);
-    const auto loginManager1 = new LoginManager(app);
-    QString user1Id, user2Id, user1Auth, user2Auth;
-    auto user1KeyPair = EncryptionUtils::RSAKeyPair();
-    auto user2KeyPair = EncryptionUtils::RSAKeyPair();
-
-    // Step 2: Generate session key (AES-128)
-    const auto sessionKey = EncryptionUtils::generateSessionKey();
-    auto testPassed = false;
-
-    // Step 2.5 Helper: proceed when both users are ready
-    int readyCount = 0;
-    auto proceed = [&]() {
-        if (++readyCount < 2)
-            return;
-
-        // Step 3: Encrypt session key with each user's public key
-        QVector<RocketChatRestApi::SuggestedGroupKey> suggestedKeys;
-        qDebug() << "user1KeyPair.publicKey size:" << user1KeyPair.publicKey.size();
-        const auto encryptedSessionKeyForUser1 = EncryptionUtils::encryptSessionKey(sessionKey, EncryptionUtils::publicKeyFromPEM(user1KeyPair.publicKey));
-        const auto encryptedSessionKeyForUser2 = EncryptionUtils::encryptSessionKey(sessionKey, EncryptionUtils::publicKeyFromPEM(user2KeyPair.publicKey));
-        suggestedKeys.append({user1Id, QString::fromLatin1(encryptedSessionKeyForUser1.toBase64())});
-        suggestedKeys.append({user2Id, QString::fromLatin1(encryptedSessionKeyForUser2.toBase64())});
-
-        // Step 4: Distribute encrypted keys using API
-        const auto provideMethod = new RocketChatRestApi::RestApiMethod;
-        provideMethod->setServerUrl(url);
-        const auto provideJob = new RocketChatRestApi::ProvideUsersWithSuggestedGroupKeysJob(app);
-        provideJob->setNetworkAccessManager(networkManager);
-        provideJob->setRestApiMethod(provideMethod);
-        provideJob->setRoomId(roomId);
-        provideJob->setKeys(suggestedKeys);
-        QObject::connect(
-            provideJob,
-            &RocketChatRestApi::ProvideUsersWithSuggestedGroupKeysJob::provideUsersWithSuggestedGroupKeysDone,
-            app,
-            [&](const QJsonObject &) {
-                // Simulate user1 receiving and accepting the key
-                const auto encKey1 = QByteArray::fromBase64(suggestedKeys[0].encryptedKey.toUtf8());
-                const auto decKey1 = EncryptionUtils::decryptSessionKey(encKey1, EncryptionUtils::privateKeyFromPEM(user1KeyPair.privateKey));
-                QCOMPARE(decKey1, sessionKey);
-
-                const auto acceptMethod = new RocketChatRestApi::RestApiMethod;
-                acceptMethod->setServerUrl(url);
-                const auto acceptJob1 = new RocketChatRestApi::AcceptSuggestedGroupKeyJob(app);
-                acceptJob1->setRestApiMethod(acceptMethod);
-                acceptJob1->setNetworkAccessManager(networkManager);
-                acceptJob1->setRoomId(roomId);
-                QObject::connect(acceptJob1, &RocketChatRestApi::AcceptSuggestedGroupKeyJob::acceptSuggestedGroupKeyDone, app, [&](const QJsonObject &) {
-                    // Simulate user2 receiving and rejecting the key
-                    const auto encKey2 = QByteArray::fromBase64(suggestedKeys[1].encryptedKey.toUtf8());
-                    const auto decKey2 = EncryptionUtils::decryptSessionKey(encKey2, EncryptionUtils::privateKeyFromPEM(user2KeyPair.privateKey));
-                    QCOMPARE(decKey2, sessionKey);
-
-                    const auto rejectJob2 = new RocketChatRestApi::RejectSuggestedGroupKeyJob(app);
-                    const auto rejectMethod = new RocketChatRestApi::RestApiMethod;
-                    rejectMethod->setServerUrl(url);
-                    rejectJob2->setRestApiMethod(rejectMethod);
-                    rejectJob2->setNetworkAccessManager(networkManager);
-                    rejectJob2->setRoomId(roomId);
-                    QObject::connect(rejectJob2, &RocketChatRestApi::RejectSuggestedGroupKeyJob::rejectSuggestedGroupKeyDone, app, [&](const QJsonObject &) {
-                        testPassed = true;
-                        app->quit();
-                    });
-                    rejectJob2->start();
-                });
-                acceptJob1->start();
-            });
-        provideJob->start();
-    };
-
-    // Step 1a: Login and upload keys for user1
-    QObject::connect(loginManager0, &LoginManager::loginSucceeded, this, [&](const QString &authToken, const QString &userId) {
-        user1Id = userId;
-        user1Auth = authToken;
-        uploadKeys(authToken, url, userId, password, networkManager, [&](const QString &, const EncryptionUtils::RSAKeyPair &keypair) {
-            user1KeyPair = keypair;
-            proceed();
-        });
-    });
-    loginManager0->login(url, networkManager, 0);
-
-    // Step 1b: Login and upload keys for user2
-    QObject::connect(loginManager1, &LoginManager::loginSucceeded, this, [&](const QString &authToken, const QString &userId) {
-        user2Id = userId;
-        user2Auth = authToken;
-        uploadKeys(authToken, url, userId, password, networkManager, [&](const QString &, const EncryptionUtils::RSAKeyPair &keypair) {
-            user2KeyPair = keypair;
-            proceed();
-        });
-    });
-    loginManager1->login(url, networkManager, 1);
-
-    // Handle login failures
-    QObject::connect(loginManager0, &LoginManager::loginFailed, this, [=](const QString &err) {
-        QFAIL(qPrintable(QStringLiteral("User1 login failed: %1").arg(err)));
-        app->quit();
-    });
-    QObject::connect(loginManager1, &LoginManager::loginFailed, this, [=](const QString &err) {
-        QFAIL(qPrintable(QStringLiteral("User2 login failed: %1").arg(err)));
-        app->quit();
-    });
-
-    app->exec();
-    QVERIFY(testPassed);
-} */
-
 void SessionKeyDistributionTest::testJsonPayload()
 {
     RocketChatRestApi::ProvideUsersWithSuggestedGroupKeysJob job;
@@ -172,7 +51,7 @@ void SessionKeyDistributionTest::testCanStartValidation()
     job.setRoomId(QStringLiteral("room123"));
     QVERIFY(!job.canStart());
 
-    QVector<RocketChatRestApi::SuggestedGroupKey> keys = {{QStringLiteral("users"), QStringLiteral("base64keyA")}};
+    const QVector<RocketChatRestApi::SuggestedGroupKey> keys = {{QStringLiteral("users"), QStringLiteral("base64keyA")}};
     job.setKeys(keys);
     QVERIFY(job.canStart());
     delete restApiMethod;
diff --git a/src/core/autotests/sessionkeydistributiontest.h b/src/core/autotests/sessionkeydistributiontest.h
index 26c5117dc5..d969cdd26b 100644
--- a/src/core/autotests/sessionkeydistributiontest.h
+++ b/src/core/autotests/sessionkeydistributiontest.h
@@ -7,35 +7,6 @@
 #pragma once
 #include <QObject>
 
-/**
- * @class SessionKeyDistributionTest
- * @brief Autotest for Rocket.Chat E2EE session key distribution and acceptance/rejection flows.
- *
- * This test simulates two users in an end-to-end encrypted room:
- *
- * - User1:
- *   - Receives the suggested group (session) key.
- *   - Decrypts it with their private key.
- *   - Accepts it using AcceptSuggestedGroupKeyJob (acceptJob1).
- *
- * - User2:
- *   - Receives the suggested group (session) key.
- *   - Decrypts it with their private key.
- *   - Rejects it using RejectSuggestedGroupKeyJob (rejectJob2).
- *
- * The test verifies:
- *   - Correct encryption and decryption of the session key for both users.
- *   - Proper API communication for distributing, accepting, and rejecting session keys.
- *   - That only users with the correct private key can decrypt the session key.
- *   - That the session key is correctly assigned or rejected in the users’ room subscriptions.
- *
- *
- *  * Prerequisites:
- *
- *  - The .env file must contain credentials for at least two users (USERNAME1, PASSWORD1, USERNAME2, PASSWORD2).
- *
- *  - The test room must exist and be accessible by both users.
- */
 class SessionKeyDistributionTest : public QObject
 {
     Q_OBJECT
@@ -43,7 +14,6 @@ public:
     explicit SessionKeyDistributionTest(QObject *parent = nullptr);
     ~SessionKeyDistributionTest() override = default;
 private Q_SLOTS:
-    // void testSessionKeyDistribution();
     void testJsonPayload();
     void testCanStartValidation();
 };
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.