diff ui/tests/certlistparsertest.cpp @ 351:ee59ab0eb7ff

Add test for Certificate::fromFile
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 10 Apr 2014 15:31:02 +0200
parents 6a7eb102716d
children f6ce186cebc2
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;

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