File indexing completed on 2025-02-02 04:51:28
0001 /* 0002 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "resettotpjobtest.h" 0008 #include "restapimethod.h" 0009 #include "users/resettotpjob.h" 0010 #include <QJsonDocument> 0011 #include <QTest> 0012 QTEST_GUILESS_MAIN(ResetTOTPJobTest) 0013 using namespace RocketChatRestApi; 0014 ResetTOTPJobTest::ResetTOTPJobTest(QObject *parent) 0015 : QObject(parent) 0016 { 0017 } 0018 0019 void ResetTOTPJobTest::shouldHaveDefaultValue() 0020 { 0021 ResetTOTPJob job; 0022 QVERIFY(!job.restApiMethod()); 0023 QVERIFY(!job.networkAccessManager()); 0024 QVERIFY(!job.start()); 0025 QVERIFY(job.requireHttpAuthentication()); 0026 QVERIFY(!job.restApiLogger()); 0027 QVERIFY(!job.hasQueryParameterSupport()); 0028 QVERIFY(job.requireTwoFactorAuthentication()); 0029 QVERIFY(job.resetUserId().isEmpty()); 0030 } 0031 0032 void ResetTOTPJobTest::shouldGenerateRequest() 0033 { 0034 ResetTOTPJob job; 0035 RestApiMethod method; 0036 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0037 job.setRestApiMethod(&method); 0038 const QNetworkRequest request = job.request(); 0039 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.resetTOTP"))); 0040 } 0041 0042 void ResetTOTPJobTest::shouldGenerateJson() 0043 { 0044 ResetTOTPJob job; 0045 const QString resetUserId = QStringLiteral("foo"); 0046 job.setResetUserId(resetUserId); 0047 QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral(R"({"userId":"%1"})").arg(resetUserId).toLatin1()); 0048 } 0049 0050 void ResetTOTPJobTest::shouldNotStarting() 0051 { 0052 ResetTOTPJob job; 0053 0054 RestApiMethod method; 0055 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0056 job.setRestApiMethod(&method); 0057 0058 QNetworkAccessManager mNetworkAccessManager; 0059 job.setNetworkAccessManager(&mNetworkAccessManager); 0060 QVERIFY(!job.canStart()); 0061 const QString auth = QStringLiteral("foo"); 0062 const QString userId = QStringLiteral("foo"); 0063 job.setAuthToken(auth); 0064 QVERIFY(!job.canStart()); 0065 job.setUserId(userId); 0066 QVERIFY(!job.canStart()); 0067 0068 job.setResetUserId(QStringLiteral("ss")); 0069 QVERIFY(!job.canStart()); 0070 0071 job.setAuthCode(QStringLiteral("bla")); 0072 QVERIFY(!job.canStart()); 0073 0074 job.setAuthMethod(QStringLiteral("method")); 0075 QVERIFY(job.canStart()); 0076 } 0077 0078 #include "moc_resettotpjobtest.cpp"