Merge PR #11: Fix mock authenticator for tests

This commit is contained in:
Jenkins 2019-09-14 00:58:46 +02:00
commit b864fb8275
5 changed files with 14 additions and 12 deletions

View File

@ -64,6 +64,7 @@ void AuthenticationReply::setError(Authenticator::AuthenticationError error)
void AuthenticationReply::setFinished() void AuthenticationReply::setFinished()
{ {
m_timer->stop(); m_timer->stop();
// emit in next event loop // emit in next event loop
QTimer::singleShot(0, this, &AuthenticationReply::finished); QTimer::singleShot(0, this, &AuthenticationReply::finished);
} }

View File

@ -41,7 +41,7 @@ AuthenticationReply *DummyAuthenticator::authenticate(ProxyClient *proxyClient)
{ {
qCDebug(dcAuthentication()) << name() << "validate" << proxyClient; qCDebug(dcAuthentication()) << name() << "validate" << proxyClient;
qCWarning(dcAuthentication()) << "Attention: This authenticator will always succeed! This is a security risk and was explicitly enabled!"; 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"); proxyClient->setUserName("dummy@example.com");

View File

@ -950,6 +950,14 @@ void RemoteProxyOfflineTests::authenticationReplyConnection()
// Start the server // Start the server
startServer(); 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); RemoteProxyConnection *connection = new RemoteProxyConnection(QUuid::createUuid(), "Sleepy test client", this);
connect(connection, &RemoteProxyConnection::sslErrors, this, &BaseTest::ignoreConnectionSslError); connect(connection, &RemoteProxyConnection::sslErrors, this, &BaseTest::ignoreConnectionSslError);
@ -959,14 +967,6 @@ void RemoteProxyOfflineTests::authenticationReplyConnection()
connectionReadySpy.wait(); connectionReadySpy.wait();
QVERIFY(connectionReadySpy.count() == 1); 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); QSignalSpy connectionErrorSpy(connection, &RemoteProxyConnection::errorOccured);
connection->authenticate("blub"); connection->authenticate("blub");
connectionErrorSpy.wait(); connectionErrorSpy.wait();

View File

@ -60,9 +60,10 @@ AuthenticationReply *MockAuthenticator::authenticate(ProxyClient *proxyClient)
{ {
qCDebug(dcAuthentication()) << name() << "Start authentication for" << proxyClient << "using token" << proxyClient->token(); 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); connect(reply, &MockAuthenticationReply::finished, this, &MockAuthenticator::replyFinished);
return authenticationReply; return authenticationReply;

View File

@ -40,7 +40,7 @@ public:
private: private:
Authenticator::AuthenticationError m_error; Authenticator::AuthenticationError m_error;
AuthenticationReply *m_authenticationReply; AuthenticationReply *m_authenticationReply = nullptr;
signals: signals:
void finished(); void finished();