AusweisApp2/test/qt/core/test_CertificateChecker.cpp

52 lines
1.3 KiB
C++
Raw Normal View History

2017-07-03 09:30:10 +02:00
/*!
* \brief Unit tests for \ref CertificateChecker
*
2018-03-28 15:10:51 +02:00
* \copyright Copyright (c) 2015-2018 Governikus GmbH & Co. KG, Germany
2017-07-03 09:30:10 +02:00
*/
2017-12-20 14:54:05 +01:00
#include "CertificateChecker.h"
2017-09-15 10:23:30 +02:00
#include "context/AuthContext.h"
2017-07-03 09:30:10 +02:00
#include "SecureStorage.h"
#include "MockActivationContext.h"
#include <QtTest>
using namespace governikus;
class test_CertificateChecker
: public QObject
{
Q_OBJECT
QVector<QSslCertificate> certs;
private Q_SLOTS:
void initTestCase()
{
2017-12-20 14:54:05 +01:00
certs = SecureStorage::getInstance().getUpdateCertificates();
2017-07-03 09:30:10 +02:00
QVERIFY(certs.size() > 0);
}
void validUpdateCert()
{
2017-12-20 14:54:05 +01:00
const QSharedPointer<AuthContext> model(new AuthContext(QSharedPointer<MockActivationContext>::create()));
std::function<void(const QUrl&, const QSslCertificate&)> saveCertificateFunc = [&model]
(const QUrl& pUrl, const QSslCertificate& pCert)
{
model->addCertificateData(pUrl, pCert);
};
2017-07-03 09:30:10 +02:00
QCOMPARE(model->getCertificateList().size(), 0);
2017-12-20 14:54:05 +01:00
QCOMPARE(CertificateChecker::checkAndSaveCertificate(certs.at(0), QUrl("dummy"), model->getDidAuthenticateEac1(), model->getDvCvc(), saveCertificateFunc), CertificateChecker::CertificateStatus::Good);
2017-07-03 09:30:10 +02:00
QCOMPARE(model->getCertificateList().size(), 1);
}
};
QTEST_GUILESS_MAIN(test_CertificateChecker)
#include "test_CertificateChecker.moc"