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