From 7d6963b45998a2a6cae34f8ec27c3a1b644e0ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Tue, 3 Sep 2019 11:48:13 +0200 Subject: [PATCH 1/2] Fix mock authenticator --- .../authentication/authenticationreply.cpp | 2 ++ .../authentication/dummy/dummyauthenticator.cpp | 2 +- .../nymea-remoteproxy-tests-offline.cpp | 16 ++++++++-------- tests/testbase/mockauthenticator.cpp | 5 +++-- tests/testbase/mockauthenticator.h | 2 +- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/libnymea-remoteproxy/authentication/authenticationreply.cpp b/libnymea-remoteproxy/authentication/authenticationreply.cpp index 7abcf61..3a26dca 100644 --- a/libnymea-remoteproxy/authentication/authenticationreply.cpp +++ b/libnymea-remoteproxy/authentication/authenticationreply.cpp @@ -64,6 +64,8 @@ void AuthenticationReply::setError(Authenticator::AuthenticationError error) void AuthenticationReply::setFinished() { m_timer->stop(); + + //emit finished(); // 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(); From 530fa4185620173bd8ed452ba8bb39f45fac26a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Tue, 3 Sep 2019 11:50:46 +0200 Subject: [PATCH 2/2] Clean up comments from debugging --- libnymea-remoteproxy/authentication/authenticationreply.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libnymea-remoteproxy/authentication/authenticationreply.cpp b/libnymea-remoteproxy/authentication/authenticationreply.cpp index 3a26dca..eac8d05 100644 --- a/libnymea-remoteproxy/authentication/authenticationreply.cpp +++ b/libnymea-remoteproxy/authentication/authenticationreply.cpp @@ -65,7 +65,6 @@ void AuthenticationReply::setFinished() { m_timer->stop(); - //emit finished(); // emit in next event loop QTimer::singleShot(0, this, &AuthenticationReply::finished); }