Mercurial > trustbridge
view ui/tests/nsstest.cpp @ 306:9c5e6b142611
Set the home directory to a temporary location to avoid writing into real nss stores
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 03 Apr 2014 15:30:25 +0200 |
parents | 4a3febc6d806 |
children | 2fd69803d219 |
line wrap: on
line source
#include "nsstest.h" #include "nssstore.h" #include "strhelp.h" #include <QTest> void NSSTest::initTestCase() { /* Copy the empty nss db in the temporary dir */ QFile::copy(":/nss/cert8.db", nssDir.path() + "/" +"cert8.db"); QFile::copy(":/nss/key3.db", nssDir.path() + "/" +"key3.db"); QFile::copy(":/nss/secmod.db", nssDir.path() + "/" +"secmod.db"); QVERIFY(QFile::setPermissions(nssDir.path() + "/" +"cert8.db", QFileDevice::ReadOwner | QFileDevice::WriteOwner)); QVERIFY(QFile::setPermissions(nssDir.path() + "/" +"key3.db", QFileDevice::ReadOwner | QFileDevice::WriteOwner)); QVERIFY(QFile::setPermissions(nssDir.path() + "/" +"secmod.db", QFileDevice::ReadOwner | QFileDevice::WriteOwner)); /* Set up a temporary list */ QFile res(":/list-valid-signed.txt"); res.open(QIODevice::ReadOnly); validListFile.open(); validListFile.write(res.readAll()); validListFile.close(); nssDir.setAutoRemove(false); validList = CertificateList(validListFile.fileName().toLocal8Bit().data()); /* Create the profiles.ini `s set environment variables*/ #ifndef WIN32 QVERIFY(!setenv ("HOME", fakeHome.path().toLocal8Bit().constData(), 1)); fakeFirefoxDir = QDir(fakeHome.path() + "/.mozilla/firefox"); fakeThunderbirdDir = QDir(fakeHome.path() + "/.thunderbird"); #else QVERIFY(!setenv ("APPDATA", fakeHome.path().toLocal8Bit().constData(), 1)); fakeFirefoxDir = QDir(fakeHome.path() + "/Mozilla/firefox"); fakeThunderbirdDir = QDir(fakeHome.path() + "/Thunderbird"); #endif QVERIFY(fakeFirefoxDir.mkpath(fakeFirefoxDir.path())); QVERIFY(fakeThunderbirdDir.mkpath(fakeThunderbirdDir.path())); QFile mozProfile(fakeFirefoxDir.absoluteFilePath("profiles.ini")); QFile tbProfile(fakeThunderbirdDir.absoluteFilePath("profiles.ini")); /* Write profiles */ QVERIFY(mozProfile.open(QIODevice::WriteOnly)); QTextStream ffStream(&mozProfile); ffStream << endl << "[General]"<< "StartWithLastProfile=1" << endl << "[Profile0]" << endl << "Name=default" << endl << "IsRelative=1" << endl << "Path=" << fakeFirefoxDir.relativeFilePath(nssDir.path()) << endl; ffStream.flush(); mozProfile.close(); QVERIFY(tbProfile.open(QIODevice::WriteOnly)); QTextStream tbStream(&tbProfile); tbStream << endl << "[General]"<< "StartWithLastProfile=1" << endl << "[Profile102]" << endl << "Name=default" << endl << "IsRelative=0" << endl << "Path=" << nssDir.path() << endl; tbStream.flush(); tbProfile.close(); } void NSSTest::testInstRemove() { char ** to_install = NULL, ** to_remove = NULL; QList<Certificate> instList; foreach (const Certificate &cert, validList.getCertificates()) { if (!cert.isInstallCert()) continue; instList << cert; strv_append (&to_install, cert.base64Line().toLatin1().constData() + 2, cert.base64Line().size() - 2); } QVERIFY((size_t) instList.size() == strv_length(to_install)); QVERIFY(write_stores_nss(to_install, to_remove) == 0); } QTEST_GUILESS_MAIN (NSSTest);