diff ui/tests/nsstest.cpp @ 304:eecc06f714fd

Add first nsstest.
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 03 Apr 2014 14:29:49 +0200
parents
children 4a3febc6d806
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/tests/nsstest.cpp	Thu Apr 03 14:29:49 2014 +0200
@@ -0,0 +1,89 @@
+#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));
+
+    write_stores_nss(to_install, to_remove);
+}
+
+QTEST_GUILESS_MAIN (NSSTest);

http://wald.intevation.org/projects/trustbridge/