tst_QNetworkReply::ignoreSslErrorsList, use the right error

The error that the actual runtime will encounter, and not the one that compile-time
ifdefs will (potentially) erroneously select.

Change-Id: I8ef4c34bcb8b3e568bc39f8c8ea6bfb7732f9e27
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
bb10
Timur Pocheptsov 2021-06-08 12:36:20 +02:00
parent f6fa4b39ee
commit 096b186004
1 changed files with 8 additions and 10 deletions

View File

@ -92,14 +92,6 @@ Q_DECLARE_METATYPE(QSharedPointer<char>)
#include "../../../network-settings.h"
// Non-OpenSSL backends are not able to report a specific error code
// for self-signed certificates.
#ifndef QT_NO_OPENSSL
#define FLUKE_CERTIFICATE_ERROR QSslError::SelfSignedCertificate
#else
#define FLUKE_CERTIFICATE_ERROR QSslError::CertificateUntrusted
#endif
Q_DECLARE_METATYPE(QAuthenticator*)
#if QT_CONFIG(networkproxy)
Q_DECLARE_METATYPE(QNetworkProxyQuery)
@ -527,6 +519,9 @@ private:
bool notEnoughDataForFastSender;
bool ftpSupported = false;
#if QT_CONFIG(ssl)
QSslError::SslError flukeCertTlsError = QSslError::CertificateUntrusted;
#endif
};
const QByteArray tst_QNetworkReply::httpEmpty200Response =
@ -1589,6 +1584,9 @@ void tst_QNetworkReply::initTestCase()
cleanupTestData();
#if QT_CONFIG(ssl)
QT_PREPEND_NAMESPACE(qt_ForceTlsSecurityLevel)();
if (QSslSocket::activeBackend() == QStringLiteral("openssl"))
flukeCertTlsError = QSslError::SelfSignedCertificate;
#endif
}
@ -6408,8 +6406,8 @@ void tst_QNetworkReply::ignoreSslErrorsList_data()
QList<QSslError> expectedSslErrors;
QList<QSslCertificate> certs = QSslCertificate::fromPath(testDataDir + certsFilePath);
QSslError rightError(FLUKE_CERTIFICATE_ERROR, certs.at(0));
QSslError wrongError(FLUKE_CERTIFICATE_ERROR);
QSslError rightError(flukeCertTlsError, certs.at(0));
QSslError wrongError(flukeCertTlsError);
QTest::newRow("SSL-failure-empty-list") << expectedSslErrors << QNetworkReply::SslHandshakeFailedError;
expectedSslErrors.append(wrongError);