comparison 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
comparison
equal deleted inserted replaced
303:b54ab152a57e 304:eecc06f714fd
1 #include "nsstest.h"
2 #include "nssstore.h"
3 #include "strhelp.h"
4
5 #include <QTest>
6
7 void NSSTest::initTestCase() {
8 /* Copy the empty nss db in the temporary dir */
9 QFile::copy(":/nss/cert8.db", nssDir.path() + "/" +"cert8.db");
10 QFile::copy(":/nss/key3.db", nssDir.path() + "/" +"key3.db");
11 QFile::copy(":/nss/secmod.db", nssDir.path() + "/" +"secmod.db");
12
13 QVERIFY(QFile::setPermissions(nssDir.path() + "/" +"cert8.db",
14 QFileDevice::ReadOwner | QFileDevice::WriteOwner));
15 QVERIFY(QFile::setPermissions(nssDir.path() + "/" +"key3.db",
16 QFileDevice::ReadOwner | QFileDevice::WriteOwner));
17 QVERIFY(QFile::setPermissions(nssDir.path() + "/" +"secmod.db",
18 QFileDevice::ReadOwner | QFileDevice::WriteOwner));
19
20 /* Set up a temporary list */
21 QFile res(":/list-valid-signed.txt");
22 res.open(QIODevice::ReadOnly);
23 validListFile.open();
24 validListFile.write(res.readAll());
25 validListFile.close();
26
27 nssDir.setAutoRemove(false);
28
29 validList = CertificateList(validListFile.fileName().toLocal8Bit().data());
30
31 /* Create the profiles.ini `s set environment variables*/
32 #ifndef WIN32
33 QVERIFY(!setenv ("HOME", fakeHome.path().toLocal8Bit().constData(), 1));
34 fakeFirefoxDir = QDir(fakeHome.path() + "/.mozilla/firefox");
35 fakeThunderbirdDir = QDir(fakeHome.path() + "/.thunderbird");
36 #else
37 QVERIFY(!setenv ("APPDATA", fakeHome.path().toLocal8Bit().constData(), 1));
38 fakeFirefoxDir = QDir(fakeHome.path() + "/Mozilla/firefox");
39 fakeThunderbirdDir = QDir(fakeHome.path() + "/Thunderbird");
40 #endif
41 QVERIFY(fakeFirefoxDir.mkpath(fakeFirefoxDir.path()));
42 QVERIFY(fakeThunderbirdDir.mkpath(fakeThunderbirdDir.path()));
43
44 QFile mozProfile(fakeFirefoxDir.absoluteFilePath("profiles.ini"));
45 QFile tbProfile(fakeThunderbirdDir.absoluteFilePath("profiles.ini"));
46
47 /* Write profiles */
48 QVERIFY(mozProfile.open(QIODevice::WriteOnly));
49 QTextStream ffStream(&mozProfile);
50 ffStream << endl << "[General]"<<
51 "StartWithLastProfile=1" << endl <<
52 "[Profile0]" << endl <<
53 "Name=default" << endl <<
54 "IsRelative=1" << endl <<
55 "Path=" << fakeFirefoxDir.relativeFilePath(nssDir.path()) << endl;
56 ffStream.flush();
57 mozProfile.close();
58
59 QVERIFY(tbProfile.open(QIODevice::WriteOnly));
60 QTextStream tbStream(&tbProfile);
61 tbStream << endl << "[General]"<<
62 "StartWithLastProfile=1" << endl <<
63 "[Profile102]" << endl <<
64 "Name=default" << endl <<
65 "IsRelative=0" << endl <<
66 "Path=" << nssDir.path() << endl;
67 tbStream.flush();
68 tbProfile.close();
69 }
70
71 void NSSTest::testInstRemove() {
72 char ** to_install = NULL,
73 ** to_remove = NULL;
74
75 QList<Certificate> instList;
76
77 foreach (const Certificate &cert, validList.getCertificates()) {
78 if (!cert.isInstallCert())
79 continue;
80 instList << cert;
81 strv_append (&to_install, cert.base64Line().toLatin1().constData() + 2,
82 cert.base64Line().size() - 2);
83 }
84 QVERIFY((size_t) instList.size() == strv_length(to_install));
85
86 write_stores_nss(to_install, to_remove);
87 }
88
89 QTEST_GUILESS_MAIN (NSSTest);

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