QSslConfiguration - improve code coverage
By adding auto-tests that were missing/not triggering the paths found by LCOV. Change-Id: I472f59e8e7292786c80d7c8dcebde53a2982e1ec Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 1157167a5c69e253fdeb6c8ad532c5d52e150769) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
0d4beeea64
commit
5bfd9c0d75
@ -39,11 +39,12 @@
|
|||||||
#include <QtNetwork/qdtls.h>
|
#include <QtNetwork/qdtls.h>
|
||||||
#include <QtNetwork/qssl.h>
|
#include <QtNetwork/qssl.h>
|
||||||
|
|
||||||
#include <QtCore/qbytearray.h>
|
|
||||||
#include <QtCore/qcryptographichash.h>
|
#include <QtCore/qcryptographichash.h>
|
||||||
#include <QtCore/qlist.h>
|
#include <QtCore/qscopeguard.h>
|
||||||
|
#include <QtCore/qbytearray.h>
|
||||||
#include <QtCore/qobject.h>
|
#include <QtCore/qobject.h>
|
||||||
#include <QtCore/qstring.h>
|
#include <QtCore/qstring.h>
|
||||||
|
#include <QtCore/qlist.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -311,6 +312,19 @@ void tst_QDtls::configuration()
|
|||||||
QCOMPARE(dtls.dtlsError(), QDtlsError::InvalidOperation);
|
QCOMPARE(dtls.dtlsError(), QDtlsError::InvalidOperation);
|
||||||
QCOMPARE(dtls.dtlsConfiguration(), config);
|
QCOMPARE(dtls.dtlsConfiguration(), config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool doneAlready = false;
|
||||||
|
if (!doneAlready) {
|
||||||
|
doneAlready = true;
|
||||||
|
QSslConfiguration nullConfig;
|
||||||
|
const auto defaultDtlsConfig = QSslConfiguration::defaultDtlsConfiguration();
|
||||||
|
const auto restoreDefault = qScopeGuard([&defaultDtlsConfig] {
|
||||||
|
QSslConfiguration::setDefaultDtlsConfiguration(defaultDtlsConfig);
|
||||||
|
});
|
||||||
|
QSslConfiguration::setDefaultDtlsConfiguration(nullConfig);
|
||||||
|
QCOMPARE(QSslConfiguration::defaultDtlsConfiguration(), nullConfig);
|
||||||
|
QVERIFY(QSslConfiguration::defaultDtlsConfiguration() != defaultDtlsConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QDtls::invalidConfiguration()
|
void tst_QDtls::invalidConfiguration()
|
||||||
|
@ -192,7 +192,7 @@ private slots:
|
|||||||
void setLocalCertificate();
|
void setLocalCertificate();
|
||||||
void localCertificateChain();
|
void localCertificateChain();
|
||||||
void setLocalCertificateChain();
|
void setLocalCertificateChain();
|
||||||
void setPrivateKey();
|
void tlsConfiguration();
|
||||||
void setSocketDescriptor();
|
void setSocketDescriptor();
|
||||||
void setSslConfiguration_data();
|
void setSslConfiguration_data();
|
||||||
void setSslConfiguration();
|
void setSslConfiguration();
|
||||||
@ -1588,8 +1588,33 @@ void tst_QSslSocket::setLocalCertificateChain()
|
|||||||
QCOMPARE(chain[1].serialNumber(), QByteArray("3b:eb:99:c5:ea:d8:0b:5d:0b:97:5d:4f:06:75:4b:e1"));
|
QCOMPARE(chain[1].serialNumber(), QByteArray("3b:eb:99:c5:ea:d8:0b:5d:0b:97:5d:4f:06:75:4b:e1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QSslSocket::setPrivateKey()
|
void tst_QSslSocket::tlsConfiguration()
|
||||||
{
|
{
|
||||||
|
QFETCH_GLOBAL(const bool, setProxy);
|
||||||
|
if (setProxy)
|
||||||
|
return;
|
||||||
|
// Test some things not covered by any other auto-test.
|
||||||
|
QSslSocket socket;
|
||||||
|
auto tlsConfig = socket.sslConfiguration();
|
||||||
|
QVERIFY(tlsConfig.sessionCipher().isNull());
|
||||||
|
QCOMPARE(tlsConfig.addCaCertificates(QStringLiteral("nonexisting/chain.crt")), false);
|
||||||
|
QCOMPARE(tlsConfig.sessionProtocol(), QSsl::UnknownProtocol);
|
||||||
|
QSslConfiguration nullConfig;
|
||||||
|
QVERIFY(nullConfig.isNull());
|
||||||
|
#ifndef QT_NO_OPENSSL
|
||||||
|
nullConfig.setEllipticCurves(tlsConfig.ellipticCurves());
|
||||||
|
QCOMPARE(nullConfig.ellipticCurves(), tlsConfig.ellipticCurves());
|
||||||
|
#endif
|
||||||
|
QMap<QByteArray, QVariant> backendConfig;
|
||||||
|
backendConfig["DTLSMTU"] = QVariant::fromValue(1024);
|
||||||
|
backendConfig["DTLSTIMEOUTMS"] = QVariant::fromValue(1000);
|
||||||
|
nullConfig.setBackendConfiguration(backendConfig);
|
||||||
|
QCOMPARE(nullConfig.backendConfiguration(), backendConfig);
|
||||||
|
QTest::ignoreMessage(QtWarningMsg, "QSslConfiguration::setPeerVerifyDepth: cannot set negative depth of -1000");
|
||||||
|
nullConfig.setPeerVerifyDepth(-1000);
|
||||||
|
QVERIFY(nullConfig.peerVerifyDepth() != -1000);
|
||||||
|
nullConfig.setPeerVerifyDepth(100);
|
||||||
|
QCOMPARE(nullConfig.peerVerifyDepth(), 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QSslSocket::setSocketDescriptor()
|
void tst_QSslSocket::setSocketDescriptor()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user