andre@304: #include "nsstest.h" andre@304: #include "nssstore.h" andre@304: #include "strhelp.h" andre@304: andre@304: #include andre@304: andre@304: void NSSTest::initTestCase() { andre@304: /* Copy the empty nss db in the temporary dir */ andre@304: QFile::copy(":/nss/cert8.db", nssDir.path() + "/" +"cert8.db"); andre@304: QFile::copy(":/nss/key3.db", nssDir.path() + "/" +"key3.db"); andre@304: QFile::copy(":/nss/secmod.db", nssDir.path() + "/" +"secmod.db"); andre@304: andre@304: QVERIFY(QFile::setPermissions(nssDir.path() + "/" +"cert8.db", andre@304: QFileDevice::ReadOwner | QFileDevice::WriteOwner)); andre@304: QVERIFY(QFile::setPermissions(nssDir.path() + "/" +"key3.db", andre@304: QFileDevice::ReadOwner | QFileDevice::WriteOwner)); andre@304: QVERIFY(QFile::setPermissions(nssDir.path() + "/" +"secmod.db", andre@304: QFileDevice::ReadOwner | QFileDevice::WriteOwner)); andre@304: andre@304: /* Set up a temporary list */ andre@304: QFile res(":/list-valid-signed.txt"); andre@304: res.open(QIODevice::ReadOnly); andre@304: validListFile.open(); andre@304: validListFile.write(res.readAll()); andre@304: validListFile.close(); andre@304: andre@304: nssDir.setAutoRemove(false); andre@304: andre@304: validList = CertificateList(validListFile.fileName().toLocal8Bit().data()); andre@304: andre@304: /* Create the profiles.ini `s set environment variables*/ andre@304: #ifndef WIN32 andre@304: QVERIFY(!setenv ("HOME", fakeHome.path().toLocal8Bit().constData(), 1)); andre@304: fakeFirefoxDir = QDir(fakeHome.path() + "/.mozilla/firefox"); andre@304: fakeThunderbirdDir = QDir(fakeHome.path() + "/.thunderbird"); andre@304: #else andre@304: QVERIFY(!setenv ("APPDATA", fakeHome.path().toLocal8Bit().constData(), 1)); andre@304: fakeFirefoxDir = QDir(fakeHome.path() + "/Mozilla/firefox"); andre@304: fakeThunderbirdDir = QDir(fakeHome.path() + "/Thunderbird"); andre@304: #endif andre@304: QVERIFY(fakeFirefoxDir.mkpath(fakeFirefoxDir.path())); andre@304: QVERIFY(fakeThunderbirdDir.mkpath(fakeThunderbirdDir.path())); andre@304: andre@304: QFile mozProfile(fakeFirefoxDir.absoluteFilePath("profiles.ini")); andre@304: QFile tbProfile(fakeThunderbirdDir.absoluteFilePath("profiles.ini")); andre@304: andre@304: /* Write profiles */ andre@304: QVERIFY(mozProfile.open(QIODevice::WriteOnly)); andre@304: QTextStream ffStream(&mozProfile); andre@304: ffStream << endl << "[General]"<< andre@304: "StartWithLastProfile=1" << endl << andre@304: "[Profile0]" << endl << andre@304: "Name=default" << endl << andre@304: "IsRelative=1" << endl << andre@304: "Path=" << fakeFirefoxDir.relativeFilePath(nssDir.path()) << endl; andre@304: ffStream.flush(); andre@304: mozProfile.close(); andre@304: andre@304: QVERIFY(tbProfile.open(QIODevice::WriteOnly)); andre@304: QTextStream tbStream(&tbProfile); andre@304: tbStream << endl << "[General]"<< andre@304: "StartWithLastProfile=1" << endl << andre@304: "[Profile102]" << endl << andre@304: "Name=default" << endl << andre@304: "IsRelative=0" << endl << andre@304: "Path=" << nssDir.path() << endl; andre@304: tbStream.flush(); andre@304: tbProfile.close(); andre@304: } andre@304: andre@304: void NSSTest::testInstRemove() { andre@304: char ** to_install = NULL, andre@304: ** to_remove = NULL; andre@304: andre@304: QList instList; andre@304: andre@304: foreach (const Certificate &cert, validList.getCertificates()) { andre@304: if (!cert.isInstallCert()) andre@304: continue; andre@304: instList << cert; andre@304: strv_append (&to_install, cert.base64Line().toLatin1().constData() + 2, andre@304: cert.base64Line().size() - 2); andre@304: } andre@304: QVERIFY((size_t) instList.size() == strv_length(to_install)); andre@304: andre@304: write_stores_nss(to_install, to_remove); andre@304: } andre@304: andre@304: QTEST_GUILESS_MAIN (NSSTest);