comparison ui/tests/windowsstoretest.cpp @ 222:53ea9b975d1c

Cleanup windowsstore.c The cause for the test failure was that ADD_ALWAYS did not add a duplicate in the Root store but did add a duplicate in the Memory Store. We now check if the certificate is already in the store before actually installing it.
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 27 Mar 2014 14:16:22 +0000
parents e6c5c70a67b0
children 6a7eb102716d
comparison
equal deleted inserted replaced
221:431b058e903d 222:53ea9b975d1c
3 #include "strhelp.h" 3 #include "strhelp.h"
4 #include "certificate.h" 4 #include "certificate.h"
5 #include "../cinst/windowsstore.h" 5 #include "../cinst/windowsstore.h"
6 6
7 #include <QTest> 7 #include <QTest>
8
9 void WindowsStoreTest::dumpContents() {
10 char pszNameString[256];
11 PCCERT_CONTEXT pCert = NULL;
12 qDebug() << "Currently in store: " ;
13 while((pCert = CertEnumCertificatesInStore(testStore, pCert))) {
14 if(CertGetNameString(pCert,
15 CERT_NAME_SIMPLE_DISPLAY_TYPE,
16 0,
17 NULL,
18 pszNameString,
19 128)){
20 qDebug() << " " << pszNameString ;
21 }
22 }
23 }
8 24
9 void WindowsStoreTest::initTestCase() { 25 void WindowsStoreTest::initTestCase() {
10 testStore = CertOpenStore( 26 testStore = CertOpenStore(
11 CERT_STORE_PROV_MEMORY, // A memory store 27 CERT_STORE_PROV_MEMORY, // A memory store
12 0, // Encoding type 28 0, // Encoding type
58 } 74 }
59 } 75 }
60 QVERIFY(certFound); 76 QVERIFY(certFound);
61 i++; 77 i++;
62 } 78 }
63 qDebug() << i;
64 QVERIFY ((size_t)validList.getInstallCertificates().size() == i); 79 QVERIFY ((size_t)validList.getInstallCertificates().size() == i);
65 80
66 /* Remove all except one */ 81 /* Remove all except one */
67 for (i = 0; i < strv_length(to_install) - 1; i++) { 82 for (i = 0; i < strv_length(to_install) - 1; i++) {
68 strv_append(&to_remove, to_install[i], qstrlen(to_install[i])); 83 strv_append(&to_remove, to_install[i], qstrlen(to_install[i]));
98 i = 0; 113 i = 0;
99 while((pCert = CertEnumCertificatesInStore(testStore, pCert))) { 114 while((pCert = CertEnumCertificatesInStore(testStore, pCert))) {
100 bool certFound = false; 115 bool certFound = false;
101 QByteArray data = QByteArray::fromRawData((const char*) pCert->pbCertEncoded, 116 QByteArray data = QByteArray::fromRawData((const char*) pCert->pbCertEncoded,
102 pCert->cbCertEncoded); 117 pCert->cbCertEncoded);
103 qDebug() << "Have in store: " << data.toBase64(); 118 QVERIFY (data.toBase64() != to_remove[0]);
104 for (int j = 0; j < validList.getInstallCertificates().size() - 1; j++) { 119 for (int j = 0; j < validList.getInstallCertificates().size() - 1; j++) {
105 const Certificate &cert = validList.getInstallCertificates()[j]; 120 const Certificate &cert = validList.getInstallCertificates()[j];
106 QByteArray asn1data = QByteArray::fromBase64( 121 QByteArray asn1data = QByteArray::fromBase64(
107 cert.base64Line().right(cert.base64Line().size() - 2).toLatin1()); 122 cert.base64Line().right(cert.base64Line().size() - 2).toLatin1());
108 if (asn1data == data) { 123 if (asn1data == data) {
115 130
116 QVERIFY(i == strv_length(to_install) - 1); 131 QVERIFY(i == strv_length(to_install) - 1);
117 132
118 /* Install all again and remove them afterwards */ 133 /* Install all again and remove them afterwards */
119 do_install(testStore, to_install); 134 do_install(testStore, to_install);
120 do_remove(testStore, to_remove); 135 do_remove(testStore, to_install);
136
121 QVERIFY (CertEnumCertificatesInStore(testStore, pCert) == NULL); 137 QVERIFY (CertEnumCertificatesInStore(testStore, pCert) == NULL);
122 138
123 strv_free(to_install); 139 strv_free(to_install);
124 strv_free(to_remove); 140 strv_free(to_remove);
125 } 141 }

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