Mercurial > trustbridge
changeset 207:e35983a322d6
merged.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 26 Mar 2014 15:22:50 +0100 |
parents | d587d075eddc (current diff) 825b42da1855 (diff) |
children | 135eae057491 |
files | ui/tests/data/garbage_2MB ui/tests/data/garbage_500KB |
diffstat | 7 files changed, 62 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/ui/certificate.cpp Wed Mar 26 15:22:14 2014 +0100 +++ b/ui/certificate.cpp Wed Mar 26 15:22:50 2014 +0100 @@ -15,6 +15,10 @@ x509_crt x509cert; + if (b64Line.isEmpty()) { + return; + } + /* Cut of the first two chars (e.g. I: and decode) */ QByteArray asn1data = QByteArray::fromBase64( b64Line.right(b64Line.size() - 2).toLatin1()); @@ -25,6 +29,7 @@ asn1data.size()); if (ret != 0) { qDebug() << "Parsing certificate failed with error: " << ret; + qDebug() << "Failed cert: " << asn1data.toBase64(); x509_crt_free(&x509cert); return; }
--- a/ui/certificatelist.cpp Wed Mar 26 15:22:14 2014 +0100 +++ b/ui/certificatelist.cpp Wed Mar 26 15:22:50 2014 +0100 @@ -13,6 +13,11 @@ char *data = NULL; size_t size = 0; + mCertificatesRemove.clear(); + mCertificatesInstall.clear(); + mDate = QDateTime(); + mData = QString(); + mStatus = read_and_verify_list(fileName, &data, &size); if (!isValid()) {
--- a/ui/certificatelist.h Wed Mar 26 15:22:14 2014 +0100 +++ b/ui/certificatelist.h Wed Mar 26 15:22:50 2014 +0100 @@ -54,7 +54,6 @@ const QString& rawData() const {return mData;} private: - QString mFileName; QList<Certificate> mCertificatesInstall; QList<Certificate> mCertificatesRemove; QString mData;
--- a/ui/tests/certlistparsertest.cpp Wed Mar 26 15:22:14 2014 +0100 +++ b/ui/tests/certlistparsertest.cpp Wed Mar 26 15:22:50 2014 +0100 @@ -51,9 +51,16 @@ QVERIFY(instLines.size() == instList.size()); QVERIFY(remoLines.size() == remoList.size()); + /* Check that a default certificate is invalid */ Certificate cert; QVERIFY(!cert.isValid()); + certList->readList(fileName.toLocal8Bit().data()); + + const QList<Certificate> instList2 = certList->getInstallCertificates(); + const QList<Certificate> remoList2 = certList->getRemoveCertificates(); + QVERIFY(instLines.size() == instList2.size()); + QVERIFY(remoLines.size() == remoList2.size()); delete certList; } @@ -90,29 +97,61 @@ { const char *fname = "empty_file"; CertificateList *certList = testWithFile(fname); - printf("Status :%i\n ",certList->getStatus()); QCOMPARE (certList->getStatus(), SeekFailed); delete certList; } void CertListTest::testGarbage() { - const char *fnames[] = {"garbage_500KB", - "list-with-null.txt", - NULL}; - for (int i=0; fnames[i] != NULL; i++) { - CertificateList *certList = testWithFile(fnames[i]); - QCOMPARE (certList->getStatus(), InvalidFormat); - delete certList; + const char *fname = "list-with-null.txt"; + QString fname2 = getRandomDataFile(200); + CertificateList *certList = testWithFile(fname); + QCOMPARE (certList->getStatus(), InvalidFormat); + delete certList; + certList = testWithFile(fname2.toLocal8Bit().constData()); + QVERIFY(QFile::remove(fname2)); + QCOMPARE (certList->getStatus(), InvalidFormat); + delete certList; +} + +QString CertListTest::getRandomDataFile(size_t size) +{ + QTemporaryFile tmpfile; + tmpfile.setAutoRemove(false); + tmpfile.open(); + size_t bufsize = 1024 * 1024; + if (bufsize > size) { + bufsize = size; } + char buf[bufsize]; + + for (size_t i = 0; i < bufsize; i++) { + buf[i] = (char) qrand() % 255; + } + + size_t bytesWritten=0; + int retval = 0; + do { + size_t toWrite = size - bytesWritten; + if (toWrite < bufsize) { + retval = tmpfile.write(buf, toWrite); + } else { + retval = tmpfile.write(buf, bufsize); + } + bytesWritten += retval; + } while (retval != -1 && bytesWritten < size); + + tmpfile.close(); + return tmpfile.fileName(); } void CertListTest::testTooLarge() { - const char *fname = "garbage_2MB"; - CertificateList *certList = testWithFile(fname); - QCOMPARE (certList->getStatus(), TooLarge); - QVERIFY (!certList->isValid()); + QString fname = getRandomDataFile(MAX_LINE_LENGTH * MAX_LINES + 1); + CertificateList *certList = testWithFile(fname.toLocal8Bit().constData()); + QVERIFY(QFile::remove(fname)); + QCOMPARE(certList->getStatus(), TooLarge); + QVERIFY(!certList->isValid()); delete certList; }