Mercurial > trustbridge
annotate ui/tests/certlistparsertest.cpp @ 910:eaed02defe6a
More SSLConnection refactoring. Fixes curl downloader.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 18 Aug 2014 18:51:33 +0200 |
parents | 17e1c8f37d72 |
children | e3772d2810b3 |
rev | line source |
---|---|
404 | 1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=2) | |
5 * and comes with ABSOLUTELY NO WARRANTY! | |
6 * See LICENSE.txt for details. | |
7 */ | |
7
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
8 #include "certlistparsertest.h" |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
9 #include "certificatelist.h" |
87
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
10 #include "certificate.h" |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
204
diff
changeset
|
11 #include "common.h" |
7
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
12 |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
13 #include <QDebug> |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
14 |
31
37fc66967517
Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
15 void CertListTest::testValidList() |
37fc66967517
Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
16 { |
359
f6ce186cebc2
If DO_RELEASE_BUILD is set use pubkey-release and test with it
Andre Heinecke <andre.heinecke@intevation.de>
parents:
351
diff
changeset
|
17 #ifdef RELEASE_BUILD |
f6ce186cebc2
If DO_RELEASE_BUILD is set use pubkey-release and test with it
Andre Heinecke <andre.heinecke@intevation.de>
parents:
351
diff
changeset
|
18 const char *fname = "list-valid-signed-release.txt"; |
f6ce186cebc2
If DO_RELEASE_BUILD is set use pubkey-release and test with it
Andre Heinecke <andre.heinecke@intevation.de>
parents:
351
diff
changeset
|
19 #else |
31
37fc66967517
Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
20 const char *fname = "list-valid-signed.txt"; |
359
f6ce186cebc2
If DO_RELEASE_BUILD is set use pubkey-release and test with it
Andre Heinecke <andre.heinecke@intevation.de>
parents:
351
diff
changeset
|
21 #endif |
88
abc76b750ea8
Fix extended list test. Add Benchmarking again
Andre Heinecke <aheinecke@intevation.de>
parents:
87
diff
changeset
|
22 |
abc76b750ea8
Fix extended list test. Add Benchmarking again
Andre Heinecke <aheinecke@intevation.de>
parents:
87
diff
changeset
|
23 QDir dataDir = QDir(SOURCE_DIR"/data/"); |
abc76b750ea8
Fix extended list test. Add Benchmarking again
Andre Heinecke <aheinecke@intevation.de>
parents:
87
diff
changeset
|
24 QString fileName = dataDir.absoluteFilePath(fname); |
abc76b750ea8
Fix extended list test. Add Benchmarking again
Andre Heinecke <aheinecke@intevation.de>
parents:
87
diff
changeset
|
25 QFile validList(fileName); |
87
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
26 validList.open(QIODevice::ReadOnly); |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
27 QString validData = QString::fromLatin1(validList.readAll()); |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
28 QStringList instLines; |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
29 QStringList remoLines; |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
30 |
31
37fc66967517
Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
31 CertificateList *certList = testWithFile(fname); |
87
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
32 QCOMPARE(certList->getStatus(), Valid); |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
33 QVERIFY(certList->isValid()); |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
34 |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
35 QVERIFY(certList->rawData() == validData.toLatin1()); |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
36 |
249
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
37 const QList<Certificate> cList = certList->getCertificates(); |
87
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
38 |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
39 foreach (QString act, validData.split("\r\n")) { |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
40 if (act.startsWith("I:")) { |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
41 instLines << act; |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
42 continue; |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
43 } |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
44 if (act.startsWith("R:")) { |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
45 remoLines << act; |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
46 continue; |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
47 } |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
48 } |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
49 |
249
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
50 int instCnt = 0, |
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
51 remoCnt = 0; |
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
52 foreach (const Certificate& cert, cList) { |
87
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
53 QVERIFY(cert.isValid()); |
249
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
54 if (cert.isInstallCert()) { |
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
55 QVERIFY(instLines.contains(cert.base64Line())); |
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
56 instCnt++; |
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
57 } else { |
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
58 QVERIFY(remoLines.contains(cert.base64Line())); |
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
59 remoCnt++; |
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
60 } |
87
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
61 } |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
62 |
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
63 /* Be variable if test data changes later */ |
249
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
64 QVERIFY(instCnt >= 1); |
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
65 QVERIFY(remoCnt >= 1); |
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
66 QVERIFY(instLines.size() == instCnt); |
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
67 QVERIFY(remoLines.size() == remoCnt); |
87
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
68 |
204
825b42da1855
Avoid printing an error when an empty certificate ist constructed
Andre Heinecke <andre.heinecke@intevation.de>
parents:
203
diff
changeset
|
69 /* Check that a default certificate is invalid */ |
95
b0b1375dfd40
Add check for default ctor of Certificate. Fix return value of empty file
Andre Heinecke <aheinecke@intevation.de>
parents:
88
diff
changeset
|
70 Certificate cert; |
b0b1375dfd40
Add check for default ctor of Certificate. Fix return value of empty file
Andre Heinecke <aheinecke@intevation.de>
parents:
88
diff
changeset
|
71 QVERIFY(!cert.isValid()); |
b0b1375dfd40
Add check for default ctor of Certificate. Fix return value of empty file
Andre Heinecke <aheinecke@intevation.de>
parents:
88
diff
changeset
|
72 |
203
60c5df8e7980
Reinitialize certificatelist when readFile is called
Andre Heinecke <andre.heinecke@intevation.de>
parents:
202
diff
changeset
|
73 certList->readList(fileName.toLocal8Bit().data()); |
60c5df8e7980
Reinitialize certificatelist when readFile is called
Andre Heinecke <andre.heinecke@intevation.de>
parents:
202
diff
changeset
|
74 |
249
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
75 const QList<Certificate> cList2 = certList->getCertificates(); |
6a7eb102716d
Remove code duplication by unifying the certificatelist.
Andre Heinecke <aheinecke@intevation.de>
parents:
240
diff
changeset
|
76 QVERIFY(instLines.size() + remoLines.size() == cList2.size()); |
87
be13e5e0a98f
Expand test to cover more functionality from certificate and certificatelist
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
77 |
31
37fc66967517
Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
78 delete certList; |
37fc66967517
Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
79 } |
7
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
80 |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
81 void CertListTest::testInvalidSig() |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
82 { |
42
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
83 const char *fnames[] = {"list-invalid-signed.txt", |
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
84 "list-valid-other-signature.txt", |
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
85 "list-valid-sha1-signature.txt", |
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
86 NULL}; |
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
87 for (int i=0; fnames[i] != NULL; i++) { |
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
88 CertificateList *certList = testWithFile(fnames[i]); |
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
89 QCOMPARE (certList->getStatus(), InvalidSignature); |
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
90 delete certList; |
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
91 } |
7
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
92 } |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
93 |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
94 void verifyInvalidFile(const char *fName) { |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
95 CertificateList *certList = new CertificateList(fName); |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
96 QVERIFY (certList->getStatus() != Valid); |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
97 delete certList; |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
98 } |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
99 |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
100 void CertListTest::testInvalidFileNames() |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
101 { |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
102 verifyInvalidFile("/dev/random"); |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
103 verifyInvalidFile("/tmp/"); |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
104 verifyInvalidFile(NULL); |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
105 verifyInvalidFile("ä"); |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
106 verifyInvalidFile("💩 "); |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
107 } |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
108 |
42
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
109 void CertListTest::testEmptyFile() |
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
110 { |
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
111 const char *fname = "empty_file"; |
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
112 CertificateList *certList = testWithFile(fname); |
95
b0b1375dfd40
Add check for default ctor of Certificate. Fix return value of empty file
Andre Heinecke <aheinecke@intevation.de>
parents:
88
diff
changeset
|
113 QCOMPARE (certList->getStatus(), SeekFailed); |
42
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
114 delete certList; |
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
115 } |
6e7ef7e95031
Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents:
31
diff
changeset
|
116 |
7
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
117 void CertListTest::testGarbage() |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
118 { |
202
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
119 const char *fname = "list-with-null.txt"; |
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
120 QString fname2 = getRandomDataFile(200); |
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
121 CertificateList *certList = testWithFile(fname); |
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
122 QCOMPARE (certList->getStatus(), InvalidFormat); |
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
123 delete certList; |
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
124 certList = testWithFile(fname2.toLocal8Bit().constData()); |
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
125 QVERIFY(QFile::remove(fname2)); |
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
126 QCOMPARE (certList->getStatus(), InvalidFormat); |
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
127 delete certList; |
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
128 } |
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
129 |
7
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
130 void CertListTest::testTooLarge() |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
131 { |
202
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
132 QString fname = getRandomDataFile(MAX_LINE_LENGTH * MAX_LINES + 1); |
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
133 CertificateList *certList = testWithFile(fname.toLocal8Bit().constData()); |
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
134 QVERIFY(QFile::remove(fname)); |
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
135 QCOMPARE(certList->getStatus(), TooLarge); |
0861069fd6d0
Fix testing for handling garbage input and generate the data ad hoc.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
95
diff
changeset
|
136 QVERIFY(!certList->isValid()); |
7
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
137 delete certList; |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
138 } |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
139 |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
140 void CertListTest::benchmarkValid() |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
141 { |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
142 const char *fname = "list-valid-signed.txt"; |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
143 |
88
abc76b750ea8
Fix extended list test. Add Benchmarking again
Andre Heinecke <aheinecke@intevation.de>
parents:
87
diff
changeset
|
144 QBENCHMARK{ |
7
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
145 CertificateList *certList = testWithFile(fname); |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
146 delete certList; |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
147 } |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
148 } |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
149 |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
150 CertificateList* CertListTest::testWithFile(const char *filename) |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
151 { |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
152 QDir dataDir = QDir(SOURCE_DIR"/data/"); |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
153 QString fileName = dataDir.absoluteFilePath(filename); |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
154 return new CertificateList(fileName.toLocal8Bit().data()); |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
155 } |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
156 |
351
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
157 void CertListTest::testCertificateFromFile() |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
158 { |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
159 QList<Certificate> result; |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
160 |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
161 /* Real certificates in the wild */ |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
162 result = Certificate::fromFileName(":/Intevation-Root-CA-2010.crt"); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
163 QVERIFY(result.size() == 1); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
164 QVERIFY(result[0].isValid()); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
165 result = Certificate::fromFileName(":/Intevation-Root-CA-2010.der"); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
166 QVERIFY(result.size() == 1); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
167 QVERIFY(result[0].isValid()); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
168 |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
169 /* We can handle ECC keys */ |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
170 result = Certificate::fromFileName(":/valid_ssl_bp.pem"); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
171 QVERIFY(result.size() == 1); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
172 QVERIFY(result[0].isValid()); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
173 |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
174 /* Basic stuff */ |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
175 result = Certificate::fromFileName(":/valid_ssl_rsa.pem"); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
176 QVERIFY(result.size() == 1); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
177 QVERIFY(result[0].isValid()); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
178 |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
179 /* Multiple certs */ |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
180 result = Certificate::fromFileName(":/import_test.pem"); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
181 QVERIFY(result.size() == 15); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
182 |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
183 QString lastCertB64; |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
184 foreach (const Certificate& cert, result) { |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
185 QVERIFY(cert.isValid()); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
186 /* Just to verify that it's not all the same */ |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
187 QVERIFY(cert.base64Line() != lastCertB64); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
188 lastCertB64 = cert.base64Line(); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
189 } |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
190 |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
191 /* Some robustness */ |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
192 QString fname = getRandomDataFile(MAX_LINE_LENGTH * MAX_LINES - 100); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
193 result = Certificate::fromFileName(fname); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
194 QVERIFY(QFile::remove(fname)); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
195 QVERIFY(result.isEmpty()); |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
196 } |
ee59ab0eb7ff
Add test for Certificate::fromFile
Andre Heinecke <andre.heinecke@intevation.de>
parents:
249
diff
changeset
|
197 |
7
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
198 int main( int argc, char **argv ) |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
199 { |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
200 CertListTest tc; |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
201 return QTest::qExec( &tc, argc, argv ); |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
202 } |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
203 |
992c0ec57660
Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
204 |