Add tcp/ssl socket server and prepare tests

This commit is contained in:
Simon Stürz 2019-06-07 16:31:59 +02:00 committed by Simon Stürz
parent deaec8be40
commit 8fff4c6685
15 changed files with 210 additions and 78 deletions

View File

@ -73,19 +73,31 @@ void Engine::start(ProxyConfiguration *configuration)
m_proxyServer = new ProxyServer(this); m_proxyServer = new ProxyServer(this);
m_webSocketServer = new WebSocketServer(m_configuration->sslEnabled(), m_configuration->sslConfiguration(), this); m_webSocketServer = new WebSocketServer(m_configuration->sslEnabled(), m_configuration->sslConfiguration(), this);
m_tcpSocketServer = new TcpSocketServer(m_configuration->sslEnabled(), m_configuration->sslConfiguration(), this);
// Configure websocket server
QUrl websocketServerUrl; QUrl websocketServerUrl;
websocketServerUrl.setScheme(m_configuration->sslEnabled() ? "wss" : "ws"); websocketServerUrl.setScheme(m_configuration->sslEnabled() ? "wss" : "ws");
websocketServerUrl.setHost(m_configuration->webSocketServerHost().toString()); websocketServerUrl.setHost(m_configuration->webSocketServerHost().toString());
websocketServerUrl.setPort(m_configuration->webSocketServerPort()); websocketServerUrl.setPort(m_configuration->webSocketServerPort());
m_webSocketServer->setServerUrl(websocketServerUrl); m_webSocketServer->setServerUrl(websocketServerUrl);
m_proxyServer->registerTransportInterface(m_webSocketServer); // Configure tcp socket server
QUrl tcpSocketServerUrl;
tcpSocketServerUrl.setScheme(m_configuration->sslEnabled() ? "ssl" : "tcp");
tcpSocketServerUrl.setHost(m_configuration->tcpServerHost().toString());
tcpSocketServerUrl.setPort(m_configuration->tcpServerPort());
m_tcpSocketServer->setServerUrl(tcpSocketServerUrl);
// Register the transport interfaces in the proxy server
m_proxyServer->registerTransportInterface(m_webSocketServer);
m_proxyServer->registerTransportInterface(m_tcpSocketServer);
// Start the server
qCDebug(dcEngine()) << "Starting proxy server"; qCDebug(dcEngine()) << "Starting proxy server";
m_proxyServer->startServer(); m_proxyServer->startServer();
// Start the monitor server
m_monitorServer = new MonitorServer(configuration->monitorSocketFileName(), this); m_monitorServer = new MonitorServer(configuration->monitorSocketFileName(), this);
m_monitorServer->startServer(); m_monitorServer->startServer();
@ -153,6 +165,11 @@ ProxyServer *Engine::proxyServer() const
return m_proxyServer; return m_proxyServer;
} }
TcpSocketServer *Engine::tcpSocketServer() const
{
return m_tcpSocketServer;
}
WebSocketServer *Engine::webSocketServer() const WebSocketServer *Engine::webSocketServer() const
{ {
return m_webSocketServer; return m_webSocketServer;

View File

@ -38,6 +38,7 @@
#include "logengine.h" #include "logengine.h"
#include "proxyserver.h" #include "proxyserver.h"
#include "monitorserver.h" #include "monitorserver.h"
#include "tcpsocketserver.h"
#include "websocketserver.h" #include "websocketserver.h"
#include "proxyconfiguration.h" #include "proxyconfiguration.h"
#include "authentication/authenticator.h" #include "authentication/authenticator.h"
@ -67,6 +68,7 @@ public:
ProxyConfiguration *configuration() const; ProxyConfiguration *configuration() const;
Authenticator *authenticator() const; Authenticator *authenticator() const;
ProxyServer *proxyServer() const; ProxyServer *proxyServer() const;
TcpSocketServer *tcpSocketServer() const;
WebSocketServer *webSocketServer() const; WebSocketServer *webSocketServer() const;
MonitorServer *monitorServer() const; MonitorServer *monitorServer() const;
LogEngine *logEngine() const; LogEngine *logEngine() const;
@ -88,6 +90,7 @@ private:
ProxyConfiguration *m_configuration = nullptr; ProxyConfiguration *m_configuration = nullptr;
Authenticator *m_authenticator = nullptr; Authenticator *m_authenticator = nullptr;
ProxyServer *m_proxyServer = nullptr; ProxyServer *m_proxyServer = nullptr;
TcpSocketServer *m_tcpSocketServer = nullptr;
WebSocketServer *m_webSocketServer = nullptr; WebSocketServer *m_webSocketServer = nullptr;
MonitorServer *m_monitorServer = nullptr; MonitorServer *m_monitorServer = nullptr;
LogEngine *m_logEngine = nullptr; LogEngine *m_logEngine = nullptr;

View File

@ -32,6 +32,8 @@ Q_LOGGING_CATEGORY(dcEngine, "Engine")
Q_LOGGING_CATEGORY(dcJsonRpc, "JsonRpc") Q_LOGGING_CATEGORY(dcJsonRpc, "JsonRpc")
Q_LOGGING_CATEGORY(dcTunnel, "Tunnel") Q_LOGGING_CATEGORY(dcTunnel, "Tunnel")
Q_LOGGING_CATEGORY(dcJsonRpcTraffic, "JsonRpcTraffic") Q_LOGGING_CATEGORY(dcJsonRpcTraffic, "JsonRpcTraffic")
Q_LOGGING_CATEGORY(dcTcpSocketServer, "TcpSocketServer")
Q_LOGGING_CATEGORY(dcTcpSocketServerTraffic, "TcpSocketServerTraffic")
Q_LOGGING_CATEGORY(dcWebSocketServer, "WebSocketServer") Q_LOGGING_CATEGORY(dcWebSocketServer, "WebSocketServer")
Q_LOGGING_CATEGORY(dcWebSocketServerTraffic, "WebSocketServerTraffic") Q_LOGGING_CATEGORY(dcWebSocketServerTraffic, "WebSocketServerTraffic")
Q_LOGGING_CATEGORY(dcAuthentication, "Authentication") Q_LOGGING_CATEGORY(dcAuthentication, "Authentication")

View File

@ -38,6 +38,8 @@ Q_DECLARE_LOGGING_CATEGORY(dcTunnel)
Q_DECLARE_LOGGING_CATEGORY(dcJsonRpcTraffic) Q_DECLARE_LOGGING_CATEGORY(dcJsonRpcTraffic)
Q_DECLARE_LOGGING_CATEGORY(dcWebSocketServer) Q_DECLARE_LOGGING_CATEGORY(dcWebSocketServer)
Q_DECLARE_LOGGING_CATEGORY(dcWebSocketServerTraffic) Q_DECLARE_LOGGING_CATEGORY(dcWebSocketServerTraffic)
Q_DECLARE_LOGGING_CATEGORY(dcTcpSocketServer)
Q_DECLARE_LOGGING_CATEGORY(dcTcpSocketServerTraffic)
Q_DECLARE_LOGGING_CATEGORY(dcAuthentication) Q_DECLARE_LOGGING_CATEGORY(dcAuthentication)
Q_DECLARE_LOGGING_CATEGORY(dcAuthenticationProcess) Q_DECLARE_LOGGING_CATEGORY(dcAuthenticationProcess)
Q_DECLARE_LOGGING_CATEGORY(dcProxyServer) Q_DECLARE_LOGGING_CATEGORY(dcProxyServer)

View File

@ -20,6 +20,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "tcpsocketserver.h" #include "tcpsocketserver.h"
#include "loggingcategories.h"
namespace remoteproxy { namespace remoteproxy {
@ -28,47 +29,150 @@ TcpSocketServer::TcpSocketServer(bool sslEnabled, const QSslConfiguration &sslCo
m_sslEnabled(sslEnabled), m_sslEnabled(sslEnabled),
m_sslConfiguration(sslConfiguration) m_sslConfiguration(sslConfiguration)
{ {
m_serverName = "TCP";
} }
quint16 TcpSocketServer::port() const TcpSocketServer::~TcpSocketServer()
{ {
return m_port; stopServer();
}
void TcpSocketServer::setPort(quint16 port)
{
m_port = port;
}
QHostAddress TcpSocketServer::hostAddress() const
{
return m_hostAddress;
}
void TcpSocketServer::setHostAddress(const QHostAddress &address)
{
m_hostAddress = address;
} }
void TcpSocketServer::sendData(const QUuid &clientId, const QByteArray &data) void TcpSocketServer::sendData(const QUuid &clientId, const QByteArray &data)
{ {
QTcpSocket *client = nullptr;
client = m_clientList.value(clientId);
if (!client) {
qCWarning(dcTcpSocketServer()) << "Client" << clientId << "unknown to this transport";
return;
}
client->write(data + '\n');
} }
void TcpSocketServer::killClientConnection(const QUuid &clientId, const QString &killReason) void TcpSocketServer::killClientConnection(const QUuid &clientId, const QString &killReason)
{ {
QTcpSocket *client = m_clientList.value(clientId);
if (!client)
return;
qCWarning(dcTcpSocketServer()) << "Killing client connection" << clientId.toString() << "Reason:" << killReason;
client->abort();
}
bool TcpSocketServer::running() const
{
if (!m_server)
return false;
return m_server->isListening();
}
void TcpSocketServer::onDataAvailable(QSslSocket *client, const QByteArray &data)
{
qCDebug(dcTcpSocketServerTraffic()) << "Emitting data available internal.";
QUuid clientId = m_clientList.key(qobject_cast<QTcpSocket *>(client));
emit dataAvailable(clientId, data);
}
void TcpSocketServer::onClientConnected(QSslSocket *client)
{
QUuid clientId = QUuid::createUuid();
qCDebug(dcTcpSocketServer()) << "New client connected:" << client << client->peerAddress().toString() << clientId.toString();
m_clientList.insert(clientId, client);
emit clientConnected(clientId, client->peerAddress());
}
void TcpSocketServer::onClientDisconnected(QSslSocket *client)
{
QUuid clientId = m_clientList.key(client);
qCDebug(dcWebSocketServer()) << "Client disconnected:" << client << client->peerAddress().toString() << clientId.toString();
m_clientList.take(clientId);
// Note: the SslServer is deleting the socket object
emit clientDisconnected(clientId);
} }
bool TcpSocketServer::startServer() bool TcpSocketServer::startServer()
{ {
qCDebug(dcTcpSocketServer()) << "Starting TCP server" << m_serverUrl.toString();
m_server = new SslServer(m_sslEnabled, m_sslConfiguration);
if(!m_server->listen(QHostAddress(m_serverUrl.host()), static_cast<quint16>(m_serverUrl.port()))) {
qCWarning(dcTcpSocketServer()) << "Tcp server error: can not listen on" << m_serverUrl.toString();
delete m_server;
m_server = nullptr;
return false;
}
connect(m_server, &SslServer::clientConnected, this, &TcpSocketServer::onClientConnected);
connect(m_server, SIGNAL(clientDisconnected(QSslSocket *)), SLOT(onClientDisconnected(QSslSocket *)));
connect(m_server, &SslServer::dataAvailable, this, &TcpSocketServer::onDataAvailable);
qCDebug(dcTcpSocketServer()) << "Server started successfully.";
return true;
} }
bool TcpSocketServer::stopServer() bool TcpSocketServer::stopServer()
{
// Clean up client connections
foreach (const QUuid &clientId, m_clientList.keys()) {
killClientConnection(clientId, "Stop server");
}
if (!m_server)
return true;
qCDebug(dcTcpSocketServer()) << "Stop server" << m_serverUrl.toString();
m_server->close();
delete m_server;
m_server = nullptr;
return true;
}
SslServer::SslServer(bool sslEnabled, const QSslConfiguration &config, QObject *parent) :
QTcpServer(parent),
m_sslEnabled(sslEnabled),
m_config(config)
{ {
} }
void SslServer::incomingConnection(qintptr socketDescriptor)
{
QSslSocket *sslSocket = new QSslSocket(this);
qCDebug(dcTcpSocketServer()) << "New client connected:" << sslSocket << sslSocket->peerAddress().toString();
connect(sslSocket, &QSslSocket::encrypted, [this, sslSocket](){ emit clientConnected(sslSocket); });
connect(sslSocket, &QSslSocket::readyRead, this, &SslServer::onSocketReadyRead);
connect(sslSocket, &QSslSocket::disconnected, this, &SslServer::onClientDisconnected);
if (!sslSocket->setSocketDescriptor(socketDescriptor)) {
qCWarning(dcTcpSocketServer()) << "Failed to set SSL socket descriptor.";
delete sslSocket;
return;
}
if (m_sslEnabled) {
sslSocket->setSslConfiguration(m_config);
sslSocket->startServerEncryption();
} else {
emit clientConnected(sslSocket);
}
}
void SslServer::onClientDisconnected()
{
QSslSocket *sslSocket = qobject_cast<QSslSocket *>(sender());
qCDebug(dcTcpSocketServer()) << "Client socket disconnected:" << sslSocket << sslSocket->peerAddress().toString();;
emit clientDisconnected(sslSocket);
sslSocket->deleteLater();
}
void SslServer::onSocketReadyRead()
{
QSslSocket *sslSocket = qobject_cast<QSslSocket *>(sender());
QByteArray data = sslSocket->readAll();
qCDebug(dcTcpSocketServerTraffic()) << "Data from socket" << sslSocket->peerAddress().toString() << data;
emit dataAvailable(sslSocket, data);
}
} }

View File

@ -22,6 +22,7 @@
#ifndef TCPSOCKETSERVER_H #ifndef TCPSOCKETSERVER_H
#define TCPSOCKETSERVER_H #define TCPSOCKETSERVER_H
#include <QUuid>
#include <QObject> #include <QObject>
#include <QTcpServer> #include <QTcpServer>
#include <QSslConfiguration> #include <QSslConfiguration>
@ -35,13 +36,12 @@ class SslServer: public QTcpServer
{ {
Q_OBJECT Q_OBJECT
public: public:
SslServer(bool sslEnabled, const QSslConfiguration &config, QObject *parent = nullptr): explicit SslServer(bool sslEnabled, const QSslConfiguration &config, QObject *parent = nullptr);
QTcpServer(parent), ~SslServer() override = default;
m_sslEnabled(sslEnabled),
m_config(config)
{
} private:
bool m_sslEnabled = false;
QSslConfiguration m_config;
signals: signals:
void clientConnected(QSslSocket *socket); void clientConnected(QSslSocket *socket);
@ -55,9 +55,6 @@ private slots:
void onClientDisconnected(); void onClientDisconnected();
void onSocketReadyRead(); void onSocketReadyRead();
private:
bool m_sslEnabled = false;
QSslConfiguration m_config;
}; };
@ -68,22 +65,23 @@ public:
explicit TcpSocketServer(bool sslEnabled, const QSslConfiguration &sslConfiguration, QObject *parent = nullptr); explicit TcpSocketServer(bool sslEnabled, const QSslConfiguration &sslConfiguration, QObject *parent = nullptr);
~TcpSocketServer() override; ~TcpSocketServer() override;
quint16 port() const;
void setPort(quint16 port);
QHostAddress hostAddress() const;
void setHostAddress(const QHostAddress &address);
void sendData(const QUuid &clientId, const QByteArray &data) override; void sendData(const QUuid &clientId, const QByteArray &data) override;
void killClientConnection(const QUuid &clientId, const QString &killReason) override; void killClientConnection(const QUuid &clientId, const QString &killReason) override;
bool running() const override;
private: private:
quint16 m_port;
QHostAddress m_hostAddress;
bool m_sslEnabled; bool m_sslEnabled;
QSslConfiguration m_sslConfiguration; QSslConfiguration m_sslConfiguration;
QTcpServer *m_server = nullptr; QHash<QUuid, QTcpSocket *> m_clientList;
SslServer *m_server = nullptr;
private slots:
void onDataAvailable(QSslSocket *client, const QByteArray &data);
void onClientConnected(QSslSocket *client);
void onClientDisconnected(QSslSocket *client);
public slots: public slots:
bool startServer() override; bool startServer() override;

View File

@ -35,14 +35,24 @@ TransportInterface::TransportInterface(QObject *parent) :
} }
QString TransportInterface::serverName() const
{
return m_serverName;
}
TransportInterface::~TransportInterface() TransportInterface::~TransportInterface()
{ {
} }
QString TransportInterface::serverName() const
{
return m_serverName;
}
QUrl TransportInterface::serverUrl() const
{
return m_serverUrl;
}
void TransportInterface::setServerUrl(const QUrl &serverUrl)
{
m_serverUrl = serverUrl;
}
} }

