comparison ui/tests/windowsstoretest.cpp @ 249:6a7eb102716d

Remove code duplication by unifying the certificatelist. You should now check for isInstallCert to determine wether this certificate should be installed or removed. Leaving the getInstallCertificates and getRemoveCertificates in place for compatibilty would have been easier to keep the tests stable.
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 31 Mar 2014 08:06:17 +0000
parents 53ea9b975d1c
children 17e1c8f37d72
comparison
equal deleted inserted replaced
248:9f0865dc8b14 249:6a7eb102716d
44 char ** to_install = NULL, 44 char ** to_install = NULL,
45 ** to_remove = NULL; 45 ** to_remove = NULL;
46 PCCERT_CONTEXT pCert = NULL; 46 PCCERT_CONTEXT pCert = NULL;
47 size_t i = 0; 47 size_t i = 0;
48 48
49 foreach (const Certificate &cert, validList.getInstallCertificates()) { 49 QList<Certificate> instList;
50
51 foreach (const Certificate &cert, validList.getCertificates()) {
52 if (cert.isInstallCert())
53 instList << cert;
54 }
55
56
57 foreach (const Certificate &cert, instList) {
50 strv_append (&to_install, cert.base64Line().toLatin1().constData() + 2, 58 strv_append (&to_install, cert.base64Line().toLatin1().constData() + 2,
51 cert.base64Line().size() - 2); 59 cert.base64Line().size() - 2);
52 } 60 }
53 61
54 /* Just a quick check for str_append_str functionality */ 62 /* Just a quick check for str_append_str functionality */
55 QVERIFY((size_t) validList.getInstallCertificates().size() == strv_length(to_install)); 63 QVERIFY((size_t) instList.size() == strv_length(to_install));
56 for (i = 0; i < strv_length(to_install); i++) { 64 for (i = 0; i < strv_length(to_install); i++) {
57 QVERIFY (validList.getInstallCertificates()[i].base64Line().right( 65 QVERIFY (instList[i].base64Line().right(
58 validList.getInstallCertificates()[i].base64Line().size() - 2) == 66 instList[i].base64Line().size() - 2) ==
59 QString::fromLatin1(to_install[i])); 67 QString::fromLatin1(to_install[i]));
60 } 68 }
61 69
62 do_install(testStore, to_install); 70 do_install(testStore, to_install);
63 71
64 i = 0; 72 i = 0;
65 while((pCert = CertEnumCertificatesInStore(testStore, pCert))) { 73 while((pCert = CertEnumCertificatesInStore(testStore, pCert))) {
66 bool certFound = false; 74 bool certFound = false;
67 QByteArray data = QByteArray::fromRawData ((const char *)pCert->pbCertEncoded, 75 QByteArray data = QByteArray::fromRawData ((const char *)pCert->pbCertEncoded,
68 pCert->cbCertEncoded); 76 pCert->cbCertEncoded);
69 foreach (const Certificate &cert, validList.getInstallCertificates()) { 77 foreach (const Certificate &cert, instList) {
70 QByteArray asn1data = QByteArray::fromBase64( 78 QByteArray asn1data = QByteArray::fromBase64(
71 cert.base64Line().right(cert.base64Line().size() - 2).toLatin1()); 79 cert.base64Line().right(cert.base64Line().size() - 2).toLatin1());
72 if (asn1data == data) { 80 if (asn1data == data) {
73 certFound = true; 81 certFound = true;
74 } 82 }
75 } 83 }
76 QVERIFY(certFound); 84 QVERIFY(certFound);
77 i++; 85 i++;
78 } 86 }
79 QVERIFY ((size_t)validList.getInstallCertificates().size() == i); 87 QVERIFY ((size_t)instList.size() == i);
80 88
81 /* Remove all except one */ 89 /* Remove all except one */
82 for (i = 0; i < strv_length(to_install) - 1; i++) { 90 for (i = 0; i < strv_length(to_install) - 1; i++) {
83 strv_append(&to_remove, to_install[i], qstrlen(to_install[i])); 91 strv_append(&to_remove, to_install[i], qstrlen(to_install[i]));
84 } 92 }
114 while((pCert = CertEnumCertificatesInStore(testStore, pCert))) { 122 while((pCert = CertEnumCertificatesInStore(testStore, pCert))) {
115 bool certFound = false; 123 bool certFound = false;
116 QByteArray data = QByteArray::fromRawData((const char*) pCert->pbCertEncoded, 124 QByteArray data = QByteArray::fromRawData((const char*) pCert->pbCertEncoded,
117 pCert->cbCertEncoded); 125 pCert->cbCertEncoded);
118 QVERIFY (data.toBase64() != to_remove[0]); 126 QVERIFY (data.toBase64() != to_remove[0]);
119 for (int j = 0; j < validList.getInstallCertificates().size() - 1; j++) { 127 for (int j = 0; j < instList.size() - 1; j++) {
120 const Certificate &cert = validList.getInstallCertificates()[j]; 128 const Certificate &cert = instList[j];
121 QByteArray asn1data = QByteArray::fromBase64( 129 QByteArray asn1data = QByteArray::fromBase64(
122 cert.base64Line().right(cert.base64Line().size() - 2).toLatin1()); 130 cert.base64Line().right(cert.base64Line().size() - 2).toLatin1());
123 if (asn1data == data) { 131 if (asn1data == data) {
124 certFound = true; 132 certFound = true;
125 } 133 }

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