AusweisApp2/test/qt/configuration/test_ProviderConfigurationP...

343 lines
11 KiB
C++
Raw Permalink Normal View History

2017-07-03 09:30:10 +02:00
/*!
2017-12-20 14:54:05 +01:00
* \brief Unit tests for \ref ProviderConfigurationParser
2017-07-03 09:30:10 +02:00
*
2019-05-22 10:08:38 +02:00
* \copyright Copyright (c) 2014-2019 Governikus GmbH & Co. KG, Germany
2017-07-03 09:30:10 +02:00
*/
2017-12-20 14:54:05 +01:00
#include "ProviderConfigurationParser.h"
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
#include "ResourceLoader.h"
2017-07-03 09:30:10 +02:00
#include "TestFileHelper.h"
2017-12-20 14:54:05 +01:00
#include <QtTest>
2017-07-03 09:30:10 +02:00
using namespace governikus;
2017-12-20 14:54:05 +01:00
2017-09-15 10:23:30 +02:00
Q_DECLARE_METATYPE(QLatin1String)
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
class test_ProviderConfigurationParser
2017-07-03 09:30:10 +02:00
: public QObject
{
Q_OBJECT
private Q_SLOTS:
2017-12-20 14:54:05 +01:00
void initTestCase()
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
ResourceLoader::getInstance().init();
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
void parseEmpty()
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
QByteArray data = QByteArray("{}");
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
QCOMPARE(ProviderConfigurationParser::parseCallCosts(data).size(), 0);
QCOMPARE(ProviderConfigurationParser::parseProvider(data).size(), 0);
2017-07-03 09:30:10 +02:00
}
void parseProviders()
{
QByteArray data = QByteArray("{"
" \"provider\": ["
" {"
" \"shortName\": {\"\" : \":::(bit)kasten\", \"de\" : \":::(bit)-de-kasten\", \"fr_FR\" : \":::(bit)-fr-kasten\"},"
" \"address\": \"https://www.bitkasten.de/\","
" \"phone\": \"\","
" \"email\": \"\","
" \"postaladdress\": \"\","
" \"category\": \"other\""
" },"
" {"
" \"shortName\": {\"\" : \"Allianz Kundenportal\"},"
" \"longName\": {\"\" : \"Allianz Kundenportal - Meine Allianz\"},"
" \"shortDescription\": {\"\" : \"Kundenportal von Allianz\"},"
" \"longDescription\": {\"\" : \"Kundenportal von Allianz - Meine Allianz\"},"
" \"address\": \"https://meine.allianz.de/form\","
" \"homepage\": \"https://meine.allianz.de\","
" \"phone\": \"0421 123456\","
" \"email\": \"abc@def.de\","
" \"postalAddress\": \"Am Fallturm 9,\n28359 Bremen\","
2017-12-20 14:54:05 +01:00
" \"category\": \"insurance\""
2017-07-03 09:30:10 +02:00
" }"
" ]"
"}");
2017-12-20 14:54:05 +01:00
const auto providers = ProviderConfigurationParser::parseProvider(data);
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
QCOMPARE(providers.size(), 2);
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
auto provider = providers[0];
2017-07-03 09:30:10 +02:00
QCOMPARE(provider.getShortName().toString(), QStringLiteral(":::(bit)kasten"));
LanguageLoader::getInstance().mUsedLocale = QLocale("om");
QCOMPARE(provider.getShortName().toString(), QStringLiteral(":::(bit)kasten"));
LanguageLoader::getInstance().mUsedLocale = QLocale("de");
QCOMPARE(provider.getShortName().toString(), QStringLiteral(":::(bit)-de-kasten"));
LanguageLoader::getInstance().mUsedLocale = QLocale("fr");
QCOMPARE(provider.getShortName().toString(), QStringLiteral(":::(bit)-fr-kasten"));
LanguageLoader::getInstance().mUsedLocale = QLocale("fr_FR");
QCOMPARE(provider.getShortName().toString(), QStringLiteral(":::(bit)-fr-kasten"));
QCOMPARE(provider.getLongName().toString(), QString());
QCOMPARE(provider.getShortDescription().toString(), QString());
QCOMPARE(provider.getLongDescription().toString(), QString());
QCOMPARE(provider.getAddress(), QStringLiteral("https://www.bitkasten.de/"));
QCOMPARE(provider.getHomepage(), QString());
QCOMPARE(provider.getPhone(), QString());
QCOMPARE(provider.getEMail(), QString());
QCOMPARE(provider.getPostalAddress(), QString());
QCOMPARE(provider.getCategory(), QStringLiteral("other"));
2017-12-20 14:54:05 +01:00
QVERIFY(provider.getIcon()->lookupPath().endsWith("/other_button.svg"));
QVERIFY(provider.getImage()->lookupPath().endsWith("/other_bg.svg"));
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
provider = providers[1];
2017-07-03 09:30:10 +02:00
QCOMPARE(provider.getShortName().toString(), QStringLiteral("Allianz Kundenportal"));
QCOMPARE(provider.getLongName().toString(), QStringLiteral("Allianz Kundenportal - Meine Allianz"));
QCOMPARE(provider.getShortDescription().toString(), QStringLiteral("Kundenportal von Allianz"));
QCOMPARE(provider.getLongDescription().toString(), QStringLiteral("Kundenportal von Allianz - Meine Allianz"));
QCOMPARE(provider.getAddress(), QStringLiteral("https://meine.allianz.de/form"));
QCOMPARE(provider.getHomepage(), QStringLiteral("https://meine.allianz.de"));
QCOMPARE(provider.getPhone(), QStringLiteral("0421 123456"));
QCOMPARE(provider.getEMail(), QStringLiteral("abc@def.de"));
QCOMPARE(provider.getPostalAddress(), QStringLiteral("Am Fallturm 9,\n28359 Bremen"));
QCOMPARE(provider.getCategory(), QStringLiteral("insurance"));
2017-12-20 14:54:05 +01:00
QVERIFY(provider.getIcon()->lookupPath().endsWith("/insurance_button.svg"));
QVERIFY(provider.getImage()->lookupPath().endsWith("/insurance_bg.svg"));
2017-07-03 09:30:10 +02:00
}
void parseAdditionalData()
{
QByteArray data = QByteArray("{"
" \"provider\": ["
" {"
" \"shortName\": {\"\" : \":::(bit)kasten\"},"
" \"address\": \"https://www.bitkasten.de/\","
" \"phone\": \"\","
" \"email\": \"\","
" \"postaladdress\": \"\","
" \"category\": \"other\","
" \"someNewProperty\": \"blabla\""
" }"
" ]"
"}");
2017-12-20 14:54:05 +01:00
const auto providers = ProviderConfigurationParser::parseProvider(data);
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
QCOMPARE(providers.size(), 1);
auto provider = providers[0];
2017-07-03 09:30:10 +02:00
QCOMPARE(provider.getShortName().toString(), QString(":::(bit)kasten"));
QCOMPARE(provider.getAddress(), QString("https://www.bitkasten.de/"));
QCOMPARE(provider.getPhone(), QString(""));
QCOMPARE(provider.getEMail(), QString(""));
QCOMPARE(provider.getPostalAddress(), QString(""));
QCOMPARE(provider.getCategory(), QString("other"));
}
2017-07-03 09:33:28 +02:00
void parseTcTokenUrl()
{
QByteArray data = QByteArray("{"
" \"provider\": ["
" {"
" },"
" {"
" \"tcTokenUrl\": \"https://npa.allianz.de/azservice/NpaEIDService/nparef/-wnf\""
" }"
" ]"
"}");
2017-12-20 14:54:05 +01:00
const auto providers = ProviderConfigurationParser::parseProvider(data);
2017-07-03 09:33:28 +02:00
2017-12-20 14:54:05 +01:00
QCOMPARE(providers.size(), 2);
2017-07-03 09:33:28 +02:00
2017-12-20 14:54:05 +01:00
auto provider = providers[0];
QCOMPARE(provider.getTcTokenUrl(), QUrl());
2017-07-03 09:33:28 +02:00
2017-12-20 14:54:05 +01:00
provider = providers[1];
QCOMPARE(provider.getTcTokenUrl(), QUrl(QStringLiteral("https://npa.allianz.de/azservice/NpaEIDService/nparef/-wnf")));
2017-07-03 09:33:28 +02:00
}
void parseClientUrl()
{
QByteArray data = QByteArray("{"
" \"provider\": ["
" {"
" },"
" {"
" \"clientUrl\": \"https://www.bva.bund.de/bafoeg-online/Bafoeg/flow/anmeld\""
" }"
" ]"
"}");
2017-12-20 14:54:05 +01:00
const auto providers = ProviderConfigurationParser::parseProvider(data);
2017-07-03 09:33:28 +02:00
2017-12-20 14:54:05 +01:00
QCOMPARE(providers.size(), 2);
2017-07-03 09:33:28 +02:00
2017-12-20 14:54:05 +01:00
auto provider = providers[0];
QCOMPARE(provider.getTcTokenUrl(), QUrl());
2017-07-03 09:33:28 +02:00
2017-12-20 14:54:05 +01:00
provider = providers[1];
QCOMPARE(provider.getClientUrl(), QUrl(QStringLiteral("https://www.bva.bund.de/bafoeg-online/Bafoeg/flow/anmeld")));
2017-07-03 09:33:28 +02:00
}
void parseSubjectUrls()
{
QByteArray data = QByteArray("{"
" \"provider\": ["
" {"
" },"
" {"
" \"subjectUrls\": []"
" },"
" {"
" \"subjectUrls\": [\"https://npa.allianz.de/bla1\"]"
" },"
" {"
" \"subjectUrls\": [\"https://npa.allianz.de/bla1\", \"https://npa.allianz.de/bla2\"]"
" }"
" ]"
"}");
2017-12-20 14:54:05 +01:00
const auto providers = ProviderConfigurationParser::parseProvider(data);
2017-07-03 09:33:28 +02:00
2017-12-20 14:54:05 +01:00
QCOMPARE(providers.size(), 4);
2017-07-03 09:33:28 +02:00
2017-12-20 14:54:05 +01:00
auto provider = providers[0];
2017-07-03 09:33:28 +02:00
QCOMPARE(provider.getSubjectUrls(), QStringList());
2017-12-20 14:54:05 +01:00
provider = providers[1];
2017-07-03 09:33:28 +02:00
QCOMPARE(provider.getSubjectUrls(), QStringList());
2017-12-20 14:54:05 +01:00
provider = providers[2];
2017-07-03 09:33:28 +02:00
QCOMPARE(provider.getSubjectUrls(), QStringList({QStringLiteral("https://npa.allianz.de/bla1")}));
2017-12-20 14:54:05 +01:00
provider = providers[3];
2017-07-03 09:33:28 +02:00
QCOMPARE(provider.getSubjectUrls(), QStringList({QStringLiteral("https://npa.allianz.de/bla1"), QStringLiteral("https://npa.allianz.de/bla2")}));
}
2017-07-03 09:30:10 +02:00
void defaultProviders()
{
2017-12-20 14:54:05 +01:00
QByteArray data = TestFileHelper::readFile(QStringLiteral(":/updatable-files/supported-providers.json"));
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
const auto providers = ProviderConfigurationParser::parseProvider(data);
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
QVERIFY(!providers.isEmpty());
2017-07-03 09:30:10 +02:00
}
2017-07-03 09:33:28 +02:00
void parseCallCosts()
{
2017-12-20 14:54:05 +01:00
QByteArray data = TestFileHelper::readFile(QStringLiteral(":/updatable-files/supported-providers.json"));
2017-07-03 09:33:28 +02:00
2017-12-20 14:54:05 +01:00
const auto callCosts = ProviderConfigurationParser::parseCallCosts(data);
2017-07-03 09:33:28 +02:00
2017-12-20 14:54:05 +01:00
QCOMPARE(callCosts.size(), 17);
2017-07-03 09:33:28 +02:00
}
2017-09-15 10:23:30 +02:00
void platformCount_data()
{
QTest::addColumn<int>("count");
2019-05-22 10:08:38 +02:00
const int desktop = 58;
2017-09-15 10:23:30 +02:00
QTest::newRow("win") << desktop;
QTest::newRow("mac") << desktop;
QTest::newRow("linux") << desktop;
2019-05-22 10:08:38 +02:00
QTest::newRow("android") << desktop;
2019-09-30 17:22:19 +02:00
QTest::newRow("ios") << 17;
2017-09-15 10:23:30 +02:00
}
void platformCount()
{
QFETCH(int, count);
2017-12-20 14:54:05 +01:00
QByteArray data = TestFileHelper::readFile(QStringLiteral(":/updatable-files/supported-providers.json"));
const auto providers = ProviderConfigurationParser::parseProvider(data, QLatin1String(QTest::currentDataTag()));
2017-09-15 10:23:30 +02:00
2017-12-20 14:54:05 +01:00
QCOMPARE(providers.size(), count);
2017-09-15 10:23:30 +02:00
}
void checkExcludedPlatform_data()
{
QTest::addColumn<QByteArray>("content");
QTest::addColumn<QLatin1String>("currentOS");
QTest::addColumn<bool>("excluded");
QTest::newRow("mobile")
<< QByteArray(R"( ["mobile"] )") << QLatin1String("android") << true;
QTest::newRow("android")
<< QByteArray(R"( ["mac", "android"] )") << QLatin1String("android") << true;
QTest::newRow("desktop_excluded_mac")
<< QByteArray(R"( ["android", "desktop"] )") << QLatin1String("mac") << true;
QTest::newRow("ios")
<< QByteArray(R"( ["android", "desktop"] )") << QLatin1String("ios") << false;
QTest::newRow("ios")
<< QByteArray(R"( ["android", "win"] )") << QLatin1String("ios") << false;
QTest::newRow("mobile_excluded")
<< QByteArray(R"( ["win", "mobile"] )") << QLatin1String("android") << true;
QTest::newRow("mobile_excluded")
<< QByteArray(R"( ["mobile", "win"] )") << QLatin1String("ios") << true;
QTest::newRow("win_excluded")
<< QByteArray(R"( ["win"] )") << QLatin1String("win") << true;
QTest::newRow("desktop_excluded_single")
<< QByteArray(R"( ["desktop"] )") << QLatin1String("win") << true;
QTest::newRow("win")
<< QByteArray(R"( ["mac", "bla", "bsd", "linux", "mobile", "ios", "android"] )") << QLatin1String("win") << false;
QTest::newRow("desktop_excluded_multi")
<< QByteArray(R"( ["mac", "bla", "bsd", "linux", "desktop", "ios", "android"] )") << QLatin1String("win") << true;
QTest::newRow("win_excluded")
<< QByteArray(R"( ["mac", "bla", "dummy", "win"] )") << QLatin1String("win") << true;
QTest::newRow("nothing")
<< QByteArray(R"( [] )") << QLatin1String("win") << false;
}
void checkExcludedPlatform()
{
QFETCH(QByteArray, content);
QFETCH(QLatin1String, currentOS);
QFETCH(bool, excluded);
const auto& doc = QJsonDocument::fromJson(content);
QVERIFY(!doc.isNull());
2017-12-20 14:54:05 +01:00
QCOMPARE(ProviderConfigurationParser::isExcludedPlatform(doc.array(), currentOS), excluded);
2017-09-15 10:23:30 +02:00
}
void checkExcludedPlatformEmpty()
{
2017-12-20 14:54:05 +01:00
QCOMPARE(ProviderConfigurationParser::isExcludedPlatform(QJsonArray(), QLatin1String("ios")), false);
2017-09-15 10:23:30 +02:00
}
2017-07-03 09:30:10 +02:00
};
2017-12-20 14:54:05 +01:00
QTEST_GUILESS_MAIN(test_ProviderConfigurationParser)
#include "test_ProviderConfigurationParser.moc"