summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-16 20:16:59 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-16 20:16:59 (GMT)
commit195019a3cea52eb8bcf6a929a0daed86355e647b (patch)
tree9637201dec4588d51bd097b9b43b08119f023043
parent3765adbcf236cd76c33889c8632e6dab8aead4ac (diff)
Improve test
-rw-r--r--webengineviewer/src/checkphishingurl/autotests/createphishingurldatabasejobtest.cpp31
-rw-r--r--webengineviewer/src/checkphishingurl/autotests/createphishingurldatabasejobtest.h4
-rw-r--r--webengineviewer/src/checkphishingurl/autotests/data/empty.json2
-rw-r--r--webengineviewer/src/checkphishingurl/autotests/data/empty2.json0
-rw-r--r--webengineviewer/src/checkphishingurl/autotests/data/test1.json26
-rw-r--r--webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp4
-rw-r--r--webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h23
7 files changed, 85 insertions, 5 deletions
diff --git a/webengineviewer/src/checkphishingurl/autotests/createphishingurldatabasejobtest.cpp b/webengineviewer/src/checkphishingurl/autotests/createphishingurldatabasejobtest.cpp
index ae25f5c..0e8876e 100644
--- a/webengineviewer/src/checkphishingurl/autotests/createphishingurldatabasejobtest.cpp
+++ b/webengineviewer/src/checkphishingurl/autotests/createphishingurldatabasejobtest.cpp
@@ -20,6 +20,7 @@
#include "createphishingurldatabasejobtest.h"
#include "../createphishingurldatabasejob.h"
+#include <QSignalSpy>
#include <QTest>
QByteArray readJsonFile(const QString &jsonFile)
@@ -44,6 +45,12 @@ CreatePhishingUrlDataBaseJobTest::~CreatePhishingUrlDataBaseJobTest()
}
+void CreatePhishingUrlDataBaseJobTest::initTestcase()
+{
+ qRegisterMetaType<WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult>();
+ qRegisterMetaType<WebEngineViewer::UpdateDataBaseInfo>();
+}
+
void CreatePhishingUrlDataBaseJobTest::shouldCreateRequest_data()
{
QTest::addColumn<QString>("databasestate");
@@ -68,5 +75,29 @@ void CreatePhishingUrlDataBaseJobTest::shouldCreateRequest()
QCOMPARE(job.jsonRequest(), request);
}
+void CreatePhishingUrlDataBaseJobTest::shouldParseResult_data()
+{
+ QTest::addColumn<QString>("filename");
+ QTest::addColumn<WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult>("parseResult");
+ QTest::addColumn<WebEngineViewer::UpdateDataBaseInfo>("parseInfo");
+ QTest::newRow("emptydocument") << QStringLiteral("empty.json") << WebEngineViewer::CreatePhishingUrlDataBaseJob::InvalidData << WebEngineViewer::UpdateDataBaseInfo();
+ QTest::newRow("emptydocument2") << QStringLiteral("empty2.json") << WebEngineViewer::CreatePhishingUrlDataBaseJob::InvalidData << WebEngineViewer::UpdateDataBaseInfo();
+ //QTest::newRow("test1") << QStringLiteral("test1.json") << WebEngineViewer::CreatePhishingUrlDataBaseJob::ValidData << WebEngineViewer::UpdateDataBaseInfo();
+}
+
+void CreatePhishingUrlDataBaseJobTest::shouldParseResult()
+{
+ QFETCH (QString, filename);
+ QFETCH(WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult, parseResult);
+ QFETCH(WebEngineViewer::UpdateDataBaseInfo, parseInfo);
+ const QByteArray ba = readJsonFile(filename);
+ WebEngineViewer::CreatePhishingUrlDataBaseJob job;
+ QSignalSpy spy1(&job, SIGNAL(finished(WebEngineViewer::UpdateDataBaseInfo,WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult)));
+ job.parseResult(ba);
+ QCOMPARE(spy1.count(), 1);
+ QCOMPARE(spy1.at(0).at(1).value<WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult>(), parseResult);
+ QCOMPARE(spy1.at(0).at(0).value<WebEngineViewer::UpdateDataBaseInfo>(), parseInfo);
+}
+
QTEST_MAIN(CreatePhishingUrlDataBaseJobTest)
diff --git a/webengineviewer/src/checkphishingurl/autotests/createphishingurldatabasejobtest.h b/webengineviewer/src/checkphishingurl/autotests/createphishingurldatabasejobtest.h
index fbf1ca7..a3c9908 100644
--- a/webengineviewer/src/checkphishingurl/autotests/createphishingurldatabasejobtest.h
+++ b/webengineviewer/src/checkphishingurl/autotests/createphishingurldatabasejobtest.h
@@ -31,6 +31,10 @@ public:
private Q_SLOTS:
void shouldCreateRequest_data();
void shouldCreateRequest();
+
+ void shouldParseResult_data();
+ void shouldParseResult();
+ void initTestcase();
};
#endif // CREATEPHISHINGURLDATABASEJOBTEST_H
diff --git a/webengineviewer/src/checkphishingurl/autotests/data/empty.json b/webengineviewer/src/checkphishingurl/autotests/data/empty.json
new file mode 100644
index 0000000..2c63c08
--- /dev/null
+++ b/webengineviewer/src/checkphishingurl/autotests/data/empty.json
@@ -0,0 +1,2 @@
+{
+}
diff --git a/webengineviewer/src/checkphishingurl/autotests/data/empty2.json b/webengineviewer/src/checkphishingurl/autotests/data/empty2.json
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/webengineviewer/src/checkphishingurl/autotests/data/empty2.json
diff --git a/webengineviewer/src/checkphishingurl/autotests/data/test1.json b/webengineviewer/src/checkphishingurl/autotests/data/test1.json
new file mode 100644
index 0000000..3ddbf54
--- /dev/null
+++ b/webengineviewer/src/checkphishingurl/autotests/data/test1.json
@@ -0,0 +1,26 @@
+{
+ "listUpdateResponses": [{
+ "threatType": "MALWARE",
+ "threatEntryType": "URL",
+ "platformType": "WINDOWS",
+ "responseType" : "PARTIAL_UPDATE",
+ "additions": [{
+ "compressionType": "RAW",
+ "rawHashes": {
+ "prefixSize": 4,
+ "rawHashes": "rnGLoQ=="
+ }
+ }],
+ "removals": [{
+ "compressionType": "RAW",
+ "rawIndices": {
+ "indices": [0, 2, 4]
+ }
+ }],
+ "newClientState": "ChAIBRADGAEiAzAwMSiAEDABEAFGpqhd",
+ "checksum": {
+ "sha256": "YSgoRtsRlgHDqDA3LAhM1gegEpEzs1TjzU33vqsR8iM="
+ }
+ }],
+ "minimumWaitDuration": "593.440s"
+}
diff --git a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp
index f8d8c0d..4948608 100644
--- a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp
+++ b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp
@@ -145,7 +145,6 @@ QByteArray CreatePhishingUrlDataBaseJob::jsonRequest() const
const QJsonDocument postData = QJsonDocument::fromVariant(map);
const QByteArray baPostData = postData.toJson(mUseCompactJson ? QJsonDocument::Compact : QJsonDocument::Indented);
- //qDebug()<<" baPostData "<<baPostData;
return baPostData;
}
@@ -267,7 +266,6 @@ void CreatePhishingUrlDataBaseJob::parseResult(const QByteArray &value)
if (!addList.isEmpty()) {
databaseInfo.additionList.append(addList);
}
-
} else if (mapKey == QLatin1String("removals")) {
qDebug() << " removals items " << mapIt.value().typeName();
const QVariantList lst = mapIt.value().toList();
@@ -275,7 +273,6 @@ void CreatePhishingUrlDataBaseJob::parseResult(const QByteArray &value)
if (!removeList.isEmpty()) {
databaseInfo.removalList.append(removeList);
}
-
} else if (mapKey == QLatin1String("checksum")) {
QMapIterator<QString, QVariant> mapCheckSum(mapIt.value().toMap());
while (mapCheckSum.hasNext()) {
@@ -305,7 +302,6 @@ void CreatePhishingUrlDataBaseJob::parseResult(const QByteArray &value)
} else {
qDebug() << " unknow key " << mapKey;
}
-
}
}
}
diff --git a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h
index 6dd4d59..7977e5c 100644
--- a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h
+++ b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h
@@ -38,6 +38,10 @@ struct Addition {
bool isValid() const {
return !hashString.isEmpty() && (prefixSize > 0);
}
+ bool operator==(const Addition &other) const {
+ return (hashString == other.hashString) &&
+ (prefixSize == other.prefixSize);
+ }
QByteArray hashString;
int prefixSize;
@@ -48,6 +52,10 @@ struct Removal {
{
}
+
+ bool operator==(const Removal &other) const {
+ return (indexes == other.indexes);
+ }
bool isValid() const {
return !indexes.isEmpty();
}
@@ -64,6 +72,17 @@ struct UpdateDataBaseInfo {
QString platformType;
QString newClientState;
QString sha256;
+ bool operator==(const UpdateDataBaseInfo &other) const {
+ return (additionList == other.additionList) &&
+ (removalList == other.removalList) &&
+ (minimumWaitDuration == other.minimumWaitDuration) &&
+ (threatType == other.threatType) &&
+ (threatEntryType == other.threatEntryType) &&
+ (responseType == other.responseType) &&
+ (platformType == other.platformType) &&
+ (newClientState == other.newClientState) &&
+ (sha256 == other.sha256);
+ }
};
/* https://developers.google.com/safe-browsing/v4/update-api */
@@ -95,6 +114,7 @@ public:
QByteArray jsonRequest() const;
void setUseCompactJson(bool useCompactJson);
+ void parseResult(const QByteArray &value);
Q_SIGNALS:
void finished(const WebEngineViewer::UpdateDataBaseInfo &infoDataBase, WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult status);
@@ -106,7 +126,6 @@ private:
void slotDownloadDataBaseFinished(QNetworkReply *reply);
void slotSslErrors(QNetworkReply *reply, const QList<QSslError> &error);
void slotError(QNetworkReply::NetworkError error);
- void parseResult(const QByteArray &value);
QVector<Removal> parseRemovals(const QVariantList &lst);
QVector<Addition> parseAdditions(const QVariantList &lst);
@@ -117,6 +136,8 @@ private:
};
}
Q_DECLARE_METATYPE(WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownload)
+Q_DECLARE_METATYPE(WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult)
+Q_DECLARE_METATYPE(WebEngineViewer::UpdateDataBaseInfo)
Q_DECLARE_TYPEINFO(WebEngineViewer::Addition, Q_MOVABLE_TYPE);
Q_DECLARE_TYPEINFO(WebEngineViewer::Removal, Q_MOVABLE_TYPE);
#endif // CREATEPHISHINGURLDATABASEJOB_H