Mercurial > trustbridge
annotate ui/tests/nsstest.cpp @ 396:26651cc0cc47
Remove all certificates if a new list is loaded from file.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 15 Apr 2014 16:45:37 +0200 |
parents | 6b78a89c1e17 |
children | 17e1c8f37d72 |
rev | line source |
---|---|
307
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
1 #include <cert.h> |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
2 #include <certdb.h> |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
3 #include <certt.h> |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
4 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
5 #include <nss.h> |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
6 #include <pk11pub.h> |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
7 |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 #include "nsstest.h" |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 #include "nssstore.h" |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 #include "strhelp.h" |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
11 |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 #include <QTest> |
330
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
326
diff
changeset
|
13 #include <QTextCodec> |
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
326
diff
changeset
|
14 |
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
326
diff
changeset
|
15 #ifdef WIN32 |
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
326
diff
changeset
|
16 #define endl "\r\n" |
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
326
diff
changeset
|
17 #endif |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 |
307
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
19 QList<QByteArray> NSSTest::get_nss_certs (QTemporaryDir *nssDir) |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
20 { |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
21 CERTCertList *list; |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
22 CERTCertListNode *node; |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
23 QList<QByteArray> retval; |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
24 |
307
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
25 if (NSS_Initialize(nssDir->path().toLocal8Bit().constData(), |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
26 "", "", "secmod.db", NSS_INIT_READONLY) |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
27 == SECSuccess) |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
28 { |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
29 list = PK11_ListCerts(PK11CertListAll, NULL); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
30 for (node = CERT_LIST_HEAD(list); !CERT_LIST_END(node, list); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
31 node = CERT_LIST_NEXT(node)) { |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
32 retval << QByteArray((const char*)node->cert->derCert.data, |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
33 (int)node->cert->derCert.len); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
34 } |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
35 CERT_DestroyCertList(list); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
36 NSS_Shutdown(); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
37 } |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
38 else |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
39 { |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
40 qDebug("Could not open nss certificate store!\n"); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
41 } |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
42 return retval; |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
43 } |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
44 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
45 void NSSTest::setupTestDir(QTemporaryDir *nssDir) |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
46 { |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
47 /* Copy the empty nss db in the temporary dir */ |
330
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
326
diff
changeset
|
48 QVERIFY(QFile::copy(":/nss/cert8.db", nssDir->path() + "/" +"cert8.db")); |
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
326
diff
changeset
|
49 QVERIFY(QFile::copy(":/nss/key3.db", nssDir->path() + "/" +"key3.db")); |
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
326
diff
changeset
|
50 QVERIFY(QFile::copy(":/nss/secmod.db", nssDir->path() + "/" +"secmod.db")); |
307
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
51 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
52 QVERIFY(QFile::setPermissions(nssDir->path() + "/" +"cert8.db", |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
53 QFileDevice::ReadOwner | QFileDevice::WriteOwner)); |
307
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
54 QVERIFY(QFile::setPermissions(nssDir->path() + "/" +"key3.db", |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
55 QFileDevice::ReadOwner | QFileDevice::WriteOwner)); |
307
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
56 QVERIFY(QFile::setPermissions(nssDir->path() + "/" +"secmod.db", |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
57 QFileDevice::ReadOwner | QFileDevice::WriteOwner)); |
346
a54925d41056
Enable autoremove again
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
58 // nssDir->setAutoRemove(false); |
307
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
59 } |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
60 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
61 void NSSTest::initTestCase() { |
330
1e6d1eab8395
Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents:
326
diff
changeset
|
62 QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); /* use system default */ |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
63 |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
64 /* Set up a temporary list */ |
371
6b78a89c1e17
Fix NSS test in release build and add verify's to avoid segfault with invalid list.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
346
diff
changeset
|
65 #ifdef RELEASE_BUILD |
6b78a89c1e17
Fix NSS test in release build and add verify's to avoid segfault with invalid list.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
346
diff
changeset
|
66 QFile res(":/list-valid-signed-release.txt"); |
6b78a89c1e17
Fix NSS test in release build and add verify's to avoid segfault with invalid list.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
346
diff
changeset
|
67 #else |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
68 QFile res(":/list-valid-signed.txt"); |
371
6b78a89c1e17
Fix NSS test in release build and add verify's to avoid segfault with invalid list.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
346
diff
changeset
|
69 #endif |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
70 res.open(QIODevice::ReadOnly); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
71 validListFile.open(); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
72 validListFile.write(res.readAll()); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
73 validListFile.close(); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
74 |
307
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
75 setupTestDir(&ffNSSDir); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
76 setupTestDir(&tbNSSDir); |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
77 |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
78 validList = CertificateList(validListFile.fileName().toLocal8Bit().data()); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
79 |
371
6b78a89c1e17
Fix NSS test in release build and add verify's to avoid segfault with invalid list.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
346
diff
changeset
|
80 QVERIFY(validList.isValid()); |
6b78a89c1e17
Fix NSS test in release build and add verify's to avoid segfault with invalid list.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
346
diff
changeset
|
81 |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
82 /* Create the profiles.ini `s set environment variables*/ |
346
a54925d41056
Enable autoremove again
Andre Heinecke <andre.heinecke@intevation.de>
parents:
330
diff
changeset
|
83 // fakeHome.setAutoRemove(false); |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
84 #ifndef WIN32 |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
85 QVERIFY(!setenv ("HOME", fakeHome.path().toLocal8Bit().constData(), 1)); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
86 fakeFirefoxDir = QDir(fakeHome.path() + "/.mozilla/firefox"); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
87 fakeThunderbirdDir = QDir(fakeHome.path() + "/.thunderbird"); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
88 #else |
326
ad28f6b60e6b
Fix nsstest build for windows
Andre Heinecke <aheinecke@intevation.de>
parents:
307
diff
changeset
|
89 { |
ad28f6b60e6b
Fix nsstest build for windows
Andre Heinecke <aheinecke@intevation.de>
parents:
307
diff
changeset
|
90 char buf[fakeHome.path().toLocal8Bit().size() + 9]; |
ad28f6b60e6b
Fix nsstest build for windows
Andre Heinecke <aheinecke@intevation.de>
parents:
307
diff
changeset
|
91 snprintf(buf, fakeHome.path().toLocal8Bit().size() + 9, |
ad28f6b60e6b
Fix nsstest build for windows
Andre Heinecke <aheinecke@intevation.de>
parents:
307
diff
changeset
|
92 "APPDATA=%s",fakeHome.path().toLocal8Bit().constData()); |
ad28f6b60e6b
Fix nsstest build for windows
Andre Heinecke <aheinecke@intevation.de>
parents:
307
diff
changeset
|
93 QVERIFY(_putenv (buf) != -1); |
ad28f6b60e6b
Fix nsstest build for windows
Andre Heinecke <aheinecke@intevation.de>
parents:
307
diff
changeset
|
94 } |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
95 fakeFirefoxDir = QDir(fakeHome.path() + "/Mozilla/firefox"); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
96 fakeThunderbirdDir = QDir(fakeHome.path() + "/Thunderbird"); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
97 #endif |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
98 QVERIFY(fakeFirefoxDir.mkpath(fakeFirefoxDir.path())); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
99 QVERIFY(fakeThunderbirdDir.mkpath(fakeThunderbirdDir.path())); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
100 |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
101 QFile mozProfile(fakeFirefoxDir.absoluteFilePath("profiles.ini")); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
102 QFile tbProfile(fakeThunderbirdDir.absoluteFilePath("profiles.ini")); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
103 |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
104 /* Write profiles */ |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
105 QVERIFY(mozProfile.open(QIODevice::WriteOnly)); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
106 QTextStream ffStream(&mozProfile); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
107 ffStream << endl << "[General]"<< |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
108 "StartWithLastProfile=1" << endl << |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
109 "[Profile0]" << endl << |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
110 "Name=default" << endl << |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
111 "IsRelative=1" << endl << |
307
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
112 "Path=" << fakeFirefoxDir.relativeFilePath(ffNSSDir.path()) << endl; |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
113 ffStream.flush(); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
114 mozProfile.close(); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
115 |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
116 QVERIFY(tbProfile.open(QIODevice::WriteOnly)); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
117 QTextStream tbStream(&tbProfile); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
118 tbStream << endl << "[General]"<< |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
119 "StartWithLastProfile=1" << endl << |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
120 "[Profile102]" << endl << |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
121 "Name=default" << endl << |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
122 "IsRelative=0" << endl << |
307
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
123 "Path=" << tbNSSDir.path() << endl; |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
124 tbStream.flush(); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
125 tbProfile.close(); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
126 } |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
127 |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
128 void NSSTest::testInstRemove() { |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
129 char ** to_install = NULL, |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
130 ** to_remove = NULL; |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
131 |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
132 QList<Certificate> instList; |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
133 |
307
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
134 /* Install all certificates */ |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
135 foreach (const Certificate &cert, validList.getCertificates()) { |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
136 if (!cert.isInstallCert()) |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
137 continue; |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
138 instList << cert; |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
139 strv_append (&to_install, cert.base64Line().toLatin1().constData() + 2, |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
140 cert.base64Line().size() - 2); |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
141 } |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
142 QVERIFY((size_t) instList.size() == strv_length(to_install)); |
371
6b78a89c1e17
Fix NSS test in release build and add verify's to avoid segfault with invalid list.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
346
diff
changeset
|
143 QVERIFY(strv_length(to_install) != 0); |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
144 |
305
4a3febc6d806
Some minor cleanups. Better debug output more Verify's
Andre Heinecke <andre.heinecke@intevation.de>
parents:
304
diff
changeset
|
145 QVERIFY(write_stores_nss(to_install, to_remove) == 0); |
4a3febc6d806
Some minor cleanups. Better debug output more Verify's
Andre Heinecke <andre.heinecke@intevation.de>
parents:
304
diff
changeset
|
146 |
307
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
147 { |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
148 /* Verify that everything is installed */ |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
149 QList<QByteArray> installedCertsFF = get_nss_certs(&ffNSSDir); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
150 QList<QByteArray> installedCertsTB = get_nss_certs(&tbNSSDir); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
151 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
152 QVERIFY(installedCertsFF.size() == instList.size()); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
153 QVERIFY(installedCertsFF == installedCertsTB); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
154 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
155 for (int i = 0; to_install[i]; i++) { |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
156 QByteArray bai = QByteArray::fromBase64(to_install[i]); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
157 QVERIFY(installedCertsFF.contains(bai)); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
158 } |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
159 } |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
160 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
161 { |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
162 /* Remove one certificate */ |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
163 QVERIFY(instList.size() > 2); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
164 strv_append (&to_remove, to_install[1], qstrlen(to_install[1])); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
165 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
166 QVERIFY(write_stores_nss(NULL, to_remove) == 0); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
167 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
168 QList<QByteArray> installedCertsFF = get_nss_certs(&ffNSSDir); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
169 QList<QByteArray> installedCertsTB = get_nss_certs(&tbNSSDir); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
170 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
171 QVERIFY(installedCertsFF == installedCertsTB); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
172 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
173 QByteArray bai = QByteArray::fromBase64(to_install[1]); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
174 QVERIFY(!installedCertsTB.contains(bai)); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
175 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
176 QVERIFY((size_t)installedCertsTB.size() == strv_length(to_install) - 1); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
177 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
178 for (int i = 0; to_install[i]; i++) { |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
179 if (i == 1) { |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
180 continue; |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
181 } |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
182 QByteArray bai = QByteArray::fromBase64(to_install[i]); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
183 QVERIFY(installedCertsTB.contains(bai)); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
184 } |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
185 } |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
186 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
187 { |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
188 /* Readd all certificates check for duplication*/ |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
189 QVERIFY(write_stores_nss(to_install, NULL) == 0); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
190 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
191 QList<QByteArray> installedCertsFF = get_nss_certs(&ffNSSDir); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
192 QList<QByteArray> installedCertsTB = get_nss_certs(&tbNSSDir); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
193 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
194 QVERIFY(installedCertsFF == installedCertsTB); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
195 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
196 QVERIFY((size_t)installedCertsTB.size() == strv_length(to_install)); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
197 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
198 for (int i = 0; to_install[i]; i++) { |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
199 QByteArray bai = QByteArray::fromBase64(to_install[i]); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
200 QVERIFY(installedCertsTB.contains(bai)); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
201 } |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
202 } |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
203 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
204 { |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
205 /* Remove all certificates */ |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
206 QVERIFY(write_stores_nss(NULL, to_install) == 0); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
207 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
208 QList<QByteArray> installedCertsFF = get_nss_certs(&ffNSSDir); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
209 QList<QByteArray> installedCertsTB = get_nss_certs(&tbNSSDir); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
210 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
211 QVERIFY(installedCertsFF == installedCertsTB); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
212 |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
213 QVERIFY(installedCertsTB.size() == 0); |
2fd69803d219
Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents:
305
diff
changeset
|
214 } |
304
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
215 } |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
216 |
eecc06f714fd
Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
217 QTEST_GUILESS_MAIN (NSSTest); |