1 /*!
2  * \brief Unit tests for \ref GlobalStatus.
3  *
4  * \copyright Copyright (c) 2018-2021 Governikus GmbH & Co. KG, Germany
5  */
6 
7 #include "GlobalStatus.h"
8 
9 #include <QtTest>
10 
11 using namespace governikus;
12 
13 
14 class test_GlobalStatus
15 	: public QObject
16 {
17 	Q_OBJECT
18 
19 	private Q_SLOTS:
test_Is()20 		void test_Is()
21 		{
22 			GlobalStatus status;
23 
24 			QVERIFY(status.is(GlobalStatus::Code::Unknown_Error));
25 			QVERIFY(!status.is(GlobalStatus::Code::Downloader_Cannot_Save_File));
26 		}
27 
28 
test_IsCancellationByUser()29 		void test_IsCancellationByUser()
30 		{
31 			GlobalStatus status1;
32 			GlobalStatus status2(GlobalStatus::Code::Workflow_Cancellation_By_User, Origin::Client);
33 			GlobalStatus status3(GlobalStatus::Code::Card_Cancellation_By_User, Origin::Client);
34 			GlobalStatus status4(GlobalStatus::Code::Paos_Error_SAL_Cancellation_by_User, Origin::Client);
35 
36 			QVERIFY(!status1.isCancellationByUser());
37 			QVERIFY(status2.isCancellationByUser());
38 			QVERIFY(status3.isCancellationByUser());
39 			QVERIFY(status4.isCancellationByUser());
40 		}
41 
42 
test_ToDescriptionError_data()43 		void test_ToDescriptionError_data()
44 		{
45 			QTest::addColumn<GlobalStatus::Code>("code");
46 			QTest::addColumn<QString>("message");
47 
48 			QTest::newRow("inProgress") << GlobalStatus::Code::Workflow_AlreadyInProgress_Error << tr("Cannot start authentication. An operation is already active.");
49 			QTest::newRow("cardRemoved") << GlobalStatus::Code::Workflow_Card_Removed << tr("The connection to the ID card has been lost. The process was aborted.");
50 			QTest::newRow("unknownPaos") << GlobalStatus::Code::Workflow_Unknown_Paos_From_EidServer << tr("The program received an unknown message from the server.");
51 			QTest::newRow("unexpectedMessage") << GlobalStatus::Code::Workflow_Unexpected_Message_From_EidServer << tr("The program received an unexpected message from the server.");
52 			QTest::newRow("preverificationDevelopermode") << GlobalStatus::Code::Workflow_Preverification_Developermode_Error << tr("Using the developer mode is only allowed in a test environment.");
53 			QTest::newRow("noUniqueAtCvc") << GlobalStatus::Code::Workflow_No_Unique_AtCvc << tr("No unique AT CVC");
54 			QTest::newRow("noUniqueDvCvc") << GlobalStatus::Code::Workflow_No_Unique_DvCvc << tr("No unique DV CVC");
55 			QTest::newRow("noPermission") << GlobalStatus::Code::Workflow_No_Permission_Error << tr("Authentication failed.");
56 			QTest::newRow("certificateNoDescription") << GlobalStatus::Code::Workflow_Certificate_No_Description << tr("No certificate description available.");
57 			QTest::newRow("certificateNoUrl") << GlobalStatus::Code::Workflow_Certificate_No_Url_In_Description << tr("No subject url available in certificate description.");
58 			QTest::newRow("hashError") << GlobalStatus::Code::Workflow_Certificate_Hash_Error << tr("The certificate description does not match the certificate.");
59 			QTest::newRow("certificateSop") << GlobalStatus::Code::Workflow_Certificate_Sop_Error << tr("The subject URL in the certificate description and the TCToken URL do not satisfy the same origin policy.");
60 			QTest::newRow("wrongParameter") << GlobalStatus::Code::Workflow_Wrong_Parameter_Invocation << tr("Application was invoked with wrong parameters.");
61 			QTest::newRow("incompleteInformation") << GlobalStatus::Code::Workflow_Server_Incomplete_Information_Provided << tr("The server provided no or incomplete information. Your personal data could not be read out.");
62 			QTest::newRow("abnormalClose") << GlobalStatus::Code::RemoteReader_CloseCode_AbnormalClose << tr("The smartphone as card reader (SaC) connection was aborted.");
63 			QTest::newRow("invalidRequest") << GlobalStatus::Code::RemoteConnector_InvalidRequest << tr("Smartphone as card reader (SaC) connection request was invalid.");
64 			QTest::newRow("noSupportedApiLevel") << GlobalStatus::Code::RemoteConnector_NoSupportedApiLevel << tr("Your smartphone as card reader (SaC) version is incompatible with the local version. Please install the latest AusweisApp2 version on both your smartphone and your computer.");
65 			QTest::newRow("connectionTimeout") << GlobalStatus::Code::RemoteConnector_ConnectionTimeout << tr("A timeout occurred while trying to establish a connection to the smartphone as card reader (SaC).");
66 			QTest::newRow("connectionError") << GlobalStatus::Code::RemoteConnector_ConnectionError << tr("An error occurred while trying to establish a connection to the smartphone as card reader (SaC).");
67 			QTest::newRow("hostRefused") << GlobalStatus::Code::RemoteConnector_RemoteHostRefusedConnection << tr("The smartphone to be paired has rejected the connection. Please check the pairing code. If no pairing code is shown activate the pairing mode.");
68 			QTest::newRow("fileNotFound") << GlobalStatus::Code::Downloader_File_Not_Found << tr("File not found.");
69 			QTest::newRow("cannotSaveFile") << GlobalStatus::Code::Downloader_Cannot_Save_File << tr("Cannot save file.");
70 			QTest::newRow("dataCorrupted") << GlobalStatus::Code::Downloader_Data_Corrupted << tr("Received data were corrupted.");
71 			QTest::newRow("missingPlatform") << GlobalStatus::Code::Downloader_Missing_Platform << tr("Received data does not contain data for the current platform.");
72 			QTest::newRow("downloadAborted") << GlobalStatus::Code::Downloader_Aborted << tr("Download aborted.");
73 			QTest::newRow("updateFailed") << GlobalStatus::Code::Update_Execution_Failed << tr("A new process to start the update could not be launched.");
74 		}
75 
76 
test_ToDescriptionError()77 		void test_ToDescriptionError()
78 		{
79 			QFETCH(GlobalStatus::Code, code);
80 			QFETCH(QString, message);
81 
82 			GlobalStatus status(code, Origin::Client);
83 
84 			QCOMPARE(status.toErrorDescription(false), message);
85 		}
86 
87 
88 };
89 
90 QTEST_GUILESS_MAIN(test_GlobalStatus)
91 #include "test_GlobalStatus.moc"
92