Mercurial > trustbridge
annotate ui/tests/windowsstoretest.cpp @ 224:689b94dd89a9
Wrote FindNSS to build against nss without pkg-config support (Windows).
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Thu, 27 Mar 2014 17:00:01 +0100 |
parents | e6c5c70a67b0 |
children | 53ea9b975d1c |
rev | line source |
---|---|
220
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1 #include "windowsstoretest.h" |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
2 #include "certificatelist.h" |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
3 #include "strhelp.h" |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
4 #include "certificate.h" |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
5 #include "../cinst/windowsstore.h" |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
6 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
7 #include <QTest> |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 void WindowsStoreTest::initTestCase() { |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 testStore = CertOpenStore( |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
11 CERT_STORE_PROV_MEMORY, // A memory store |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 0, // Encoding type |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
13 // Not used with a memory store |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
14 0, // Use the default provider |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
15 0, // No flags |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
16 NULL); // Not needed |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 QVERIFY (testStore); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 QFile res(":/list-valid-signed.txt"); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
19 res.open(QIODevice::ReadOnly); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
20 tmpFile.open(); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
21 tmpFile.write(res.readAll()); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
22 tmpFile.close(); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
23 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
24 validList = CertificateList(tmpFile.fileName().toLocal8Bit().data()); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
25 } |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
27 void WindowsStoreTest::testInstRemove() { |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
28 char ** to_install = NULL, |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
29 ** to_remove = NULL; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
30 PCCERT_CONTEXT pCert = NULL; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
31 size_t i = 0; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
32 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
33 foreach (const Certificate &cert, validList.getInstallCertificates()) { |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
34 strv_append (&to_install, cert.base64Line().toLatin1().constData() + 2, |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
35 cert.base64Line().size() - 2); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
36 } |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
37 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
38 /* Just a quick check for str_append_str functionality */ |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
39 QVERIFY((size_t) validList.getInstallCertificates().size() == strv_length(to_install)); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
40 for (i = 0; i < strv_length(to_install); i++) { |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
41 QVERIFY (validList.getInstallCertificates()[i].base64Line().right( |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
42 validList.getInstallCertificates()[i].base64Line().size() - 2) == |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
43 QString::fromLatin1(to_install[i])); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
44 } |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
45 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
46 do_install(testStore, to_install); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
47 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
48 i = 0; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
49 while((pCert = CertEnumCertificatesInStore(testStore, pCert))) { |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
50 bool certFound = false; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
51 QByteArray data = QByteArray::fromRawData ((const char *)pCert->pbCertEncoded, |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
52 pCert->cbCertEncoded); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
53 foreach (const Certificate &cert, validList.getInstallCertificates()) { |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
54 QByteArray asn1data = QByteArray::fromBase64( |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
55 cert.base64Line().right(cert.base64Line().size() - 2).toLatin1()); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
56 if (asn1data == data) { |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
57 certFound = true; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
58 } |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
59 } |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
60 QVERIFY(certFound); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
61 i++; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
62 } |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
63 qDebug() << i; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
64 QVERIFY ((size_t)validList.getInstallCertificates().size() == i); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
65 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
66 /* Remove all except one */ |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
67 for (i = 0; i < strv_length(to_install) - 1; i++) { |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
68 strv_append(&to_remove, to_install[i], qstrlen(to_install[i])); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
69 } |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
70 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
71 do_remove(testStore, to_remove); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
72 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
73 i = 0; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
74 while((pCert = CertEnumCertificatesInStore(testStore, pCert))) { |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
75 i++; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
76 } |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
77 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
78 QVERIFY(i == 1); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
79 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
80 /* Remove that too */ |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
81 strv_free(to_remove); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
82 to_remove = NULL; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
83 strv_append(&to_remove, to_install[strv_length(to_install) - 1], |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
84 qstrlen(to_install[strv_length(to_install) - 1])); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
85 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
86 do_remove(testStore, to_remove); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
87 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
88 QVERIFY (CertEnumCertificatesInStore(testStore, pCert) == NULL); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
89 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
90 /* Install them all again */ |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
91 do_install(testStore, to_install); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
92 strv_free(to_remove); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
93 to_remove = NULL; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
94 strv_append(&to_remove, to_install[strv_length(to_install) - 1], |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
95 qstrlen(to_install[strv_length(to_install) - 1])); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
96 do_remove(testStore, to_remove); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
97 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
98 i = 0; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
99 while((pCert = CertEnumCertificatesInStore(testStore, pCert))) { |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
100 bool certFound = false; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
101 QByteArray data = QByteArray::fromRawData((const char*) pCert->pbCertEncoded, |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
102 pCert->cbCertEncoded); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
103 qDebug() << "Have in store: " << data.toBase64(); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
104 for (int j = 0; j < validList.getInstallCertificates().size() - 1; j++) { |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
105 const Certificate &cert = validList.getInstallCertificates()[j]; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
106 QByteArray asn1data = QByteArray::fromBase64( |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
107 cert.base64Line().right(cert.base64Line().size() - 2).toLatin1()); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
108 if (asn1data == data) { |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
109 certFound = true; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
110 } |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
111 } |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
112 QVERIFY(certFound); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
113 i++; |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
114 } |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
115 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
116 QVERIFY(i == strv_length(to_install) - 1); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
117 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
118 /* Install all again and remove them afterwards */ |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
119 do_install(testStore, to_install); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
120 do_remove(testStore, to_remove); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
121 QVERIFY (CertEnumCertificatesInStore(testStore, pCert) == NULL); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
122 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
123 strv_free(to_install); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
124 strv_free(to_remove); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
125 } |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
126 |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
127 void WindowsStoreTest::cleanupTestCase() { |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
128 CertCloseStore(testStore, 0); |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
129 } |
e6c5c70a67b0
Add test for windowsstores
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
130 QTEST_GUILESS_MAIN (WindowsStoreTest); |