View File

@ -28,6 +28,7 @@
#ifndef TRANSPORTINTERFACE_H #ifndef TRANSPORTINTERFACE_H
#define TRANSPORTINTERFACE_H #define TRANSPORTINTERFACE_H
#include <QUrl>
#include <QObject> #include <QObject>
#include <QHostAddress> #include <QHostAddress>
@ -45,12 +46,18 @@ public:
virtual void sendData(const QUuid &clientId, const QByteArray &data) = 0; virtual void sendData(const QUuid &clientId, const QByteArray &data) = 0;
virtual void killClientConnection(const QUuid &clientId, const QString &killReason) = 0; virtual void killClientConnection(const QUuid &clientId, const QString &killReason) = 0;
QUrl serverUrl() const;
void setServerUrl(const QUrl &serverUrl);
virtual bool running() const = 0;
signals: signals:
void clientConnected(const QUuid &clientId, const QHostAddress &address); void clientConnected(const QUuid &clientId, const QHostAddress &address);
void clientDisconnected(const QUuid &clientId); void clientDisconnected(const QUuid &clientId);
void dataAvailable(const QUuid &clientId, const QByteArray &data); void dataAvailable(const QUuid &clientId, const QByteArray &data);
protected: protected:
QUrl m_serverUrl;
QString m_serverName; QString m_serverName;
public slots: public slots:

