annotate ui/tests/nsstest.cpp @ 314:5e4ae994a320

Make buffer size for fakeHome environment variable dynamic. %TMP% can get ridicoulously long on windows.
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 04 Apr 2014 11:05:44 +0000
parents 2fd69803d219
children ad28f6b60e6b
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>
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
13
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
14 QList<QByteArray> NSSTest::get_nss_certs (QTemporaryDir *nssDir)
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
15 {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
16 CERTCertList *list;
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
17 CERTCertListNode *node;
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
18 QList<QByteArray> retval;
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
19
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
20 if (NSS_Initialize(nssDir->path().toLocal8Bit().constData(),
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
21 "", "", "secmod.db", NSS_INIT_READONLY)
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
22 == SECSuccess)
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
23 {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
24 list = PK11_ListCerts(PK11CertListAll, NULL);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
25 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
26 node = CERT_LIST_NEXT(node)) {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
27 retval << QByteArray((const char*)node->cert->derCert.data,
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
28 (int)node->cert->derCert.len);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
29 }
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
30 CERT_DestroyCertList(list);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
31 NSS_Shutdown();
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
32 }
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
33 else
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 qDebug("Could not open nss certificate store!\n");
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
36 }
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
37 return retval;
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
38 }
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 void NSSTest::setupTestDir(QTemporaryDir *nssDir)
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 /* Copy the empty nss db in the temporary dir */
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
43 QFile::copy(":/nss/cert8.db", nssDir->path() + "/" +"cert8.db");
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
44 QFile::copy(":/nss/key3.db", nssDir->path() + "/" +"key3.db");
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
45 QFile::copy(":/nss/secmod.db", nssDir->path() + "/" +"secmod.db");
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 QVERIFY(QFile::setPermissions(nssDir->path() + "/" +"cert8.db",
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
48 QFileDevice::ReadOwner | QFileDevice::WriteOwner));
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
49 QVERIFY(QFile::setPermissions(nssDir->path() + "/" +"key3.db",
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
50 QFileDevice::ReadOwner | QFileDevice::WriteOwner));
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
51 QVERIFY(QFile::setPermissions(nssDir->path() + "/" +"secmod.db",
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
52 QFileDevice::ReadOwner | QFileDevice::WriteOwner));
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
53 }
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
54
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
55 void NSSTest::initTestCase() {
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
56
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
57 /* Set up a temporary list */
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
58 QFile res(":/list-valid-signed.txt");
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
59 res.open(QIODevice::ReadOnly);
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
60 validListFile.open();
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
61 validListFile.write(res.readAll());
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
62 validListFile.close();
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
63
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
64 setupTestDir(&ffNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
65 setupTestDir(&tbNSSDir);
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
66
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
67 validList = CertificateList(validListFile.fileName().toLocal8Bit().data());
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
68
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
69 /* Create the profiles.ini `s set environment variables*/
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
70 #ifndef WIN32
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
71 QVERIFY(!setenv ("HOME", fakeHome.path().toLocal8Bit().constData(), 1));
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
72 fakeFirefoxDir = QDir(fakeHome.path() + "/.mozilla/firefox");
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
73 fakeThunderbirdDir = QDir(fakeHome.path() + "/.thunderbird");
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
74 #else
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
75 QVERIFY(!setenv ("APPDATA", fakeHome.path().toLocal8Bit().constData(), 1));
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
76 fakeFirefoxDir = QDir(fakeHome.path() + "/Mozilla/firefox");
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
77 fakeThunderbirdDir = QDir(fakeHome.path() + "/Thunderbird");
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
78 #endif
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
79 QVERIFY(fakeFirefoxDir.mkpath(fakeFirefoxDir.path()));
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
80 QVERIFY(fakeThunderbirdDir.mkpath(fakeThunderbirdDir.path()));
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
81
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
82 QFile mozProfile(fakeFirefoxDir.absoluteFilePath("profiles.ini"));
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
83 QFile tbProfile(fakeThunderbirdDir.absoluteFilePath("profiles.ini"));
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
84
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
85 /* Write profiles */
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
86 QVERIFY(mozProfile.open(QIODevice::WriteOnly));
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
87 QTextStream ffStream(&mozProfile);
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
88 ffStream << endl << "[General]"<<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
89 "StartWithLastProfile=1" << endl <<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
90 "[Profile0]" << endl <<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
91 "Name=default" << endl <<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
92 "IsRelative=1" << endl <<
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
93 "Path=" << fakeFirefoxDir.relativeFilePath(ffNSSDir.path()) << endl;
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
94 ffStream.flush();
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
95 mozProfile.close();
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
96
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
97 QVERIFY(tbProfile.open(QIODevice::WriteOnly));
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
98 QTextStream tbStream(&tbProfile);
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
99 tbStream << endl << "[General]"<<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
100 "StartWithLastProfile=1" << endl <<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
101 "[Profile102]" << endl <<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
102 "Name=default" << endl <<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
103 "IsRelative=0" << endl <<
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
104 "Path=" << tbNSSDir.path() << endl;
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
105 tbStream.flush();
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
106 tbProfile.close();
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
107 }
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
108
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
109 void NSSTest::testInstRemove() {
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
110 char ** to_install = NULL,
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
111 ** to_remove = NULL;
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
112
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
113 QList<Certificate> instList;
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
114
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
115 /* Install all certificates */
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
116 foreach (const Certificate &cert, validList.getCertificates()) {
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
117 if (!cert.isInstallCert())
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
118 continue;
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
119 instList << cert;
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
120 strv_append (&to_install, cert.base64Line().toLatin1().constData() + 2,
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
121 cert.base64Line().size() - 2);
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
122 }
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
123 QVERIFY((size_t) instList.size() == strv_length(to_install));
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
124
305
4a3febc6d806 Some minor cleanups. Better debug output more Verify's
Andre Heinecke <andre.heinecke@intevation.de>
parents: 304
diff changeset
125 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
126
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
127 {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
128 /* Verify that everything is installed */
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
129 QList<QByteArray> installedCertsFF = get_nss_certs(&ffNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
130 QList<QByteArray> installedCertsTB = get_nss_certs(&tbNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
131
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
132 QVERIFY(installedCertsFF.size() == instList.size());
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
133 QVERIFY(installedCertsFF == installedCertsTB);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
134
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
135 for (int i = 0; to_install[i]; i++) {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
136 QByteArray bai = QByteArray::fromBase64(to_install[i]);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
137 QVERIFY(installedCertsFF.contains(bai));
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
138 }
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
139 }
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
140
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
141 {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
142 /* Remove one certificate */
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
143 QVERIFY(instList.size() > 2);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
144 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
145
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
146 QVERIFY(write_stores_nss(NULL, to_remove) == 0);
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 QList<QByteArray> installedCertsFF = get_nss_certs(&ffNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
149 QList<QByteArray> installedCertsTB = get_nss_certs(&tbNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
150
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
151 QVERIFY(installedCertsFF == installedCertsTB);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
152
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
153 QByteArray bai = QByteArray::fromBase64(to_install[1]);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
154 QVERIFY(!installedCertsTB.contains(bai));
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
155
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
156 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
157
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
158 for (int i = 0; to_install[i]; i++) {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
159 if (i == 1) {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
160 continue;
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 QByteArray bai = QByteArray::fromBase64(to_install[i]);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
163 QVERIFY(installedCertsTB.contains(bai));
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
164 }
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
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 /* Readd all certificates check for duplication*/
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
169 QVERIFY(write_stores_nss(to_install, NULL) == 0);
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 QList<QByteArray> installedCertsFF = get_nss_certs(&ffNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
172 QList<QByteArray> installedCertsTB = get_nss_certs(&tbNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
173
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
174 QVERIFY(installedCertsFF == installedCertsTB);
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));
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 QByteArray bai = QByteArray::fromBase64(to_install[i]);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
180 QVERIFY(installedCertsTB.contains(bai));
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 }
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
183
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 /* Remove all certificates */
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
186 QVERIFY(write_stores_nss(NULL, to_install) == 0);
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 QList<QByteArray> installedCertsFF = get_nss_certs(&ffNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
189 QList<QByteArray> installedCertsTB = get_nss_certs(&tbNSSDir);
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 QVERIFY(installedCertsFF == installedCertsTB);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
192
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
193 QVERIFY(installedCertsTB.size() == 0);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
194 }
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
195 }
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
196
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
197 QTEST_GUILESS_MAIN (NSSTest);

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