annotate ui/tests/nsstest.cpp @ 697:a45682b5ff7e

(Auto) Update translations
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 01 Jul 2014 17:20:23 +0200
parents c262ee333c56
children 344d15e23f6c
rev   line source
404
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 371
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 371
diff changeset
2 * Software engineering by Intevation GmbH
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 371
diff changeset
3 *
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 371
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 371
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 371
diff changeset
6 * See LICENSE.txt for details.
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 371
diff changeset
7 */
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
8 #include <cert.h>
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
9 #include <certdb.h>
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
10 #include <certt.h>
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
11
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
12 #include <nss.h>
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
13 #include <pk11pub.h>
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
14
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
15 #include "nsstest.h"
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
16 #include "nssstore.h"
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
17 #include "strhelp.h"
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
18
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
19 #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
20 #include <QTextCodec>
1e6d1eab8395 Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents: 326
diff changeset
21
1e6d1eab8395 Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents: 326
diff changeset
22 #ifdef WIN32
1e6d1eab8395 Fix NSS unit test for Windows and change how instructions are written
Andre Heinecke <aheinecke@intevation.de>
parents: 326
diff changeset
23 #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
24 #endif
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
25
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
26 QList<QByteArray> NSSTest::get_nss_certs (QTemporaryDir *nssDir)
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
27 {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
28 CERTCertList *list;
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
29 CERTCertListNode *node;
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
30 QList<QByteArray> retval;
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
31
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
32 if (NSS_Initialize(nssDir->path().toLocal8Bit().constData(),
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
33 "", "", "secmod.db", NSS_INIT_READONLY)
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
34 == SECSuccess)
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
35 {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
36 list = PK11_ListCerts(PK11CertListAll, NULL);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
37 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
38 node = CERT_LIST_NEXT(node)) {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
39 retval << QByteArray((const char*)node->cert->derCert.data,
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
40 (int)node->cert->derCert.len);
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 CERT_DestroyCertList(list);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
43 NSS_Shutdown();
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 else
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 qDebug("Could not open nss certificate store!\n");
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
48 }
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
49 return retval;
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
50 }
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 void NSSTest::setupTestDir(QTemporaryDir *nssDir)
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 /* 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
55 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
56 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
57 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
58
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
59 QVERIFY(QFile::setPermissions(nssDir->path() + "/" +"cert8.db",
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
60 QFileDevice::ReadOwner | QFileDevice::WriteOwner));
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
61 QVERIFY(QFile::setPermissions(nssDir->path() + "/" +"key3.db",
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
62 QFileDevice::ReadOwner | QFileDevice::WriteOwner));
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
63 QVERIFY(QFile::setPermissions(nssDir->path() + "/" +"secmod.db",
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
64 QFileDevice::ReadOwner | QFileDevice::WriteOwner));
346
a54925d41056 Enable autoremove again
Andre Heinecke <andre.heinecke@intevation.de>
parents: 330
diff changeset
65 // nssDir->setAutoRemove(false);
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
66 }
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
67
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
68 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
69 QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); /* use system default */
304
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 /* 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
72 #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
73 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
74 #else
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
75 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
76 #endif
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
77 res.open(QIODevice::ReadOnly);
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
78 validListFile.open();
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
79 validListFile.write(res.readAll());
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
80 validListFile.close();
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
81
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
82 setupTestDir(&ffNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
83 setupTestDir(&tbNSSDir);
304
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 validList = CertificateList(validListFile.fileName().toLocal8Bit().data());
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
86
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
87 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
88
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
89 /* Create the profiles.ini `s set environment variables*/
346
a54925d41056 Enable autoremove again
Andre Heinecke <andre.heinecke@intevation.de>
parents: 330
diff changeset
90 // fakeHome.setAutoRemove(false);
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
91 #ifndef WIN32
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
92 fakeFirefoxDir = QDir(fakeHome.path() + "/.mozilla/firefox");
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
93 fakeThunderbirdDir = QDir(fakeHome.path() + "/.thunderbird");
492
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
94
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
95 /* Copy the current systems NSSSHARED db in the fake home for benchmark tests */
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
96 QDir fakeNSSSharedDir = fakeHome.path() + "/.pki/nssdb";
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
97 QVERIFY(fakeNSSSharedDir.mkpath(fakeNSSSharedDir.path()));
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
98 qDebug() << "Copying: " << QDir::homePath() + "/.pki/nssdb/cert9.db" <<
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
99 " to " << fakeNSSSharedDir.path() + "cert9.db";
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
100 QVERIFY(QFile::copy(QDir::homePath() + "/.pki/nssdb/cert9.db",
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
101 fakeNSSSharedDir.path() + "cert9.db"));
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
102 QVERIFY(QFile::copy(QDir::homePath() + "/.pki/nssdb/key4.db",
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
103 fakeNSSSharedDir.path() + "key4.db"));
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
104 QVERIFY(QFile::copy(QDir::homePath() + "/.pki/nssdb/pkcs11.txt",
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
105 fakeNSSSharedDir.path() + "pkcs11.txt"));
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
106
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
107 QVERIFY(!setenv ("HOME", fakeHome.path().toLocal8Bit().constData(), 1));
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
108 #else
326
ad28f6b60e6b Fix nsstest build for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
109 {
ad28f6b60e6b Fix nsstest build for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
110 char buf[fakeHome.path().toLocal8Bit().size() + 9];
ad28f6b60e6b Fix nsstest build for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
111 snprintf(buf, fakeHome.path().toLocal8Bit().size() + 9,
ad28f6b60e6b Fix nsstest build for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
112 "APPDATA=%s",fakeHome.path().toLocal8Bit().constData());
ad28f6b60e6b Fix nsstest build for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
113 QVERIFY(_putenv (buf) != -1);
ad28f6b60e6b Fix nsstest build for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
114 }
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
115 fakeFirefoxDir = QDir(fakeHome.path() + "/Mozilla/firefox");
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
116 fakeThunderbirdDir = QDir(fakeHome.path() + "/Thunderbird");
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
117 #endif
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
118 QVERIFY(fakeFirefoxDir.mkpath(fakeFirefoxDir.path()));
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
119 QVERIFY(fakeThunderbirdDir.mkpath(fakeThunderbirdDir.path()));
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
120
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
121 QFile mozProfile(fakeFirefoxDir.absoluteFilePath("profiles.ini"));
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
122 QFile tbProfile(fakeThunderbirdDir.absoluteFilePath("profiles.ini"));
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
123
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
124 /* Write profiles */
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
125 QVERIFY(mozProfile.open(QIODevice::WriteOnly));
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
126 QTextStream ffStream(&mozProfile);
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
127 ffStream << endl << "[General]"<<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
128 "StartWithLastProfile=1" << endl <<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
129 "[Profile0]" << endl <<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
130 "Name=default" << endl <<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
131 "IsRelative=1" << endl <<
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
132 "Path=" << fakeFirefoxDir.relativeFilePath(ffNSSDir.path()) << endl;
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
133 ffStream.flush();
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
134 mozProfile.close();
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
135
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
136 QVERIFY(tbProfile.open(QIODevice::WriteOnly));
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
137 QTextStream tbStream(&tbProfile);
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
138 tbStream << endl << "[General]"<<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
139 "StartWithLastProfile=1" << endl <<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
140 "[Profile102]" << endl <<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
141 "Name=default" << endl <<
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
142 "IsRelative=0" << endl <<
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
143 "Path=" << tbNSSDir.path() << endl;
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
144 tbStream.flush();
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
145 tbProfile.close();
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
146 }
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
147
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
148 void NSSTest::testInstRemove() {
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
149 char ** to_install = NULL,
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
150 ** to_remove = NULL;
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
151
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
152 QList<Certificate> instList;
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
153
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
154 /* Install all certificates */
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
155 foreach (const Certificate &cert, validList.getCertificates()) {
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
156 if (!cert.isInstallCert())
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
157 continue;
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
158 instList << cert;
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
159 strv_append (&to_install, cert.base64Line().toLatin1().constData() + 2,
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
160 cert.base64Line().size() - 2);
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
161 }
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
162 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
163 QVERIFY(strv_length(to_install) != 0);
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
164
305
4a3febc6d806 Some minor cleanups. Better debug output more Verify's
Andre Heinecke <andre.heinecke@intevation.de>
parents: 304
diff changeset
165 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
166
307
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 /* Verify that everything is installed */
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
169 QList<QByteArray> installedCertsFF = get_nss_certs(&ffNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
170 QList<QByteArray> installedCertsTB = get_nss_certs(&tbNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
171
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
172 QVERIFY(installedCertsFF.size() == instList.size());
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
173 QVERIFY(installedCertsFF == installedCertsTB);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
174
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
175 for (int i = 0; to_install[i]; i++) {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
176 QByteArray bai = QByteArray::fromBase64(to_install[i]);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
177 QVERIFY(installedCertsFF.contains(bai));
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
178 }
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
179 }
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
180
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 /* Remove one certificate */
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
183 QVERIFY(instList.size() > 2);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
184 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
185
477
48161978c84c Add some more verifications
Andre Heinecke <aheinecke@intevation.de>
parents: 404
diff changeset
186 QList<QByteArray> beforeFF = get_nss_certs(&ffNSSDir);
48161978c84c Add some more verifications
Andre Heinecke <aheinecke@intevation.de>
parents: 404
diff changeset
187 QVERIFY(strv_length(to_remove) == 1);
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
188 QVERIFY(write_stores_nss(NULL, to_remove) == 0);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
189
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
190 QList<QByteArray> installedCertsFF = get_nss_certs(&ffNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
191 QList<QByteArray> installedCertsTB = get_nss_certs(&tbNSSDir);
477
48161978c84c Add some more verifications
Andre Heinecke <aheinecke@intevation.de>
parents: 404
diff changeset
192 QVERIFY(beforeFF.size() > 0);
48161978c84c Add some more verifications
Andre Heinecke <aheinecke@intevation.de>
parents: 404
diff changeset
193 QVERIFY(beforeFF.size() - 1 == installedCertsFF.size());
307
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
194
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
195 QVERIFY(installedCertsFF == installedCertsTB);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
196
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
197 QByteArray bai = QByteArray::fromBase64(to_install[1]);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
198 QVERIFY(!installedCertsTB.contains(bai));
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
199
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
200 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
201
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
202 for (int i = 0; to_install[i]; i++) {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
203 if (i == 1) {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
204 continue;
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
205 }
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
206 QByteArray bai = QByteArray::fromBase64(to_install[i]);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
207 QVERIFY(installedCertsTB.contains(bai));
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
208 }
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
209 }
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 {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
212 /* Readd all certificates check for duplication*/
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
213 QVERIFY(write_stores_nss(to_install, NULL) == 0);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
214
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
215 QList<QByteArray> installedCertsFF = get_nss_certs(&ffNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
216 QList<QByteArray> installedCertsTB = get_nss_certs(&tbNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
217
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
218 QVERIFY(installedCertsFF == installedCertsTB);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
219
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
220 QVERIFY((size_t)installedCertsTB.size() == strv_length(to_install));
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
221
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
222 for (int i = 0; to_install[i]; i++) {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
223 QByteArray bai = QByteArray::fromBase64(to_install[i]);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
224 QVERIFY(installedCertsTB.contains(bai));
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
225 }
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
226 }
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
227
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
228 {
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
229 /* Remove all certificates */
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
230 QVERIFY(write_stores_nss(NULL, to_install) == 0);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
231
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
232 QList<QByteArray> installedCertsFF = get_nss_certs(&ffNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
233 QList<QByteArray> installedCertsTB = get_nss_certs(&tbNSSDir);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
234
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
235 QVERIFY(installedCertsFF == installedCertsTB);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
236
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
237 QVERIFY(installedCertsTB.size() == 0);
2fd69803d219 Complete InstRemove NSS test
Andre Heinecke <andre.heinecke@intevation.de>
parents: 305
diff changeset
238 }
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
239 }
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
240
492
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
241 void NSSTest::benchmarkInstall()
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
242 {
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
243 char ** to_install = NULL,
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
244 ** to_remove = NULL;
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
245
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
246 QList<Certificate> instList;
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
247
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
248 /* Install all certificates */
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
249 foreach (const Certificate &cert, validList.getCertificates()) {
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
250 if (!cert.isInstallCert())
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
251 continue;
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
252 instList << cert;
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
253 strv_append (&to_install, cert.base64Line().toLatin1().constData() + 2,
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
254 cert.base64Line().size() - 2);
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
255 }
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
256 QVERIFY((size_t) instList.size() == strv_length(to_install));
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
257 QVERIFY(strv_length(to_install) != 0);
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
258
534
c262ee333c56 Only benchmark nss once
Andre Heinecke <aheinecke@intevation.de>
parents: 492
diff changeset
259 QBENCHMARK_ONCE {
492
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
260 write_stores_nss(to_install, to_remove);
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
261 }
dcb014e7d32f Add NSSShared to test environment and create benchmark
Andre Heinecke <aheinecke@intevation.de>
parents: 477
diff changeset
262 }
304
eecc06f714fd Add first nsstest.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
263 QTEST_GUILESS_MAIN (NSSTest);

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