View File

@ -37,7 +37,7 @@ WebSocketServer::WebSocketServer(bool sslEnabled, const QSslConfiguration &sslCo
m_sslEnabled(sslEnabled), m_sslEnabled(sslEnabled),
m_sslConfiguration(sslConfiguration) m_sslConfiguration(sslConfiguration)
{ {
m_serverName = "Websocket server"; m_serverName = "WebSocket";
} }
WebSocketServer::~WebSocketServer() WebSocketServer::~WebSocketServer()
@ -45,16 +45,6 @@ WebSocketServer::~WebSocketServer()
stopServer(); stopServer();
} }
QUrl WebSocketServer::serverUrl() const
{
return m_serverUrl;
}
void WebSocketServer::setServerUrl(const QUrl &serverUrl)
{
m_serverUrl = serverUrl;
}
bool WebSocketServer::running() const bool WebSocketServer::running() const
{ {
if (!m_server) if (!m_server)
@ -215,13 +205,13 @@ bool WebSocketServer::stopServer()
} }
// Delete the server object // Delete the server object
if (m_server) { if (!m_server)
qCDebug(dcWebSocketServer()) << "Stop server" << m_server->serverName() << serverUrl().toString(); return true;
m_server->close();
delete m_server;
m_server = nullptr;
}
qCDebug(dcWebSocketServer()) << "Stop server" << m_server->serverName() << serverUrl().toString();
m_server->close();
delete m_server;
m_server = nullptr;
return true; return true;
} }

