annotate ui/tests/certlistparsertest.cpp @ 51:78633b2b580c

Add macro for common signal setup tasks
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 17 Mar 2014 11:38:13 +0000
parents a7b8cb29f1f6
children be13e5e0a98f
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"
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
3
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
4 #include <QDebug>
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
5
31
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
6 void CertListTest::testValidList()
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
7 {
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
8 const char *fname = "list-valid-signed.txt";
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
9 CertificateList *certList = testWithFile(fname);
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
10 QCOMPARE (certList->getStatus(), Valid);
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
11 QVERIFY (certList->isValid());
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
12 delete certList;
37fc66967517 Implement signature verification wiht polarssl
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
13 }
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15 void CertListTest::testInvalidSig()
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 {
42
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
17 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
18 "list-valid-other-signature.txt",
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
19 "list-valid-sha1-signature.txt",
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
20 NULL};
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
21 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
22 CertificateList *certList = testWithFile(fnames[i]);
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
23 QCOMPARE (certList->getStatus(), InvalidSignature);
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
24 delete certList;
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
25 }
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
26 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
27
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
28 void verifyInvalidFile(const char *fName) {
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29 CertificateList *certList = new CertificateList(fName);
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30 QVERIFY (certList->getStatus() != Valid);
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31 delete certList;
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34 void CertListTest::testInvalidFileNames()
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35 {
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
36 verifyInvalidFile("/dev/random");
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 verifyInvalidFile("/tmp/");
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 verifyInvalidFile(NULL);
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 verifyInvalidFile("ä");
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 verifyInvalidFile("💩 ");
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42
42
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
43 void CertListTest::testEmptyFile()
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
44 {
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
45 const char *fname = "empty_file";
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
46 CertificateList *certList = testWithFile(fname);
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
47 printf("Status :%i\n ",certList->getStatus());
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
48 QCOMPARE (certList->getStatus(), UnknownError);
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
49 delete certList;
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
50 }
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
51
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
52 void CertListTest::testGarbage()
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
53 {
50
a7b8cb29f1f6 Rename random files to garbage to clarify what they contain
Andre Heinecke <aheinecke@intevation.de>
parents: 42
diff changeset
54 const char *fnames[] = {"garbage_500KB",
42
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
55 "list-with-null.txt",
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
56 NULL};
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
57 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
58 CertificateList *certList = testWithFile(fnames[i]);
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
59 QCOMPARE (certList->getStatus(), InvalidFormat);
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
60 delete certList;
6e7ef7e95031 Some more tests and some more test data
Andre Heinecke <aheinecke@intevation.de>
parents: 31
diff changeset
61 }
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
62 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
63
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
64 void CertListTest::testTooLarge()
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
65 {
50
a7b8cb29f1f6 Rename random files to garbage to clarify what they contain
Andre Heinecke <aheinecke@intevation.de>
parents: 42
diff changeset
66 const char *fname = "garbage_2MB";
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
67 CertificateList *certList = testWithFile(fname);
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68 QCOMPARE (certList->getStatus(), TooLarge);
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
69 QVERIFY (!certList->isValid());
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
70 delete certList;
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
71 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
72
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
73 void CertListTest::benchmarkValid()
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
74 {
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
75 const char *fname = "list-valid-signed.txt";
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
76
9
2ad9a96518e3 Actually parse all elements in the list
Andre Heinecke <aheinecke@intevation.de>
parents: 7
diff changeset
77 QBENCHMARK_ONCE {
7
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
78 CertificateList *certList = testWithFile(fname);
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
79 delete certList;
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 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
82
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
83 CertificateList* CertListTest::testWithFile(const char *filename)
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
84 {
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
85 QDir dataDir = QDir(SOURCE_DIR"/data/");
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
86 QString fileName = dataDir.absoluteFilePath(filename);
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
87 return new CertificateList(fileName.toLocal8Bit().data());
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
88 }
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
89
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
90 int main( int argc, char **argv )
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 CertListTest tc;
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
93 return QTest::qExec( &tc, argc, argv );
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
992c0ec57660 Add unit tests make CertificateList work.
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
96

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