tests/auto/qsslcertificate/tst_qsslcertificate.cpp
changeset 7 f7bc934e204c
parent 0 1918ee327afb
child 33 3e2da88830cd
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the test suite of the Qt Toolkit.
     7 ** This file is part of the test suite of the Qt Toolkit.
     8 **
     8 **
   103     void toPemOrDer();
   103     void toPemOrDer();
   104     void fromDevice();
   104     void fromDevice();
   105     void fromPath_data();
   105     void fromPath_data();
   106     void fromPath();
   106     void fromPath();
   107     void certInfo();
   107     void certInfo();
       
   108     void certInfoQByteArray();
   108     void task256066toPem();
   109     void task256066toPem();
   109     void nulInCN();
   110     void nulInCN();
   110     void nulInSan();
   111     void nulInSan();
   111 // ### add tests for certificate bundles (multiple certificates concatenated into a single
   112 // ### add tests for certificate bundles (multiple certificates concatenated into a single
   112 //     structure); both PEM and DER formatted
   113 //     structure); both PEM and DER formatted
   540     QTest::newRow("\"d.*/c.*.pem\" regexp der") << QString("d.*/c.*.pem") << int(QRegExp::RegExp) << false << 0;
   541     QTest::newRow("\"d.*/c.*.pem\" regexp der") << QString("d.*/c.*.pem") << int(QRegExp::RegExp) << false << 0;
   541     QTest::newRow("\"d.*/c.*.pem\" wildcard pem") << QString("d.*/c.*.pem") << int(QRegExp::Wildcard) << true << 0;
   542     QTest::newRow("\"d.*/c.*.pem\" wildcard pem") << QString("d.*/c.*.pem") << int(QRegExp::Wildcard) << true << 0;
   542     QTest::newRow("\"d.*/c.*.pem\" wildcard der") << QString("d.*/c.*.pem") << int(QRegExp::Wildcard) << false << 0;
   543     QTest::newRow("\"d.*/c.*.pem\" wildcard der") << QString("d.*/c.*.pem") << int(QRegExp::Wildcard) << false << 0;
   543 
   544 
   544     QTest::newRow("trailing-whitespace") << QString("more-certificates/trailing-whitespace.pem") << int(QRegExp::FixedString) << true << 1;
   545     QTest::newRow("trailing-whitespace") << QString("more-certificates/trailing-whitespace.pem") << int(QRegExp::FixedString) << true << 1;
       
   546     QTest::newRow("no-ending-newline") << QString("more-certificates/no-ending-newline.pem") << int(QRegExp::FixedString) << true << 1;
       
   547     QTest::newRow("malformed-just-begin") << QString("more-certificates/malformed-just-begin.pem") << int(QRegExp::FixedString) << true << 0;
       
   548     QTest::newRow("malformed-just-begin-no-newline") << QString("more-certificates/malformed-just-begin-no-newline.pem") << int(QRegExp::FixedString) << true << 0;
   545 }
   549 }
   546 
   550 
   547 void tst_QSslCertificate::fromPath()
   551 void tst_QSslCertificate::fromPath()
   548 {
   552 {
   549     QFETCH(QString, path);
   553     QFETCH(QString, path);
   695 
   699 
   696     QCOMPARE(cert, QSslCertificate(pem, QSsl::Pem));
   700     QCOMPARE(cert, QSslCertificate(pem, QSsl::Pem));
   697     QCOMPARE(cert, QSslCertificate(QByteArray::fromHex(der), QSsl::Der));
   701     QCOMPARE(cert, QSslCertificate(QByteArray::fromHex(der), QSsl::Der));
   698 }
   702 }
   699 
   703 
       
   704 void tst_QSslCertificate::certInfoQByteArray()
       
   705 {
       
   706     QSslCertificate cert =  QSslCertificate::fromPath("certificates/cert.pem", QSsl::Pem,
       
   707                                                       QRegExp::FixedString).first();
       
   708     QVERIFY(!cert.isNull());
       
   709 
       
   710     // in this test, check the bytearray variants before the enum variants to see if
       
   711     // we fixed a bug we had with lazy initialization of the values.
       
   712     QCOMPARE(cert.issuerInfo("CN"), QString("Test CA (1024 bit)"));
       
   713     QCOMPARE(cert.subjectInfo("CN"), QString("name/with/slashes"));
       
   714 }
       
   715 
   700 void tst_QSslCertificate::task256066toPem()
   716 void tst_QSslCertificate::task256066toPem()
   701 {
   717 {
   702     // a certificate whose PEM encoding's length is a multiple of 64
   718     // a certificate whose PEM encoding's length is a multiple of 64
   703     const char *mycert = "-----BEGIN CERTIFICATE-----\n" \
   719     const char *mycert = "-----BEGIN CERTIFICATE-----\n" \
   704                          "MIIEGjCCAwKgAwIBAgIESikYSjANBgkqhkiG9w0BAQUFADBbMQswCQYDVQQGEwJF\n" \
   720                          "MIIEGjCCAwKgAwIBAgIESikYSjANBgkqhkiG9w0BAQUFADBbMQswCQYDVQQGEwJF\n" \