View File

@ -46,10 +46,7 @@ public:
explicit WebSocketServer(bool sslEnabled, const QSslConfiguration &sslConfiguration, QObject *parent = nullptr); explicit WebSocketServer(bool sslEnabled, const QSslConfiguration &sslConfiguration, QObject *parent = nullptr);
~WebSocketServer() override; ~WebSocketServer() override;
QUrl serverUrl() const; bool running() const override;
void setServerUrl(const QUrl &serverUrl);
bool running() const;
QSslConfiguration sslConfiguration() const; QSslConfiguration sslConfiguration() const;
@ -57,7 +54,6 @@ public:
void killClientConnection(const QUuid &clientId, const QString &killReason) override; void killClientConnection(const QUuid &clientId, const QString &killReason) override;
private: private:
QUrl m_serverUrl;
QWebSocketServer *m_server = nullptr; QWebSocketServer *m_server = nullptr;
bool m_sslEnabled; bool m_sslEnabled;
QSslConfiguration m_sslConfiguration; QSslConfiguration m_sslConfiguration;

View File

@ -27,6 +27,7 @@
#include "proxyconnection.h" #include "proxyconnection.h"
#include "proxyjsonrpcclient.h" #include "proxyjsonrpcclient.h"
#include "tcpsocketconnection.h"
#include "websocketconnection.h" #include "websocketconnection.h"
#include "remoteproxyconnection.h" #include "remoteproxyconnection.h"
@ -335,8 +336,7 @@ bool RemoteProxyConnection::connectServer(const QUrl &url)
m_connection = qobject_cast<ProxyConnection *>(new WebSocketConnection(this)); m_connection = qobject_cast<ProxyConnection *>(new WebSocketConnection(this));
break; break;
case ConnectionTypeTcpSocket: case ConnectionTypeTcpSocket:
// FIXME: m_connection = qobject_cast<ProxyConnection *>(new TcpSocketConnection(this));
//m_connection = qobject_cast<ProxyConnection *>(new WebSocketConnection(this));
break; break;
} }

View File

@ -153,6 +153,7 @@ public slots:
bool authenticate(const QString &token, const QString &nonce = QString()); bool authenticate(const QString &token, const QString &nonce = QString());
void disconnectServer(); void disconnectServer();
bool sendData(const QByteArray &data); bool sendData(const QByteArray &data);
}; };
} }

View File

@ -73,7 +73,7 @@ void RemoteProxyOfflineTests::dummyAuthenticator()
params.insert("name", "test"); params.insert("name", "test");
params.insert("token", "foobar"); params.insert("token", "foobar");
QVariant response = invokeApiCall("Authentication.Authenticate", params); QVariant response = invokeWebSocketApiCall("Authentication.Authenticate", params);
qDebug() << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented)); qDebug() << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented));
verifyAuthenticationError(response); verifyAuthenticationError(response);
@ -291,7 +291,7 @@ void RemoteProxyOfflineTests::getIntrospect()
// Start the server // Start the server
startServer(); startServer();
QVariant response = invokeApiCall("RemoteProxy.Introspect"); QVariant response = invokeWebSocketApiCall("RemoteProxy.Introspect");
qDebug() << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented)); qDebug() << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented));
// Clean up // Clean up
@ -303,7 +303,7 @@ void RemoteProxyOfflineTests::getHello()
// Start the server // Start the server
startServer(); startServer();
QVariantMap response = invokeApiCall("RemoteProxy.Hello").toMap(); QVariantMap response = invokeWebSocketApiCall("RemoteProxy.Hello").toMap();
qDebug() << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented)); qDebug() << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented));
// Verify data // Verify data
@ -342,7 +342,7 @@ void RemoteProxyOfflineTests::apiBasicCalls()
// Start the server // Start the server
startServer(); startServer();
QVariant response = injectSocketData(data); QVariant response = injectWebSocketData(data);
qDebug() << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented)); qDebug() << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented));
QCOMPARE(response.toMap().value("id").toInt(), responseId); QCOMPARE(response.toMap().value("id").toInt(), responseId);
@ -409,7 +409,7 @@ void RemoteProxyOfflineTests::authenticate()
params.insert("token", token); params.insert("token", token);
if (!nonce.isEmpty()) params.insert("nonce", nonce); if (!nonce.isEmpty()) params.insert("nonce", nonce);
QVariant response = invokeApiCall("Authentication.Authenticate", params); QVariant response = invokeWebSocketApiCall("Authentication.Authenticate", params);
qDebug() << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented)); qDebug() << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented));
verifyAuthenticationError(response, expectedError); verifyAuthenticationError(response, expectedError);
@ -925,7 +925,7 @@ void RemoteProxyOfflineTests::jsonRpcTimeout()
params.insert("name", "name"); params.insert("name", "name");
params.insert("token", "token"); params.insert("token", "token");
QVariant response = invokeApiCall("Authentication.Authenticate", params); QVariant response = invokeWebSocketApiCall("Authentication.Authenticate", params);
qDebug() << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented)); qDebug() << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented));
QVERIFY(response.toMap().value("status").toString() == "error"); QVERIFY(response.toMap().value("status").toString() == "error");
@ -976,7 +976,7 @@ void RemoteProxyOfflineTests::authenticationReplyTimeout()
params.insert("name", "Sleepy test client"); params.insert("name", "Sleepy test client");
params.insert("token", "sleepy token zzzZZZ"); params.insert("token", "sleepy token zzzZZZ");
QVariant response = invokeApiCall("Authentication.Authenticate", params); QVariant response = invokeWebSocketApiCall("Authentication.Authenticate", params);
qDebug() << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented)); qDebug() << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented));
verifyAuthenticationError(response, Authenticator::AuthenticationErrorTimeout); verifyAuthenticationError(response, Authenticator::AuthenticationErrorTimeout);

View File

@ -89,6 +89,7 @@ void BaseTest::startServer()
QVERIFY(Engine::instance()->running()); QVERIFY(Engine::instance()->running());
QVERIFY(Engine::instance()->developerMode()); QVERIFY(Engine::instance()->developerMode());
QVERIFY(Engine::instance()->webSocketServer()->running()); QVERIFY(Engine::instance()->webSocketServer()->running());
QVERIFY(Engine::instance()->tcpSocketServer()->running());
QVERIFY(Engine::instance()->monitorServer()->running()); QVERIFY(Engine::instance()->monitorServer()->running());
} }
@ -101,7 +102,7 @@ void BaseTest::stopServer()
QVERIFY(!Engine::instance()->running()); QVERIFY(!Engine::instance()->running());
} }
QVariant BaseTest::invokeApiCall(const QString &method, const QVariantMap params, bool remainsConnected) QVariant BaseTest::invokeWebSocketApiCall(const QString &method, const QVariantMap params, bool remainsConnected)
{ {
Q_UNUSED(remainsConnected) Q_UNUSED(remainsConnected)
@ -152,11 +153,12 @@ QVariant BaseTest::invokeApiCall(const QString &method, const QVariantMap params
return jsonDoc.toVariant(); return jsonDoc.toVariant();
} }
} }
m_commandCounter++; m_commandCounter++;
return QVariant(); return QVariant();
} }
QVariant BaseTest::injectSocketData(const QByteArray &data) QVariant BaseTest::injectWebSocketData(const QByteArray &data)
{ {
QWebSocket *socket = new QWebSocket("proxy-testclient", QWebSocketProtocol::Version13); QWebSocket *socket = new QWebSocket("proxy-testclient", QWebSocketProtocol::Version13);
connect(socket, &QWebSocket::sslErrors, this, &BaseTest::sslErrors); connect(socket, &QWebSocket::sslErrors, this, &BaseTest::sslErrors);

View File

@ -78,8 +78,8 @@ protected:
void startServer(); void startServer();
void stopServer(); void stopServer();
QVariant invokeApiCall(const QString &method, const QVariantMap params = QVariantMap(), bool remainsConnected = true); QVariant invokeWebSocketApiCall(const QString &method, const QVariantMap params = QVariantMap(), bool remainsConnected = true);
QVariant injectSocketData(const QByteArray &data); QVariant injectWebSocketData(const QByteArray &data);
bool createRemoteConnection(const QString &token, const QString &nonce, QObject *parent); bool createRemoteConnection(const QString &token, const QString &nonce, QObject *parent);