# HG changeset patch # User Andre Heinecke # Date 1397136662 -7200 # Node ID ee59ab0eb7ffb5dbb644d427a0b01a25ee8461ca # Parent 8fb815b7874285e48bdb0d90467b62fcef0398b6 Add test for Certificate::fromFile diff -r 8fb815b78742 -r ee59ab0eb7ff ui/tests/certlistparsertest.cpp --- 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 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; diff -r 8fb815b78742 -r ee59ab0eb7ff ui/tests/certlistparsertest.h --- 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