diff --git a/libnymea-remoteproxy/authentication/authenticationreply.cpp b/libnymea-remoteproxy/authentication/authenticationreply.cpp index 7abcf61..eac8d05 100644 --- a/libnymea-remoteproxy/authentication/authenticationreply.cpp +++ b/libnymea-remoteproxy/authentication/authenticationreply.cpp @@ -64,6 +64,7 @@ void AuthenticationReply::setError(Authenticator::AuthenticationError error) void AuthenticationReply::setFinished() { m_timer->stop(); + // emit in next event loop QTimer::singleShot(0, this, &AuthenticationReply::finished); } diff --git a/libnymea-remoteproxy/authentication/dummy/dummyauthenticator.cpp b/libnymea-remoteproxy/authentication/dummy/dummyauthenticator.cpp index ef73ce5..fb1b760 100644 --- a/libnymea-remoteproxy/authentication/dummy/dummyauthenticator.cpp +++ b/libnymea-remoteproxy/authentication/dummy/dummyauthenticator.cpp @@ -41,7 +41,7 @@ AuthenticationReply *DummyAuthenticator::authenticate(ProxyClient *proxyClient) { qCDebug(dcAuthentication()) << name() << "validate" << proxyClient; qCWarning(dcAuthentication()) << "Attention: This authenticator will always succeed! This is a security risk and was explicitly enabled!"; - AuthenticationReply *reply = createAuthenticationReply(proxyClient, this); + AuthenticationReply *reply = createAuthenticationReply(proxyClient, proxyClient); proxyClient->setUserName("dummy@example.com"); diff --git a/tests/test-offline/nymea-remoteproxy-tests-offline.cpp b/tests/test-offline/nymea-remoteproxy-tests-offline.cpp index 76a8d3e..fc7b240 100644 --- a/tests/test-offline/nymea-remoteproxy-tests-offline.cpp +++ b/tests/test-offline/nymea-remoteproxy-tests-offline.cpp @@ -950,6 +950,14 @@ void RemoteProxyOfflineTests::authenticationReplyConnection() // Start the server startServer(); + // Configure result (authentication takes longer than json rpc timeout + m_mockAuthenticator->setExpectedAuthenticationError(); + m_mockAuthenticator->setTimeoutDuration(1000); + + m_configuration->setAuthenticationTimeout(500); + m_configuration->setJsonRpcTimeout(1000); + m_configuration->setInactiveTimeout(1000); + RemoteProxyConnection *connection = new RemoteProxyConnection(QUuid::createUuid(), "Sleepy test client", this); connect(connection, &RemoteProxyConnection::sslErrors, this, &BaseTest::ignoreConnectionSslError); @@ -959,14 +967,6 @@ void RemoteProxyOfflineTests::authenticationReplyConnection() connectionReadySpy.wait(); QVERIFY(connectionReadySpy.count() == 1); - // Configure result (authentication takes longer than json rpc timeout - m_mockAuthenticator->setExpectedAuthenticationError(); - m_mockAuthenticator->setTimeoutDuration(1000); - - m_configuration->setAuthenticationTimeout(500); - m_configuration->setJsonRpcTimeout(1000); - m_configuration->setInactiveTimeout(1000); - QSignalSpy connectionErrorSpy(connection, &RemoteProxyConnection::errorOccured); connection->authenticate("blub"); connectionErrorSpy.wait(); diff --git a/tests/testbase/mockauthenticator.cpp b/tests/testbase/mockauthenticator.cpp index cea9385..07d1097 100644 --- a/tests/testbase/mockauthenticator.cpp +++ b/tests/testbase/mockauthenticator.cpp @@ -60,9 +60,10 @@ AuthenticationReply *MockAuthenticator::authenticate(ProxyClient *proxyClient) { qCDebug(dcAuthentication()) << name() << "Start authentication for" << proxyClient << "using token" << proxyClient->token(); - AuthenticationReply *authenticationReply = createAuthenticationReply(proxyClient, this); + AuthenticationReply *authenticationReply = createAuthenticationReply(proxyClient, proxyClient); - MockAuthenticationReply *reply = new MockAuthenticationReply(m_timeoutDuration, m_expectedError, authenticationReply, this); + // Create mock authentication reply with the given configuration + MockAuthenticationReply *reply = new MockAuthenticationReply(m_timeoutDuration, m_expectedError, authenticationReply, proxyClient); connect(reply, &MockAuthenticationReply::finished, this, &MockAuthenticator::replyFinished); return authenticationReply; diff --git a/tests/testbase/mockauthenticator.h b/tests/testbase/mockauthenticator.h index 8259f15..b8c4c97 100644 --- a/tests/testbase/mockauthenticator.h +++ b/tests/testbase/mockauthenticator.h @@ -40,7 +40,7 @@ public: private: Authenticator::AuthenticationError m_error; - AuthenticationReply *m_authenticationReply; + AuthenticationReply *m_authenticationReply = nullptr; signals: void finished();