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

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