File indexing completed on 2025-03-09 04:54:26

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "dkimcheckauthenticationstatusjobtest.h"
0008 #include "dkim-verify/dkimauthenticationstatusinfo.h"
0009 #include "dkim-verify/dkimcheckauthenticationstatusjob.h"
0010 #include <KMime/Message>
0011 #include <QSignalSpy>
0012 #include <QTest>
0013 #include <QTimer>
0014 #include <chrono>
0015 
0016 using namespace std::chrono_literals;
0017 
0018 QTEST_MAIN(DKIMCheckAuthenticationStatusJobTest)
0019 
0020 DKIMCheckAuthenticationStatusJobTest::DKIMCheckAuthenticationStatusJobTest(QObject *parent)
0021     : QObject(parent)
0022 {
0023 }
0024 
0025 void DKIMCheckAuthenticationStatusJobTest::initTestCase()
0026 {
0027     qRegisterMetaType<MessageViewer::DKIMAuthenticationStatusInfo>();
0028 }
0029 
0030 void DKIMCheckAuthenticationStatusJobTest::shouldHaveDefaultValues()
0031 {
0032     MessageViewer::DKIMCheckAuthenticationStatusJob job;
0033     QVERIFY(!job.canStart());
0034     QVERIFY(!job.useRelaxedParsing());
0035 }
0036 
0037 void DKIMCheckAuthenticationStatusJobTest::shouldTestMail_data()
0038 {
0039     QTest::addColumn<QString>("fileName");
0040     QTest::addColumn<QString>("currentPath");
0041     QTest::addColumn<bool>("relaxedParsing");
0042     const QString curPath = QStringLiteral(DKIM_DATA_DIR "/");
0043 
0044     QTest::addRow("dkim2") << QStringLiteral("dkim2.mbox") << curPath << false;
0045     QTest::addRow("notsigned") << QStringLiteral("notsigned.mbox") << curPath << false;
0046     QTest::addRow("broken1") << QStringLiteral("broken1.mbox") << curPath << false;
0047 }
0048 
0049 void DKIMCheckAuthenticationStatusJobTest::shouldTestMail()
0050 {
0051     QFETCH(QString, fileName);
0052     QFETCH(QString, currentPath);
0053     QFETCH(bool, relaxedParsing);
0054     auto msg = new KMime::Message;
0055     QFile file(currentPath + fileName);
0056     QVERIFY(file.open(QIODevice::ReadOnly));
0057     msg->setContent(file.readAll());
0058     msg->parse();
0059 
0060     auto job = new MessageViewer::DKIMCheckAuthenticationStatusJob(this);
0061     MessageViewer::DKIMHeaderParser mHeaderParser;
0062     mHeaderParser.setHead(msg->head());
0063     mHeaderParser.parse();
0064     job->setHeaderParser(mHeaderParser);
0065     job->setUseRelaxedParsing(relaxedParsing);
0066     QSignalSpy dkimSignatureSpy(job, &MessageViewer::DKIMCheckAuthenticationStatusJob::result);
0067     QTimer::singleShot(10ms, job, &MessageViewer::DKIMCheckAuthenticationStatusJob::start);
0068     QVERIFY(dkimSignatureSpy.wait());
0069     delete msg;
0070 }
0071 
0072 #include "moc_dkimcheckauthenticationstatusjobtest.cpp"