AusweisApp2/test/qt/core/states/test_StateGenericSendReceive.cpp

148 lines
4.8 KiB
C++
Raw Normal View History

2017-07-03 09:30:10 +02:00
/*!
2018-03-28 15:10:51 +02:00
* \copyright Copyright (c) 2014-2018 Governikus GmbH & Co. KG, Germany
2017-07-03 09:30:10 +02:00
*/
#include "controller/AuthController.h"
2017-12-20 14:54:05 +01:00
#include "Env.h"
2017-07-03 09:30:10 +02:00
#include "paos/invoke/InitializeFrameworkResponse.h"
#include "paos/retrieve/InitializeFramework.h"
#include "states/StateBuilder.h"
#include "states/StateGenericSendReceive.h"
#include "MockNetworkManager.h"
2017-12-20 14:54:05 +01:00
#include "TestAuthContext.h"
#include "TestFileHelper.h"
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
#include <QtTest>
2017-07-03 09:30:10 +02:00
using namespace governikus;
class test_StateGenericSendReceive
: public QObject
{
Q_OBJECT
private:
QSharedPointer<StateSendInitializeFrameworkResponse> mState;
QSharedPointer<AuthContext> mAuthContext;
QPointer<MockNetworkManager> mNetworkManager;
Q_SIGNALS:
void fireStateStart(QEvent* pEvent);
private Q_SLOTS:
void init()
{
2017-07-03 09:33:28 +02:00
mAuthContext.reset(new TestAuthContext(nullptr, ":/paos/DIDAuthenticateEAC1.xml"));
2017-07-03 09:30:10 +02:00
2017-12-20 14:54:05 +01:00
QSharedPointer<TcToken> tcToken(new TcToken(TestFileHelper::readFile(":/tctoken/ok.xml")));
2017-07-03 09:30:10 +02:00
mAuthContext->setTcToken(tcToken);
mNetworkManager = new MockNetworkManager();
2017-12-20 14:54:05 +01:00
Env::set(NetworkManager::staticMetaObject, mNetworkManager.data());
2017-07-03 09:30:10 +02:00
mState.reset(StateBuilder::createState<StateSendInitializeFrameworkResponse>(mAuthContext));
mState->setStateName("StateSendInitializeFrameworkResponse");
connect(this, &test_StateGenericSendReceive::fireStateStart, mState.data(), &AbstractState::onEntry, Qt::ConnectionType::DirectConnection);
}
void connectionError()
{
MockNetworkReply reply;
reply.setNetworkError(QNetworkReply::ConnectionRefusedError, "forced connection refused");
mNetworkManager->setNextReply(&reply);
QSharedPointer<InitializeFrameworkResponse> initializeFrameworkResponse(new InitializeFrameworkResponse());
mAuthContext->setInitializeFrameworkResponse(initializeFrameworkResponse);
2017-12-20 14:54:05 +01:00
QSignalSpy spy(mState.data(), &StateGenericSendReceive::fireAbort);
2017-07-03 09:30:10 +02:00
Q_EMIT fireStateStart(nullptr);
mAuthContext->setStateApproved();
mNetworkManager->fireFinished();
QCOMPARE(spy.count(), 1);
}
void sendInitializeFrameworkResponse_receiveDIDList()
{
mNetworkManager->setFilename(":/paos/DIDList.xml");
QSharedPointer<InitializeFrameworkResponse> initializeFrameworkResponse(new InitializeFrameworkResponse());
mAuthContext->setInitializeFrameworkResponse(initializeFrameworkResponse);
2017-12-20 14:54:05 +01:00
QSignalSpy spy(mState.data(), &StateGenericSendReceive::fireContinue);
2017-07-03 09:30:10 +02:00
Q_EMIT fireStateStart(nullptr);
mAuthContext->setStateApproved();
mNetworkManager->fireFinished();
QCOMPARE(spy.count(), 1);
}
void sendInitializeFrameworkResponse_receiveDIDAuthenticateEAC1()
{
mNetworkManager->setFilename(":/paos/DIDAuthenticateEAC1.xml");
QSharedPointer<InitializeFrameworkResponse> initializeFrameworkResponse(new InitializeFrameworkResponse());
mAuthContext->setInitializeFrameworkResponse(initializeFrameworkResponse);
QSignalSpy spy(mState.data(), &StateSendInitializeFrameworkResponse::fireReceivedExtractCvcsFromEac1InputType);
Q_EMIT fireStateStart(nullptr);
mAuthContext->setStateApproved();
mNetworkManager->fireFinished();
QCOMPARE(spy.count(), 1);
}
void sendInitializeFrameworkResponse_unexpected()
{
mNetworkManager->setFilename(":/paos/Transmit.xml");
QSharedPointer<InitializeFrameworkResponse> initializeFrameworkResponse(new InitializeFrameworkResponse());
mAuthContext->setInitializeFrameworkResponse(initializeFrameworkResponse);
2017-12-20 14:54:05 +01:00
QSignalSpy spy(mState.data(), &StateGenericSendReceive::fireAbort);
2017-07-03 09:30:10 +02:00
Q_EMIT fireStateStart(nullptr);
mAuthContext->setStateApproved();
mNetworkManager->fireFinished();
QCOMPARE(spy.count(), 1);
}
2017-07-03 09:33:28 +02:00
void mappingToTrustedChannelError()
{
const QVector<GlobalStatus::Code> states = QVector<GlobalStatus::Code>()
<< GlobalStatus::Code::Workflow_TrustedChannel_Establishment_Error
<< GlobalStatus::Code::Workflow_TrustedChannel_Error_From_Server
<< GlobalStatus::Code::Workflow_TrustedChannel_Hash_Not_In_Description
<< GlobalStatus::Code::Workflow_TrustedChannel_No_Data_Received
<< GlobalStatus::Code::Workflow_TrustedChannel_Ssl_Certificate_Unsupported_Algorithm_Or_Length
<< GlobalStatus::Code::Workflow_TrustedChannel_TimeOut
<< GlobalStatus::Code::Workflow_TrustedChannel_Proxy_Error
<< GlobalStatus::Code::Workflow_TrustedChannel_Ssl_Establishment_Error
<< GlobalStatus::Code::Workflow_TrustedChannel_Server_Format_Error
<< GlobalStatus::Code::Workflow_TrustedChannel_Other_Network_Error;
for (const GlobalStatus::Code state : states)
{
const Result& result = Result(GlobalStatus(state));
QCOMPARE(result.getMinor(), GlobalStatus::Code::Paos_Error_DP_Trusted_Channel_Establishment_Failed);
}
}
2017-07-03 09:30:10 +02:00
void cleanup()
{
mAuthContext.reset();
mNetworkManager.clear();
}
};
QTEST_GUILESS_MAIN(test_StateGenericSendReceive)
#include "test_StateGenericSendReceive.moc"