2017-07-03 09:33:28 +02:00
|
|
|
/*!
|
|
|
|
* \brief Unit tests for \ref UIPlugInWebSocket
|
|
|
|
*
|
2019-05-22 10:08:38 +02:00
|
|
|
* \copyright Copyright (c) 2016-2019 Governikus GmbH & Co. KG, Germany
|
2017-07-03 09:33:28 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "UIPlugInWebSocket.h"
|
2019-01-03 15:06:22 +01:00
|
|
|
|
|
|
|
#include "PortFile.h"
|
2017-07-03 09:33:28 +02:00
|
|
|
#include "WebSocketHelper.h"
|
|
|
|
|
2017-09-15 10:23:30 +02:00
|
|
|
#include <climits>
|
2017-07-03 09:33:28 +02:00
|
|
|
#include <QFile>
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
|
|
|
using namespace governikus;
|
|
|
|
|
|
|
|
|
|
|
|
class test_UIPlugInWebSocket
|
|
|
|
: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const int PROCESS_TIMEOUT = 15000;
|
|
|
|
|
|
|
|
QScopedPointer<QProcess> mApp2;
|
|
|
|
QScopedPointer<QWebSocket> mWebSocket;
|
|
|
|
QScopedPointer<WebSocketHelper> mHelper;
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase()
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
QSKIP("Not supported");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void init()
|
|
|
|
{
|
|
|
|
qRegisterMetaType<QProcess::ProcessState>("QProcess::ProcessState");
|
|
|
|
|
|
|
|
QString path = QCoreApplication::applicationDirPath() + "/../../src/";
|
|
|
|
QString app = path + "AusweisApp2";
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
app += ".exe";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QStringList args;
|
|
|
|
args << "--ui" << "websocket";
|
|
|
|
args << "--port" << "0";
|
|
|
|
#ifndef Q_OS_WIN
|
|
|
|
args << "-platform" << "offscreen";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mApp2.reset(new QProcess());
|
|
|
|
mApp2->setProgram(app);
|
|
|
|
mApp2->setWorkingDirectory(path);
|
|
|
|
mApp2->setArguments(args);
|
|
|
|
|
|
|
|
mApp2->start();
|
|
|
|
mApp2->waitForStarted(PROCESS_TIMEOUT);
|
|
|
|
QCOMPARE(mApp2->state(), QProcess::Running);
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
QFile portInfoFile(PortFile::getPortFilename(QString(), mApp2->processId(), QStringLiteral("AusweisApp2")));
|
|
|
|
QTRY_COMPARE_WITH_TIMEOUT(portInfoFile.exists(), true, PROCESS_TIMEOUT);
|
2017-07-03 09:33:28 +02:00
|
|
|
QVERIFY(portInfoFile.open(QIODevice::ReadOnly));
|
|
|
|
|
|
|
|
quint16 webSocketPort = 0;
|
|
|
|
QTextStream(&portInfoFile) >> webSocketPort;
|
|
|
|
QVERIFY(webSocketPort > 0);
|
|
|
|
|
|
|
|
mHelper.reset(new WebSocketHelper(webSocketPort));
|
|
|
|
QCOMPARE(mHelper->getState(), QAbstractSocket::SocketState::ConnectedState);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cleanup()
|
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
const QString portFile = PortFile::getPortFilename(QString(), mApp2->processId(), QStringLiteral("AusweisApp2"));
|
|
|
|
QVERIFY(QFile::exists(portFile));
|
2017-07-03 09:33:28 +02:00
|
|
|
mHelper.reset();
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
QCOMPARE(mApp2->state(), QProcess::Running);
|
|
|
|
|
2017-07-03 09:33:28 +02:00
|
|
|
mApp2->terminate();
|
|
|
|
mApp2->waitForFinished(PROCESS_TIMEOUT);
|
|
|
|
|
|
|
|
if (mApp2->state() != QProcess::NotRunning)
|
|
|
|
{
|
|
|
|
mApp2->kill();
|
|
|
|
}
|
2019-01-03 15:06:22 +01:00
|
|
|
QCOMPARE(mApp2->state(), QProcess::NotRunning);
|
|
|
|
|
|
|
|
if (mApp2->exitCode() != 0)
|
|
|
|
{
|
|
|
|
qDebug().noquote() << "Error output from AusweisApp2 process:\n" << mApp2->readAllStandardError();
|
|
|
|
}
|
|
|
|
QCOMPARE(mApp2->exitCode(), 0);
|
|
|
|
QVERIFY(!QFile::exists(portFile));
|
2017-07-03 09:33:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void runAndStop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void getInfoAndApiLevel()
|
|
|
|
{
|
|
|
|
mHelper->sendMessage("{\"cmd\": \"GET_INFO\"}");
|
|
|
|
QVERIFY(mHelper->waitForMessage([](const QJsonObject& pMessage){
|
|
|
|
return pMessage["msg"] == "INFO" &&
|
|
|
|
pMessage["VersionInfo"].toObject()["Name"] == "AusweisApp2";
|
|
|
|
}));
|
|
|
|
|
|
|
|
mHelper->sendMessage("{\"cmd\": \"GET_API_LEVEL\"}");
|
|
|
|
QVERIFY(mHelper->waitForMessage([](const QJsonObject& pMessage){
|
|
|
|
return pMessage["msg"] == "API_LEVEL" &&
|
|
|
|
pMessage["available"].toArray().size() >= 1;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tryLocalhostAuth()
|
|
|
|
{
|
2017-12-20 14:54:05 +01:00
|
|
|
#ifdef Q_OS_FREEBSD
|
|
|
|
QSKIP("Not supported");
|
|
|
|
#endif
|
|
|
|
|
2017-07-03 09:33:28 +02:00
|
|
|
mHelper->sendMessage("{\"cmd\": \"RUN_AUTH\", \"tcTokenURL\" : \"https://localhost/\"}");
|
|
|
|
QVERIFY(mHelper->waitForMessage([](const QJsonObject& pMessage){
|
|
|
|
return pMessage["msg"] == "AUTH";
|
|
|
|
}));
|
|
|
|
|
|
|
|
QVERIFY(mHelper->waitForMessage([](const QJsonObject& pMessage){
|
|
|
|
return pMessage["result"].toObject()["major"].toString().endsWith("#error");
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(test_UIPlugInWebSocket)
|
|
|
|
#include "test_UIPlugInWebSocket.moc"
|