• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.14
  • kdepim
  • kmail
  • editor
  • potentialphishingemail
  • autotests
potentialphishingemailjobtest.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015 Montel Laurent <montel@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 
19 */
20 
21 #include "potentialphishingemailjobtest.h"
22 #include "../potentialphishingemailjob.h"
23 #include <qtest_kde.h>
24 #include <QStringList>
25 #include <QSignalSpy>
26 
27 PotentialPhishingEmailJobTest::PotentialPhishingEmailJobTest(QObject *parent)
28  : QObject(parent)
29 {
30 
31 }
32 
33 PotentialPhishingEmailJobTest::~PotentialPhishingEmailJobTest()
34 {
35 
36 }
37 
38 void PotentialPhishingEmailJobTest::shouldNotStartIfNoEmails()
39 {
40  PotentialPhishingEmailJob *job = new PotentialPhishingEmailJob;
41  QVERIFY(!job->start());
42  QVERIFY(job->potentialPhisingEmails().isEmpty());
43 }
44 
45 void PotentialPhishingEmailJobTest::shouldReturnPotentialPhishingEmails_data()
46 {
47  QTest::addColumn<QStringList>("listEmails");
48  QTest::addColumn<QStringList>("whiteListEmail");
49  QTest::addColumn<bool>("hasPotentialPhishing");
50  QTest::newRow("NoPotentialPhishing") << (QStringList() << QLatin1String("foo@kde.org")) << QStringList() << false;
51  QTest::newRow("HasPotentialPhishing") << (QStringList() << QLatin1String("\"bla@kde.org\" <foo@kde.org>")) << QStringList() << true;
52  const QString email = QLatin1String("\"bla@kde.org\" <foo@kde.org>");
53  QTest::newRow("EmailInWhiteList") << (QStringList() << email) << (QStringList() << email) << false;
54  QTest::newRow("NotAllEmailInWhiteList") << (QStringList() << email << QLatin1String("\"c@kde.org\" <dd@kde.org>")) << (QStringList() << email) << true;
55  QTest::newRow("EmailInWhiteListWithSpace") << (QStringList() << QLatin1String(" \"bla@kde.org\" <foo@kde.org> ")) << (QStringList() << email) << false;
56  QTest::newRow("EmailWithSameNameAndDisplayName") << (QStringList() << QLatin1String("\"<foo@kde.com>\" <foo@kde.com>")) << (QStringList() << email) << false;
57  QTest::newRow("EmailWithSameNameAndDisplayNameWithSpace") << (QStringList() << QLatin1String(" \"<foo@kde.com>\" <foo@kde.com> ")) << (QStringList() << email) << false;
58 
59  QTest::newRow("notsamecase") << (QStringList() << QLatin1String("\"Foo@kde.org\" <foo@kde.org>")) << QStringList() << false;
60  QTest::newRow("notsamecaseaddress") << (QStringList() << QLatin1String("\"Foo@kde.org\" <FOO@kde.ORG>")) << QStringList() << false;
61 
62  QTest::newRow("emailinparenthese") << (QStringList() << QLatin1String("\"bla (Foo@kde.org)\" <FOO@kde.ORG>")) << QStringList() << false;
63  QTest::newRow("notemailinparenthese") << (QStringList() << QLatin1String("\"bla (bli@kde.org)\" <FOO@kde.ORG>")) << QStringList() << true;
64  QTest::newRow("erroremailinparenthese") << (QStringList() << QLatin1String("\"bla Foo@kde.org\" <FOO@kde.ORG>")) << QStringList() << true;
65 }
66 
67 void PotentialPhishingEmailJobTest::shouldReturnPotentialPhishingEmails()
68 {
69  QFETCH( QStringList, listEmails );
70  QFETCH( QStringList,whiteListEmail );
71  QFETCH( bool, hasPotentialPhishing );
72 
73  PotentialPhishingEmailJob *job = new PotentialPhishingEmailJob;
74  job->setEmailWhiteList(whiteListEmail);
75  job->setEmails(listEmails);
76  QVERIFY(job->start());
77  QCOMPARE(job->potentialPhisingEmails().isEmpty(), !hasPotentialPhishing);
78 }
79 
80 void PotentialPhishingEmailJobTest::shouldEmitSignal()
81 {
82  PotentialPhishingEmailJob *job = new PotentialPhishingEmailJob;
83  QSignalSpy spy(job, SIGNAL(potentialPhishingEmailsFound(QStringList)));
84  job->setEmails((QStringList() << QLatin1String("\"bla@kde.org\" <foo@kde.org>")));
85  job->start();
86  QCOMPARE(spy.count(), 1);
87 }
88 
89 
90 QTEST_KDEMAIN(PotentialPhishingEmailJobTest, NoGUI)
PotentialPhishingEmailJob::potentialPhisingEmails
QStringList potentialPhisingEmails() const
Definition: potentialphishingemailjob.cpp:45
email
const QString email
Definition: identitydialog.cpp:640
PotentialPhishingEmailJob::start
bool start()
Definition: potentialphishingemailjob.cpp:50
PotentialPhishingEmailJob
Definition: potentialphishingemailjob.h:27
PotentialPhishingEmailJob::setEmailWhiteList
void setEmailWhiteList(const QStringList &emails)
Definition: potentialphishingemailjob.cpp:35
potentialphishingemailjobtest.h
QObject
QList::isEmpty
bool isEmpty() const
QSignalSpy
QString
QStringList
PotentialPhishingEmailJob::setEmails
void setEmails(const QStringList &emails)
Definition: potentialphishingemailjob.cpp:40
QTest::newRow
QTestData & newRow(const char *dataTag)
QLatin1String
PotentialPhishingEmailJobTest::PotentialPhishingEmailJobTest
PotentialPhishingEmailJobTest(QObject *parent=0)
Definition: potentialphishingemailjobtest.cpp:27
PotentialPhishingEmailJobTest::~PotentialPhishingEmailJobTest
~PotentialPhishingEmailJobTest()
Definition: potentialphishingemailjobtest.cpp:33
PotentialPhishingEmailJobTest
Definition: potentialphishingemailjobtest.h:26
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal