Merge PR #29: Fix authentication reply crash if client already disconnected

This commit is contained in:
jenkins 2022-05-06 18:55:21 +02:00
commit a04f6d117e
8 changed files with 130 additions and 140 deletions

View File

@ -51,28 +51,10 @@ QString AwsAuthenticator::name() const
return "AWS authenticator";
}
void AwsAuthenticator::onAuthenticationProcessFinished(Authenticator::AuthenticationError error, const UserInformation &userInformation)
{
AuthenticationProcess *process = static_cast<AuthenticationProcess *>(sender());
AuthenticationReply *reply = m_runningProcesses.take(process);
if (error == AuthenticationErrorNoError) {
qCDebug(dcAuthentication()) << name() << reply->proxyClient() << "finished successfully." << userInformation;
} else {
qCDebug(dcAuthentication()) << name() << reply->proxyClient() << "finished with error" << error;
}
reply->proxyClient()->setUserName(userInformation.email());
setReplyError(reply, error);
setReplyFinished(reply);
}
AuthenticationReply *AwsAuthenticator::authenticate(ProxyClient *proxyClient)
{
qCDebug(dcAuthentication()) << name() << "Start authenticating" << proxyClient;
AuthenticationReply *reply = createAuthenticationReply(proxyClient, this);
AuthenticationReply *reply = createAuthenticationReply(proxyClient, proxyClient);
if (!m_credentialsProvider->isValid()) {
qCWarning(dcAuthentication()) << name() << "There are no credentials for authenticating.";
setReplyError(reply, AuthenticationErrorProxyError);
@ -83,12 +65,21 @@ AuthenticationReply *AwsAuthenticator::authenticate(ProxyClient *proxyClient)
AuthenticationProcess *process = new AuthenticationProcess(m_manager,
m_credentialsProvider->accessKey(),
m_credentialsProvider->secretAccessKey(),
m_credentialsProvider->sessionToken(), this);
m_credentialsProvider->sessionToken(), reply);
connect(process, &AuthenticationProcess::authenticationFinished, this, &AwsAuthenticator::onAuthenticationProcessFinished);
connect(process, &AuthenticationProcess::authenticationFinished, proxyClient, [=](Authenticator::AuthenticationError error, const UserInformation &userInformation = UserInformation()){
if (error == AuthenticationErrorNoError) {
qCDebug(dcAuthentication()) << name() << proxyClient << "finished successfully." << userInformation;
} else {
qCDebug(dcAuthentication()) << name() << proxyClient << "finished with error" << error;
}
proxyClient->setUserName(userInformation.email());
setReplyError(reply, error);
setReplyFinished(reply);
});
// Configure process
m_runningProcesses.insert(process, reply);
// Start authentication process
process->authenticate(proxyClient->token());

View File

@ -50,10 +50,6 @@ public:
private:
QNetworkAccessManager *m_manager = nullptr;
AwsCredentialProvider *m_credentialsProvider = nullptr;
QHash<AuthenticationProcess *, AuthenticationReply *> m_runningProcesses;
private slots:
void onAuthenticationProcessFinished(Authenticator::AuthenticationError error, const UserInformation &userInformation);
public slots:
AuthenticationReply *authenticate(ProxyClient *proxyClient) override;

View File

@ -79,36 +79,28 @@ JsonReply *AuthenticationHandler::Authenticate(const QVariantMap &params, Transp
proxyClient->setNonce(nonce);
AuthenticationReply *authReply = Engine::instance()->authenticator()->authenticate(proxyClient);
connect(authReply, &AuthenticationReply::finished, this, &AuthenticationHandler::onAuthenticationFinished);
connect(authReply, &AuthenticationReply::finished, jsonReply, [=](){
authReply->deleteLater();
m_runningAuthentications.insert(authReply, jsonReply);
qCDebug(dcJsonRpc()) << "Authentication reply finished";
if (authReply->error() != Authenticator::AuthenticationErrorNoError) {
qCWarning(dcJsonRpc()) << "Authentication error occurred" << authReply->error();
jsonReply->setSuccess(false);
} else {
// Successfully authenticated
jsonReply->setSuccess(true);
}
// Set client authenticated if still there
if (!authReply->proxyClient().isNull()) {
authReply->proxyClient()->setAuthenticated(authReply->error() == Authenticator::AuthenticationErrorNoError);
jsonReply->setData(errorToReply(authReply->error()));
}
emit jsonReply->finished();
});
return jsonReply;
}
void AuthenticationHandler::onAuthenticationFinished()
{
AuthenticationReply *authenticationReply = static_cast<AuthenticationReply *>(sender());
authenticationReply->deleteLater();
qCDebug(dcJsonRpc()) << "Authentication reply finished";
JsonReply *jsonReply = m_runningAuthentications.take(authenticationReply);
if (authenticationReply->error() != Authenticator::AuthenticationErrorNoError) {
qCWarning(dcJsonRpc()) << "Authentication error occurred" << authenticationReply->error();
jsonReply->setSuccess(false);
} else {
// Successfully authenticated
jsonReply->setSuccess(true);
}
// Set client authenticated if still there
if (!authenticationReply->proxyClient().isNull()) {
authenticationReply->proxyClient()->setAuthenticated(authenticationReply->error() == Authenticator::AuthenticationErrorNoError);
jsonReply->setData(errorToReply(authenticationReply->error()));
}
emit jsonReply->finished();
}
}

View File

@ -48,13 +48,6 @@ public:
Q_INVOKABLE JsonReply *Authenticate(const QVariantMap &params, TransportClient *transportClient);
private:
QHash<AuthenticationReply *, JsonReply *> m_runningAuthentications;
private slots:
void onAuthenticationFinished();
};
}

View File

@ -300,6 +300,10 @@ void ProxyServer::onClientDataAvailable(const QUuid &clientId, const QByteArray
// Calculate server statisitcs
m_troughputCounter += data.count();
proxyClient->addRxDataCount(data.count());
if (!remoteClient)
return;
remoteClient->addTxDataCount(data.count());
m_totalTraffic += data.count();

View File

@ -3,10 +3,10 @@ name=test-nymea-remoteproxy
writeLogs=false
logFile=/var/log/nymea-remoteproxy.log
monitorSocket=/tmp/nymea-remoteproxy-test.sock
jsonRpcTimeout=2000
authenticationTimeout=1000
inactiveTimeout=1500
aloneTimeout=1500
jsonRpcTimeout=10000
authenticationTimeout=10000
inactiveTimeout=5000
aloneTimeout=10000
[SSL]
certificate=:/test-certificate.crt

View File

@ -130,14 +130,14 @@ void RemoteProxyTestsProxy::monitorServer()
// Connect one
QSignalSpy connectionOneReadySpy(connectionOne, &RemoteProxyConnection::ready);
QVERIFY(connectionOne->connectServer(m_serverUrlProxyTcp));
connectionOneReadySpy.wait();
if (connectionOneReadySpy.count() < 1) connectionOneReadySpy.wait();
QVERIFY(connectionOneReadySpy.count() == 1);
QVERIFY(connectionOne->isConnected());
// Connect two
QSignalSpy connectionTwoReadySpy(connectionTwo, &RemoteProxyConnection::ready);
QVERIFY(connectionTwo->connectServer(m_serverUrlProxyTcp));
connectionTwoReadySpy.wait();
if (connectionTwoReadySpy.count() < 1) connectionTwoReadySpy.wait();
QVERIFY(connectionTwoReadySpy.count() == 1);
QVERIFY(connectionTwo->isConnected());
@ -145,7 +145,7 @@ void RemoteProxyTestsProxy::monitorServer()
QSignalSpy remoteConnectionEstablishedOne(connectionOne, &RemoteProxyConnection::remoteConnectionEstablished);
QSignalSpy connectionOneAuthenticatedSpy(connectionOne, &RemoteProxyConnection::authenticated);
QVERIFY(connectionOne->authenticate(m_testToken));
connectionOneAuthenticatedSpy.wait();
if (connectionOneAuthenticatedSpy.count() < 1) connectionOneAuthenticatedSpy.wait();
QVERIFY(connectionOneAuthenticatedSpy.count() == 1);
QVERIFY(connectionOne->isConnected());
QVERIFY(connectionOne->isAuthenticated());
@ -155,14 +155,17 @@ void RemoteProxyTestsProxy::monitorServer()
QSignalSpy remoteConnectionEstablishedTwo(connectionTwo, &RemoteProxyConnection::remoteConnectionEstablished);
QSignalSpy connectionTwoAuthenticatedSpy(connectionTwo, &RemoteProxyConnection::authenticated);
QVERIFY(connectionTwo->authenticate(m_testToken));
connectionTwoAuthenticatedSpy.wait();
if (connectionTwoAuthenticatedSpy.count() < 1) connectionTwoAuthenticatedSpy.wait();
QVERIFY(connectionTwoAuthenticatedSpy.count() == 1);
QVERIFY(connectionTwo->isConnected());
QVERIFY(connectionTwo->isAuthenticated());
// Wait for both to be connected
remoteConnectionEstablishedOne.wait(500);
remoteConnectionEstablishedTwo.wait(500);
if (remoteConnectionEstablishedOne.count() < 1)
remoteConnectionEstablishedOne.wait();
if (remoteConnectionEstablishedTwo.count() < 1)
remoteConnectionEstablishedTwo.wait();
QVERIFY(remoteConnectionEstablishedOne.count() == 1);
QVERIFY(remoteConnectionEstablishedTwo.count() == 1);
@ -174,16 +177,15 @@ void RemoteProxyTestsProxy::monitorServer()
QCOMPARE(connectionTwo->tunnelPartnerName(), nameConnectionOne);
QCOMPARE(QUuid(connectionTwo->tunnelPartnerUuid()), uuidConnectionOne);
// Get monitor data
QLocalSocket *monitor = new QLocalSocket(this);
QSignalSpy connectedSpy(monitor, &QLocalSocket::connected);
monitor->connectToServer(m_configuration->monitorSocketFileName());
connectedSpy.wait(200);
if (connectedSpy.count() < 1) connectedSpy.wait();
QVERIFY(connectedSpy.count() == 1);
QSignalSpy dataSpy(monitor, &QLocalSocket::readyRead);
dataSpy.wait();
if (dataSpy.count() < 1) dataSpy.wait();
QVERIFY(dataSpy.count() == 1);
QByteArray data = monitor->readAll();
qDebug() << data;
@ -192,7 +194,7 @@ void RemoteProxyTestsProxy::monitorServer()
QSignalSpy disconnectedSpy(monitor, &QLocalSocket::connected);
monitor->disconnectFromServer();
disconnectedSpy.wait(200);
if (disconnectedSpy.count() < 1) disconnectedSpy.wait();
// Clean up
monitor->deleteLater();
@ -315,7 +317,7 @@ void RemoteProxyTestsProxy::websocketBinaryData()
// Send binary data and make sure the server disconnects this socket
QSignalSpy spyDisconnected(client, SIGNAL(disconnected()));
client->sendBinaryMessage("trying to upload stuff...stuff...more stuff... other stuff");
spyConnection.wait(200);
spyConnection.wait(1000);
QVERIFY(spyConnection.count() == 1);
// Clean up
@ -508,26 +510,26 @@ void RemoteProxyTestsProxy::authenticate_data()
QTest::addColumn<Authenticator::AuthenticationError>("expectedError");
QTest::newRow("success") << QUuid::createUuid().toString() << "Testclient, hello form the test!" << m_testToken << ""
<< 100 << Authenticator::AuthenticationErrorNoError;
<< 500 << Authenticator::AuthenticationErrorNoError;
QTest::newRow("success") << QUuid::createUuid().toString() << "Testclient, hello form the test!" << m_testToken << "nonce"
<< 100 << Authenticator::AuthenticationErrorNoError;
<< 500 << Authenticator::AuthenticationErrorNoError;
QTest::newRow("success") << QUuid::createUuid().toString() << "Testclient, hello form the test!" << m_testToken << "nonce"
<< 100 << Authenticator::AuthenticationErrorAuthenticationFailed;
<< 300 << Authenticator::AuthenticationErrorAuthenticationFailed;
QTest::newRow("failed") << QUuid::createUuid().toString() << "Testclient, hello form the test!" << m_testToken << ""
<< 100 << Authenticator::AuthenticationErrorAuthenticationFailed;
<< 300 << Authenticator::AuthenticationErrorAuthenticationFailed;
QTest::newRow("not responding") << QUuid::createUuid().toString() << "Testclient, hello form the test!" << m_testToken << ""
<< 200 << Authenticator::AuthenticationErrorProxyError;
<< 500 << Authenticator::AuthenticationErrorProxyError;
QTest::newRow("aborted") << QUuid::createUuid().toString() << "Testclient, hello form the test!" << m_testToken << ""
<< 100 << Authenticator::AuthenticationErrorAborted;
<< 300 << Authenticator::AuthenticationErrorAborted;
QTest::newRow("unknown") << QUuid::createUuid().toString() << "Testclient, hello form the test!" << m_testToken << ""
<< 100 << Authenticator::AuthenticationErrorUnknown;
<< 300 << Authenticator::AuthenticationErrorUnknown;
}
@ -543,6 +545,10 @@ void RemoteProxyTestsProxy::authenticate()
// Start the server
startServer();
m_configuration->setAuthenticationTimeout(8000);
m_configuration->setJsonRpcTimeout(10000);
m_configuration->setInactiveTimeout(10000);
// Configure result
m_mockAuthenticator->setExpectedAuthenticationError(expectedError);
m_mockAuthenticator->setTimeoutDuration(timeout);
@ -630,8 +636,11 @@ void RemoteProxyTestsProxy::authenticateNonce()
QVERIFY(connectionTwo->isAuthenticated());
// Wait for both to be connected
remoteConnectionEstablishedOne.wait(500);
remoteConnectionEstablishedTwo.wait(500);
if (remoteConnectionEstablishedOne.count() < 1)
remoteConnectionEstablishedOne.wait();
if (remoteConnectionEstablishedTwo.count() < 1)
remoteConnectionEstablishedTwo.wait();
QVERIFY(remoteConnectionEstablishedOne.count() == 1);
QVERIFY(remoteConnectionEstablishedTwo.count() == 1);
@ -648,12 +657,12 @@ void RemoteProxyTestsProxy::authenticateNonce()
QSignalSpy remoteConnectionDataTwo(connectionTwo, &RemoteProxyConnection::dataReady);
connectionOne->sendData(dataOne);
remoteConnectionDataTwo.wait(500);
remoteConnectionDataTwo.wait();
QVERIFY(remoteConnectionDataTwo.count() == 1);
QCOMPARE(remoteConnectionDataTwo.at(0).at(0).toByteArray().trimmed(), dataOne);
connectionTwo->sendData(dataTwo);
remoteConnectionDataOne.wait(500);
remoteConnectionDataOne.wait();
QVERIFY(remoteConnectionDataOne.count() == 1);
QCOMPARE(remoteConnectionDataOne.at(0).at(0).toByteArray().trimmed(), dataTwo);
@ -750,8 +759,7 @@ void RemoteProxyTestsProxy::clientConnectionWebSocket()
// Disconnect and clean up
QSignalSpy spyDisconnected(connection, &RemoteProxyConnection::disconnected);
connection->disconnectServer();
// FIXME: check why it waits the full time here
spyDisconnected.wait(500);
if (spyDisconnected.count() < 1) spyDisconnected.wait();
QVERIFY(spyDisconnected.count() >= 1);
QVERIFY(!connection->isConnected());
@ -800,8 +808,8 @@ void RemoteProxyTestsProxy::clientConnectionTcpSocket()
// Disconnect and clean up
QSignalSpy spyDisconnected(connection, &RemoteProxyConnection::disconnected);
connection->disconnectServer();
// FIXME: check why it waits the full time here
spyDisconnected.wait(500);
if (spyDisconnected.count() < 1) spyDisconnected.wait();
QVERIFY(spyDisconnected.count() >= 1);
QVERIFY(!connection->isConnected());
@ -869,8 +877,11 @@ void RemoteProxyTestsProxy::remoteConnection()
QVERIFY(connectionTwo->isAuthenticated());
// Wait for both to be connected
remoteConnectionEstablishedOne.wait(500);
remoteConnectionEstablishedTwo.wait(500);
if (remoteConnectionEstablishedOne.count() < 1)
remoteConnectionEstablishedOne.wait();
if (remoteConnectionEstablishedTwo.count() < 1)
remoteConnectionEstablishedTwo.wait();
QVERIFY(remoteConnectionEstablishedOne.count() == 1);
QVERIFY(remoteConnectionEstablishedTwo.count() == 1);
@ -887,12 +898,12 @@ void RemoteProxyTestsProxy::remoteConnection()
QSignalSpy remoteConnectionDataTwo(connectionTwo, &RemoteProxyConnection::dataReady);
connectionOne->sendData(dataOne);
remoteConnectionDataTwo.wait(500);
remoteConnectionDataTwo.wait();
QVERIFY(remoteConnectionDataTwo.count() == 1);
QCOMPARE(remoteConnectionDataTwo.at(0).at(0).toByteArray().trimmed(), dataOne);
connectionTwo->sendData(dataTwo);
remoteConnectionDataOne.wait(500);
remoteConnectionDataOne.wait();
QVERIFY(remoteConnectionDataOne.count() == 1);
QCOMPARE(remoteConnectionDataOne.at(0).at(0).toByteArray().trimmed(), dataTwo);
@ -957,21 +968,21 @@ void RemoteProxyTestsProxy::trippleConnection()
// Connect one
QSignalSpy connectionOneReadySpy(connectionOne, &RemoteProxyConnection::ready);
QVERIFY(connectionOne->connectServer(m_serverUrlProxyTcp));
connectionOneReadySpy.wait();
if (connectionOneReadySpy.count() < 1) connectionOneReadySpy.wait();
QVERIFY(connectionOneReadySpy.count() == 1);
QVERIFY(connectionOne->isConnected());
// Connect two
QSignalSpy connectionTwoReadySpy(connectionTwo, &RemoteProxyConnection::ready);
QVERIFY(connectionTwo->connectServer(m_serverUrlProxyTcp));
connectionTwoReadySpy.wait();
if (connectionTwoReadySpy.count() < 1) connectionTwoReadySpy.wait();
QVERIFY(connectionTwoReadySpy.count() == 1);
QVERIFY(connectionTwo->isConnected());
// Authenticate one
QSignalSpy connectionOneAuthenticatedSpy(connectionOne, &RemoteProxyConnection::authenticated);
QVERIFY(connectionOne->authenticate(m_testToken, nonce));
connectionOneAuthenticatedSpy.wait();
if (connectionOneAuthenticatedSpy.count() < 1) connectionOneAuthenticatedSpy.wait();
QVERIFY(connectionOneAuthenticatedSpy.count() == 1);
QVERIFY(connectionOne->isConnected());
QVERIFY(connectionOne->isAuthenticated());
@ -983,13 +994,14 @@ void RemoteProxyTestsProxy::trippleConnection()
QSignalSpy remoteConnectionEstablishedTwo(connectionTwo, &RemoteProxyConnection::remoteConnectionEstablished);
QSignalSpy connectionTwoAuthenticatedSpy(connectionTwo, &RemoteProxyConnection::authenticated);
QVERIFY(connectionTwo->authenticate(m_testToken, nonce));
connectionTwoAuthenticatedSpy.wait();
if (connectionTwoAuthenticatedSpy.count() < 1) connectionTwoAuthenticatedSpy.wait();
QVERIFY(connectionTwoAuthenticatedSpy.count() == 1);
QVERIFY(connectionTwo->isConnected());
QVERIFY(connectionTwo->isAuthenticated());
// Wait for both to be connected
remoteConnectionEstablishedOne.wait(500);
if (remoteConnectionEstablishedOne.count() < 1)
remoteConnectionEstablishedOne.wait();
// Now connect a third connection and make sure the client will be closed
@ -997,17 +1009,17 @@ void RemoteProxyTestsProxy::trippleConnection()
QSignalSpy connectionThreeReadySpy(connectionThree, &RemoteProxyConnection::ready);
QSignalSpy connectionThreeDisconnectedSpy(connectionThree, &RemoteProxyConnection::disconnected);
QVERIFY(connectionThree->connectServer(m_serverUrlProxyTcp));
connectionThreeReadySpy.wait();
if (connectionThreeReadySpy.count() < 1) connectionThreeReadySpy.wait();
QVERIFY(connectionThreeReadySpy.count() == 1);
QVERIFY(connectionThree->isConnected());
// Authenticate three
QSignalSpy connectionThreeAuthenticatedSpy(connectionThree, &RemoteProxyConnection::authenticated);
QVERIFY(connectionThree->authenticate(m_testToken, nonce));
connectionThreeAuthenticatedSpy.wait();
if (connectionThreeAuthenticatedSpy.count() < 1) connectionThreeAuthenticatedSpy.wait();
QVERIFY(connectionOneAuthenticatedSpy.count() == 1);
connectionThreeDisconnectedSpy.wait(200);
if (connectionThreeDisconnectedSpy.count() < 1) connectionThreeDisconnectedSpy.wait();
QVERIFY(connectionThreeDisconnectedSpy.count() >= 1);
// Make sure the one and two are still connected
@ -1042,21 +1054,21 @@ void RemoteProxyTestsProxy::duplicateUuid()
// Connect one
QSignalSpy connectionOneReadySpy(connectionOne, &RemoteProxyConnection::ready);
QVERIFY(connectionOne->connectServer(m_serverUrlProxyTcp));
connectionOneReadySpy.wait();
if (connectionOneReadySpy.count() < 1) connectionOneReadySpy.wait();
QVERIFY(connectionOneReadySpy.count() == 1);
QVERIFY(connectionOne->isConnected());
// Connect two
QSignalSpy connectionTwoReadySpy(connectionTwo, &RemoteProxyConnection::ready);
QVERIFY(connectionTwo->connectServer(m_serverUrlProxyTcp));
connectionTwoReadySpy.wait();
if (connectionTwoReadySpy.count() < 1) connectionTwoReadySpy.wait();
QVERIFY(connectionTwoReadySpy.count() == 1);
QVERIFY(connectionTwo->isConnected());
// Authenticate one
QSignalSpy connectionOneAuthenticatedSpy(connectionOne, &RemoteProxyConnection::authenticated);
QVERIFY(connectionOne->authenticate(m_testToken));
connectionOneAuthenticatedSpy.wait();
if (connectionOneAuthenticatedSpy.count() < 1) connectionOneAuthenticatedSpy.wait();
QVERIFY(connectionOneAuthenticatedSpy.count() == 1);
QVERIFY(connectionOne->isConnected());
QVERIFY(connectionOne->isAuthenticated());
@ -1067,10 +1079,10 @@ void RemoteProxyTestsProxy::duplicateUuid()
QSignalSpy disconnectSpyTwo(connectionTwo, &RemoteProxyConnection::disconnected);
QVERIFY(connectionTwo->authenticate(m_testToken));
disconnectSpyOne.wait(200);
if (disconnectSpyOne.count() < 1 ) disconnectSpyOne.wait();
QVERIFY(disconnectSpyOne.count() >= 1);
disconnectSpyTwo.wait(200);
if (disconnectSpyTwo.count() < 1 ) disconnectSpyTwo.wait();
QVERIFY(disconnectSpyTwo.count() >= 1);
connectionOne->deleteLater();
@ -1116,16 +1128,12 @@ void RemoteProxyTestsProxy::jsonRpcTimeout()
// Start the server
startServer();
m_configuration->setAuthenticationTimeout(3000);
m_configuration->setJsonRpcTimeout(1000);
m_configuration->setInactiveTimeout(2000);
// Configure result (authentication takes longer than json rpc timeout
m_mockAuthenticator->setExpectedAuthenticationError();
m_mockAuthenticator->setTimeoutDuration(4000);
m_configuration->setAuthenticationTimeout(4000);
m_mockAuthenticator->setTimeoutDuration(10000);
m_configuration->setAuthenticationTimeout(10000);
m_configuration->setJsonRpcTimeout(1000);
m_configuration->setInactiveTimeout(2000);
m_configuration->setInactiveTimeout(10000);
// Create request
QVariantMap params;
@ -1147,6 +1155,8 @@ void RemoteProxyTestsProxy::inactiveTimeout()
// Start the server
startServer();
m_configuration->setInactiveTimeout(1000);
RemoteProxyConnection *connection = new RemoteProxyConnection(QUuid::createUuid(), "Sleepy test client", this);
connect(connection, &RemoteProxyConnection::sslErrors, this, &BaseTest::ignoreConnectionSslError);
@ -1154,11 +1164,13 @@ void RemoteProxyTestsProxy::inactiveTimeout()
QSignalSpy connectionReadySpy(connection, &RemoteProxyConnection::ready);
QSignalSpy connectionDisconnectedSpy(connection, &RemoteProxyConnection::disconnected);
QVERIFY(connection->connectServer(m_serverUrlProxyTcp));
connectionReadySpy.wait();
if (connectionReadySpy.count() < 1) connectionReadySpy.wait();
QVERIFY(connectionReadySpy.count() == 1);
// Now wait for disconnected
connectionDisconnectedSpy.wait();
if (connectionDisconnectedSpy.count() < 1)
connectionDisconnectedSpy.wait();
QVERIFY(connectionDisconnectedSpy.count() >= 1);
// Clean up
@ -1285,8 +1297,11 @@ void RemoteProxyTestsProxy::tcpRemoteConnection()
QVERIFY(connectionTwo->isAuthenticated());
// Wait for both to be connected
remoteConnectionEstablishedOne.wait(500);
remoteConnectionEstablishedTwo.wait(500);
if (remoteConnectionEstablishedOne.count() < 1)
remoteConnectionEstablishedOne.wait();
if (remoteConnectionEstablishedTwo.count() < 1)
remoteConnectionEstablishedTwo.wait();
QVERIFY(remoteConnectionEstablishedOne.count() == 1);
QVERIFY(remoteConnectionEstablishedTwo.count() == 1);
@ -1303,12 +1318,12 @@ void RemoteProxyTestsProxy::tcpRemoteConnection()
QSignalSpy remoteConnectionDataTwo(connectionTwo, &RemoteProxyConnection::dataReady);
connectionOne->sendData(dataOne);
remoteConnectionDataTwo.wait(500);
remoteConnectionDataTwo.wait();
QVERIFY(remoteConnectionDataTwo.count() == 1);
QCOMPARE(remoteConnectionDataTwo.at(0).at(0).toByteArray().trimmed(), dataOne);
connectionTwo->sendData(dataTwo);
remoteConnectionDataOne.wait(500);
remoteConnectionDataOne.wait();
QVERIFY(remoteConnectionDataOne.count() == 1);
QCOMPARE(remoteConnectionDataOne.at(0).at(0).toByteArray().trimmed(), dataTwo);
@ -1379,8 +1394,11 @@ void RemoteProxyTestsProxy::tcpWebsocketRemoteConnection()
QVERIFY(connectionTwo->isAuthenticated());
// Wait for both to be connected
remoteConnectionEstablishedOne.wait(500);
remoteConnectionEstablishedTwo.wait(500);
if (remoteConnectionEstablishedOne.count() < 1)
remoteConnectionEstablishedOne.wait();
if (remoteConnectionEstablishedTwo.count() < 1)
remoteConnectionEstablishedTwo.wait();
QVERIFY(remoteConnectionEstablishedOne.count() == 1);
QVERIFY(remoteConnectionEstablishedTwo.count() == 1);
@ -1397,12 +1415,12 @@ void RemoteProxyTestsProxy::tcpWebsocketRemoteConnection()
QSignalSpy remoteConnectionDataTwo(connectionTwo, &RemoteProxyConnection::dataReady);
connectionOne->sendData(dataOne);
remoteConnectionDataTwo.wait(500);
remoteConnectionDataTwo.wait();
QVERIFY(remoteConnectionDataTwo.count() == 1);
QCOMPARE(remoteConnectionDataTwo.at(0).at(0).toByteArray().trimmed(), dataOne);
connectionTwo->sendData(dataTwo);
remoteConnectionDataOne.wait(500);
remoteConnectionDataOne.wait();
QVERIFY(remoteConnectionDataOne.count() == 1);
QCOMPARE(remoteConnectionDataOne.at(0).at(0).toByteArray().trimmed(), dataTwo);

View File

@ -125,7 +125,7 @@ void BaseTest::startServer()
QSignalSpy runningSpy(Engine::instance(), &Engine::runningChanged);
Engine::instance()->setDeveloperModeEnabled(true);
Engine::instance()->start(m_configuration);
runningSpy.wait(200);
runningSpy.wait();
QVERIFY(runningSpy.count() == 1);
}
@ -266,8 +266,7 @@ QVariant BaseTest::invokeTcpSocketProxyApiCall(const QString &method, const QVar
QSignalSpy dataSpy(socket, &QSslSocket::readyRead);
socket->write(jsonDoc.toJson(QJsonDocument::Compact) + '\n');
// FIXME: check why it waits the full time here
dataSpy.wait(500);
dataSpy.wait();
if (dataSpy.count() != 1) {
qWarning() << "No data received";
return QVariant();
@ -368,7 +367,7 @@ bool BaseTest::createRemoteConnection(const QString &token, const QString &nonce
return false;
}
connectionOneAuthenticatedSpy.wait(500);
connectionOneAuthenticatedSpy.wait();
if (connectionOneAuthenticatedSpy.count() != 1) {
qWarning() << "Could not authenticate client one";
return false;
@ -387,7 +386,7 @@ bool BaseTest::createRemoteConnection(const QString &token, const QString &nonce
return false;
}
connectionTwoAuthenticatedSpy.wait(500);
connectionTwoAuthenticatedSpy.wait();
if (connectionTwoAuthenticatedSpy.count() != 1) {
qWarning() << "Could not authenticate client two";
return false;
@ -399,8 +398,11 @@ bool BaseTest::createRemoteConnection(const QString &token, const QString &nonce
}
// Wait for both to be connected
remoteConnectionEstablishedOne.wait(500);
remoteConnectionEstablishedTwo.wait(500);
if (remoteConnectionEstablishedOne.count() < 1)
remoteConnectionEstablishedOne.wait();
if (remoteConnectionEstablishedTwo.count() < 1)
remoteConnectionEstablishedTwo.wait();
if (remoteConnectionEstablishedOne.count() != 1 || remoteConnectionEstablishedTwo.count() != 1) {
qWarning() << "Could not establish remote connection";
@ -433,8 +435,6 @@ QVariant BaseTest::injectTcpSocketProxyData(const QByteArray &data)
QSignalSpy dataSpy(socket, &QSslSocket::readyRead);
socket->write(data + '\n');
dataSpy.wait();
// FIXME: check why it waits the full time here
dataSpy.wait(500);
if (dataSpy.count() != 1) {
qWarning() << "No data received";
return QVariant();
@ -578,8 +578,7 @@ QVariant BaseTest::invokeTcpSocketTunnelProxyApiCall(const QString &method, cons
QSignalSpy dataSpy(socket, &QSslSocket::readyRead);
socket->write(jsonDoc.toJson(QJsonDocument::Compact) + '\n');
// FIXME: check why it waits the full time here
dataSpy.wait(500);
dataSpy.wait();
if (dataSpy.count() != 1) {
qWarning() << "No data received";
return QVariant();
@ -631,8 +630,6 @@ QVariant BaseTest::injectTcpSocketTunnelProxyData(const QByteArray &data)
QSignalSpy dataSpy(socket, &QSslSocket::readyRead);
socket->write(data + '\n');
dataSpy.wait();
// FIXME: check why it waits the full time here
dataSpy.wait(500);
if (dataSpy.count() != 1) {
qWarning() << "No data received";
return QVariant();
@ -697,8 +694,7 @@ QPair<QVariant, QSslSocket *> BaseTest::invokeTcpSocketTunnelProxyApiCallPersist
socket->write(payload);
}
// FIXME: check why it waits the full time here
dataSpy.wait(500);
dataSpy.wait();
if (dataSpy.count() < 1) {
qWarning() << "No data received";
return QPair<QVariant, QSslSocket *>(QVariant(), socket);