changeset 351:ee59ab0eb7ff

Add test for Certificate::fromFile
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 10 Apr 2014 15:31:02 +0200
parents 8fb815b78742
children 5f1494fab517
files ui/tests/certlistparsertest.cpp ui/tests/certlistparsertest.h
diffstat 2 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ui/tests/certlistparsertest.cpp	Thu Apr 10 15:30:36 2014 +0200
+++ b/ui/tests/certlistparsertest.cpp	Thu Apr 10 15:31:02 2014 +0200
@@ -143,6 +143,47 @@
     return new CertificateList(fileName.toLocal8Bit().data());
 }
 
+void CertListTest::testCertificateFromFile()
+{
+    QList<Certificate> result;
+
+    /* Real certificates in the wild */
+    result = Certificate::fromFileName(":/Intevation-Root-CA-2010.crt");
+    QVERIFY(result.size() == 1);
+    QVERIFY(result[0].isValid());
+    result = Certificate::fromFileName(":/Intevation-Root-CA-2010.der");
+    QVERIFY(result.size() == 1);
+    QVERIFY(result[0].isValid());
+
+    /* We can handle ECC keys */
+    result = Certificate::fromFileName(":/valid_ssl_bp.pem");
+    QVERIFY(result.size() == 1);
+    QVERIFY(result[0].isValid());
+
+    /* Basic stuff */
+    result = Certificate::fromFileName(":/valid_ssl_rsa.pem");
+    QVERIFY(result.size() == 1);
+    QVERIFY(result[0].isValid());
+
+    /* Multiple certs */
+    result = Certificate::fromFileName(":/import_test.pem");
+    QVERIFY(result.size() == 15);
+
+    QString lastCertB64;
+    foreach (const Certificate& cert, result) {
+        QVERIFY(cert.isValid());
+        /* Just to verify that it's not all the same */
+        QVERIFY(cert.base64Line() != lastCertB64);
+        lastCertB64 = cert.base64Line();
+    }
+
+    /* Some robustness */
+    QString fname = getRandomDataFile(MAX_LINE_LENGTH * MAX_LINES - 100);
+    result = Certificate::fromFileName(fname);
+    QVERIFY(QFile::remove(fname));
+    QVERIFY(result.isEmpty());
+}
+
 int main( int argc, char **argv )
 {
   CertListTest tc;
--- a/ui/tests/certlistparsertest.h	Thu Apr 10 15:30:36 2014 +0200
+++ b/ui/tests/certlistparsertest.h	Thu Apr 10 15:31:02 2014 +0200
@@ -19,6 +19,7 @@
     void testGarbage();
     void testTooLarge();
     void testEmptyFile();
+    void testCertificateFromFile();
     void benchmarkValid();
 };
 #endif

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