summaryrefslogtreecommitdiffstats
path: root/tests/auto/qsslcertificate/tst_qsslcertificate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qsslcertificate/tst_qsslcertificate.cpp')
-rw-r--r--tests/auto/qsslcertificate/tst_qsslcertificate.cpp84
1 files changed, 48 insertions, 36 deletions
diff --git a/tests/auto/qsslcertificate/tst_qsslcertificate.cpp b/tests/auto/qsslcertificate/tst_qsslcertificate.cpp
index 6e29072d8f..e95af1e97c 100644
--- a/tests/auto/qsslcertificate/tst_qsslcertificate.cpp
+++ b/tests/auto/qsslcertificate/tst_qsslcertificate.cpp
@@ -114,6 +114,7 @@ private slots:
void largeExpirationDate();
void blacklistedCertificates();
void toText();
+ void multipleCommonNames();
// ### add tests for certificate bundles (multiple certificates concatenated into a single
// structure); both PEM and DER formatted
@@ -195,8 +196,8 @@ void tst_QSslCertificate::emptyConstructor()
QCOMPARE(certificate.version() , QByteArray());
QCOMPARE(certificate.serialNumber(), QByteArray());
QCOMPARE(certificate.digest(), QCryptographicHash::hash(QByteArray(), QCryptographicHash::Md5));
- QCOMPARE(certificate.issuerInfo(QSslCertificate::Organization), QString());
- QCOMPARE(certificate.subjectInfo(QSslCertificate::Organization), QString());
+ QCOMPARE(certificate.issuerInfo(QSslCertificate::Organization), QStringList());
+ QCOMPARE(certificate.subjectInfo(QSslCertificate::Organization), QStringList());
QCOMPARE(certificate.alternateSubjectNames(),(QMultiMap<QSsl::AlternateNameEntryType, QString>()));
#ifndef QT_NO_TEXTSTREAM
QCOMPARE(certificate.effectiveDate(), QDateTime());
@@ -423,11 +424,11 @@ void tst_QSslCertificate::utf8SubjectNames()
static const char *ou = "\xe3\x88\xa7" "A" "\xe3\x89\x81\xef\xbd\xab" "BC";
// the following two tests should help find "\x"-literal encoding bugs in the test itself
- QCOMPARE(cert.subjectInfo("O").length(), QString::fromUtf8(o).length());
- QCOMPARE (cert.subjectInfo("O").toUtf8().toHex(), QByteArray(o).toHex());
+ QCOMPARE(cert.subjectInfo("O")[0].length(), QString::fromUtf8(o).length());
+ QCOMPARE (cert.subjectInfo("O")[0].toUtf8().toHex(), QByteArray(o).toHex());
- QCOMPARE(cert.subjectInfo("O"), QString::fromUtf8(o));
- QCOMPARE(cert.subjectInfo("OU"), QString::fromUtf8(ou));
+ QCOMPARE(cert.subjectInfo("O")[0], QString::fromUtf8(o));
+ QCOMPARE(cert.subjectInfo("OU")[0], QString::fromUtf8(ou));
}
void tst_QSslCertificate::publicKey_data()
@@ -680,33 +681,33 @@ void tst_QSslCertificate::certInfo()
QRegExp::FixedString).first();
QVERIFY(!cert.isNull());
- QCOMPARE(cert.issuerInfo(QSslCertificate::Organization), QString("CryptSoft Pty Ltd"));
- QCOMPARE(cert.issuerInfo(QSslCertificate::CommonName), QString("Test CA (1024 bit)"));
- QCOMPARE(cert.issuerInfo(QSslCertificate::LocalityName), QString());
- QCOMPARE(cert.issuerInfo(QSslCertificate::OrganizationalUnitName), QString());
- QCOMPARE(cert.issuerInfo(QSslCertificate::CountryName), QString("AU"));
- QCOMPARE(cert.issuerInfo(QSslCertificate::StateOrProvinceName), QString("Queensland"));
-
- QCOMPARE(cert.issuerInfo("O"), QString("CryptSoft Pty Ltd"));
- QCOMPARE(cert.issuerInfo("CN"), QString("Test CA (1024 bit)"));
- QCOMPARE(cert.issuerInfo("L"), QString());
- QCOMPARE(cert.issuerInfo("OU"), QString());
- QCOMPARE(cert.issuerInfo("C"), QString("AU"));
- QCOMPARE(cert.issuerInfo("ST"), QString("Queensland"));
-
- QCOMPARE(cert.subjectInfo(QSslCertificate::Organization), QString());
- QCOMPARE(cert.subjectInfo(QSslCertificate::CommonName), QString("name/with/slashes"));
- QCOMPARE(cert.subjectInfo(QSslCertificate::LocalityName), QString());
- QCOMPARE(cert.subjectInfo(QSslCertificate::OrganizationalUnitName), QString());
- QCOMPARE(cert.subjectInfo(QSslCertificate::CountryName), QString("NO"));
- QCOMPARE(cert.subjectInfo(QSslCertificate::StateOrProvinceName), QString());
-
- QCOMPARE(cert.subjectInfo("O"), QString());
- QCOMPARE(cert.subjectInfo("CN"), QString("name/with/slashes"));
- QCOMPARE(cert.subjectInfo("L"), QString());
- QCOMPARE(cert.subjectInfo("OU"), QString());
- QCOMPARE(cert.subjectInfo("C"), QString("NO"));
- QCOMPARE(cert.subjectInfo("ST"), QString());
+ QCOMPARE(cert.issuerInfo(QSslCertificate::Organization)[0], QString("CryptSoft Pty Ltd"));
+ QCOMPARE(cert.issuerInfo(QSslCertificate::CommonName)[0], QString("Test CA (1024 bit)"));
+ QCOMPARE(cert.issuerInfo(QSslCertificate::LocalityName), QStringList());
+ QCOMPARE(cert.issuerInfo(QSslCertificate::OrganizationalUnitName), QStringList());
+ QCOMPARE(cert.issuerInfo(QSslCertificate::CountryName)[0], QString("AU"));
+ QCOMPARE(cert.issuerInfo(QSslCertificate::StateOrProvinceName)[0], QString("Queensland"));
+
+ QCOMPARE(cert.issuerInfo("O")[0], QString("CryptSoft Pty Ltd"));
+ QCOMPARE(cert.issuerInfo("CN")[0], QString("Test CA (1024 bit)"));
+ QCOMPARE(cert.issuerInfo("L"), QStringList());
+ QCOMPARE(cert.issuerInfo("OU"), QStringList());
+ QCOMPARE(cert.issuerInfo("C")[0], QString("AU"));
+ QCOMPARE(cert.issuerInfo("ST")[0], QString("Queensland"));
+
+ QCOMPARE(cert.subjectInfo(QSslCertificate::Organization), QStringList());
+ QCOMPARE(cert.subjectInfo(QSslCertificate::CommonName)[0], QString("name/with/slashes"));
+ QCOMPARE(cert.subjectInfo(QSslCertificate::LocalityName), QStringList());
+ QCOMPARE(cert.subjectInfo(QSslCertificate::OrganizationalUnitName), QStringList());
+ QCOMPARE(cert.subjectInfo(QSslCertificate::CountryName)[0], QString("NO"));
+ QCOMPARE(cert.subjectInfo(QSslCertificate::StateOrProvinceName), QStringList());
+
+ QCOMPARE(cert.subjectInfo("O"), QStringList());
+ QCOMPARE(cert.subjectInfo("CN")[0], QString("name/with/slashes"));
+ QCOMPARE(cert.subjectInfo("L"), QStringList());
+ QCOMPARE(cert.subjectInfo("OU"), QStringList());
+ QCOMPARE(cert.subjectInfo("C")[0], QString("NO"));
+ QCOMPARE(cert.subjectInfo("ST"), QStringList());
QCOMPARE(cert.version(), QByteArray::number(1));
QCOMPARE(cert.serialNumber(), QByteArray::number(17));
@@ -739,8 +740,8 @@ void tst_QSslCertificate::certInfoQByteArray()
// in this test, check the bytearray variants before the enum variants to see if
// we fixed a bug we had with lazy initialization of the values.
- QCOMPARE(cert.issuerInfo("CN"), QString("Test CA (1024 bit)"));
- QCOMPARE(cert.subjectInfo("CN"), QString("name/with/slashes"));
+ QCOMPARE(cert.issuerInfo("CN")[0], QString("Test CA (1024 bit)"));
+ QCOMPARE(cert.subjectInfo("CN")[0], QString("name/with/slashes"));
}
void tst_QSslCertificate::task256066toPem()
@@ -789,7 +790,7 @@ void tst_QSslCertificate::nulInCN()
const QSslCertificate &cert = certList.at(0);
QVERIFY(!cert.isNull());
- QString cn = cert.subjectInfo(QSslCertificate::CommonName);
+ QString cn = cert.subjectInfo(QSslCertificate::CommonName)[0];
QVERIFY(cn != "www.bank.com");
static const char realCN[] = "www.bank.com\0.badguy.com";
@@ -871,6 +872,17 @@ void tst_QSslCertificate::toText()
QVERIFY(txtOld == cert.toText() || txtNew == cert.toText());
}
+void tst_QSslCertificate::multipleCommonNames()
+{
+ QList<QSslCertificate> certList =
+ QSslCertificate::fromPath(SRCDIR "more-certificates/test-cn-two-cns-cert.pem");
+ QVERIFY2(certList.count() > 0, "Please run this test from the source directory");
+
+ QStringList commonNames = certList[0].subjectInfo(QSslCertificate::CommonName);
+ QVERIFY(commonNames.contains(QString("www.example.com")));
+ QVERIFY(commonNames.contains(QString("www2.example.com")));
+}
+
#endif // QT_NO_OPENSSL
QTEST_MAIN(tst_QSslCertificate)