summaryrefslogtreecommitdiffstats
path: root/tests/auto/network
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/network')
-rw-r--r--tests/auto/network/access/http2/CMakeLists.txt4
-rw-r--r--tests/auto/network/access/http2/tst_http2.cpp4
-rw-r--r--tests/auto/network/access/qdecompresshelper/10K.gzbin0 -> 55 bytes
-rw-r--r--tests/auto/network/access/qdecompresshelper/tst_qdecompresshelper.cpp40
-rw-r--r--tests/auto/network/access/qnetworkcookie/tst_qnetworkcookie.cpp6
-rw-r--r--tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp31
-rw-r--r--tests/auto/network/access/qnetworkreply/test/CMakeLists.txt3
-rw-r--r--tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp10
-rw-r--r--tests/auto/network/kernel/CMakeLists.txt1
-rw-r--r--tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp49
-rw-r--r--tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp22
-rw-r--r--tests/auto/network/kernel/qnetworkinformation_appless/CMakeLists.txt6
-rw-r--r--tests/auto/network/kernel/qnetworkinformation_appless/tst_qnetworkinformation_appless.cpp67
-rw-r--r--tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp4
-rw-r--r--tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp216
-rw-r--r--tests/auto/network/socket/qudpsocket/test/CMakeLists.txt3
-rw-r--r--tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp4
-rw-r--r--tests/auto/network/ssl/qdtlscookie/tst_qdtlscookie.cpp2
-rw-r--r--tests/auto/network/ssl/qocsp/tst_qocsp.cpp1
-rw-r--r--tests/auto/network/ssl/qsslkey/tst_qsslkey.cpp74
-rw-r--r--tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp224
21 files changed, 503 insertions, 268 deletions
diff --git a/tests/auto/network/access/http2/CMakeLists.txt b/tests/auto/network/access/http2/CMakeLists.txt
index 7ac1c8001c..735f95deff 100644
--- a/tests/auto/network/access/http2/CMakeLists.txt
+++ b/tests/auto/network/access/http2/CMakeLists.txt
@@ -6,15 +6,13 @@
qt_internal_add_test(tst_http2
SOURCES
- ../../../../shared/emulationdetector.h
http2srv.cpp http2srv.h
tst_http2.cpp
DEFINES
SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/\\\"
- INCLUDE_DIRECTORIES
- ../../../../shared
PUBLIC_LIBRARIES
Qt::CorePrivate
Qt::Network
Qt::NetworkPrivate
+ Qt::TestPrivate
)
diff --git a/tests/auto/network/access/http2/tst_http2.cpp b/tests/auto/network/access/http2/tst_http2.cpp
index d4ef1520a7..1aa012c6ac 100644
--- a/tests/auto/network/access/http2/tst_http2.cpp
+++ b/tests/auto/network/access/http2/tst_http2.cpp
@@ -55,7 +55,7 @@
#include <memory>
#include <string>
-#include "emulationdetector.h"
+#include <QtTest/private/qemulationdetector_p.h>
#if (!defined(QT_NO_OPENSSL) && OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(OPENSSL_NO_TLSEXT)) \
|| QT_CONFIG(schannel)
@@ -379,7 +379,7 @@ void tst_Http2::flowControlServerSide()
// to let all replies finish without any error.
using namespace Http2;
- if (EmulationDetector::isRunningArmOnX86())
+ if (QTestPrivate::isRunningArmOnX86())
QSKIP("Test is too slow to run on emulator");
clearHTTP2State();
diff --git a/tests/auto/network/access/qdecompresshelper/10K.gz b/tests/auto/network/access/qdecompresshelper/10K.gz
new file mode 100644
index 0000000000..c5c4959763
--- /dev/null
+++ b/tests/auto/network/access/qdecompresshelper/10K.gz
Binary files differ
diff --git a/tests/auto/network/access/qdecompresshelper/tst_qdecompresshelper.cpp b/tests/auto/network/access/qdecompresshelper/tst_qdecompresshelper.cpp
index c31ab294cc..cfeff188f4 100644
--- a/tests/auto/network/access/qdecompresshelper/tst_qdecompresshelper.cpp
+++ b/tests/auto/network/access/qdecompresshelper/tst_qdecompresshelper.cpp
@@ -64,6 +64,9 @@ private Q_SLOTS:
void decompressBigData_data();
void decompressBigData();
+ void archiveBomb_data();
+ void archiveBomb();
+
#if QT_POINTER_SIZE >= 8
void bigZlib();
#endif
@@ -392,6 +395,43 @@ void tst_QDecompressHelper::decompressBigData()
QTEST(totalSize, "size");
}
+void tst_QDecompressHelper::archiveBomb_data()
+{
+ QTest::addColumn<QByteArray>("encoding");
+ QTest::addColumn<QString>("path");
+ QTest::addColumn<bool>("shouldFail");
+
+ QTest::newRow("gzip-10K") << QByteArray("gzip") << (srcDir + "/10K.gz") << false;
+ QTest::newRow("gzip-4G") << QByteArray("gzip") << QString(":/4G.gz") << true;
+}
+
+void tst_QDecompressHelper::archiveBomb()
+{
+ QFETCH(bool, shouldFail);
+ QFETCH(QString, path);
+ QFile file(path);
+ QVERIFY(file.open(QIODevice::ReadOnly));
+
+ QDecompressHelper helper;
+ QFETCH(QByteArray, encoding);
+ helper.setEncoding(encoding);
+ QVERIFY(helper.isValid());
+
+ constexpr qint64 SafeSizeLimit = 10 * 1024 * 1024;
+ constexpr qint64 RatioLimit = 40;
+ qint64 bytesToRead = std::min(SafeSizeLimit / RatioLimit, file.bytesAvailable());
+ QByteArray output(1 + bytesToRead * RatioLimit, Qt::Uninitialized);
+ helper.feed(file.read(bytesToRead));
+ qsizetype bytesRead = helper.read(output.data(), output.size());
+ QVERIFY(bytesRead <= output.size());
+ QVERIFY(helper.isValid());
+
+ if (shouldFail)
+ QCOMPARE(bytesRead, -1);
+ else
+ QVERIFY(bytesRead > 0);
+}
+
#if QT_POINTER_SIZE >= 8
void tst_QDecompressHelper::bigZlib()
{
diff --git a/tests/auto/network/access/qnetworkcookie/tst_qnetworkcookie.cpp b/tests/auto/network/access/qnetworkcookie/tst_qnetworkcookie.cpp
index b71934fc15..7f1b8e6369 100644
--- a/tests/auto/network/access/qnetworkcookie/tst_qnetworkcookie.cpp
+++ b/tests/auto/network/access/qnetworkcookie/tst_qnetworkcookie.cpp
@@ -688,11 +688,11 @@ void tst_QNetworkCookie::parseMultipleCookies()
void tst_QNetworkCookie::sameSite()
{
QList<QNetworkCookie> result = QNetworkCookie::parseCookies(QByteArrayLiteral("a=b;domain=qt-project.org"));
- QCOMPARE(result.first().sameSite(), QNetworkCookie::SameSite::Default);
+ QCOMPARE(result.first().sameSitePolicy(), QNetworkCookie::SameSite::Default);
result = QNetworkCookie::parseCookies(QByteArrayLiteral("a=b;domain=qt-project.org;samesite=strict"));
- QCOMPARE(result.first().sameSite(), QNetworkCookie::SameSite::Strict);
+ QCOMPARE(result.first().sameSitePolicy(), QNetworkCookie::SameSite::Strict);
result = QNetworkCookie::parseCookies(QByteArrayLiteral("a=b;domain=qt-project.org;samesite=none;secure"));
- QCOMPARE(result.first().sameSite(), QNetworkCookie::SameSite::None);
+ QCOMPARE(result.first().sameSitePolicy(), QNetworkCookie::SameSite::None);
QCOMPARE(result.first().toRawForm(), QByteArrayLiteral("a=b; secure; SameSite=None; domain=qt-project.org"));
}
diff --git a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
index 4d66dd2b1b..d4e9698ca3 100644
--- a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
+++ b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
@@ -480,22 +480,27 @@ void tst_QNetworkCookieJar::effectiveTLDs_data()
QTest::newRow("yes-platform.sh") << "eu.platform.sh" << true;
QTest::newRow("no-platform.sh") << "something.platform.sh" << false;
- int i;
- for (i = 0; tldIndices[i] < tldChunks[0]; i++) { }
- Q_ASSERT(i < tldCount);
- int TLDsInFirstChunk = i;
-
- const char *lastGroupFromFirstChunk = &tldData[0][tldIndices[TLDsInFirstChunk - 1]];
- QTest::addRow("lastGroupFromFirstChunk: %s", lastGroupFromFirstChunk)
- << lastGroupFromFirstChunk
- << true;
+ int inFirst = 0; // First group is guaranteed to be in first chunk.
+ while (tldIndices[inFirst] < tldChunks[0])
+ ++inFirst;
+ Q_ASSERT(inFirst < tldCount);
+ const char *lastGroupFromFirstChunk = &tldData[0][tldIndices[inFirst - 1]];
+ const char *cut = &tldData[0][tldChunks[0]];
+ for (const char *entry = lastGroupFromFirstChunk; entry < cut; entry += strlen(entry) + 1)
+ QTest::addRow("lastGroupFromFirstChunk: %s", entry) << entry << true;
Q_ASSERT(tldChunkCount > 1); // There are enough TLDs to fill 64K bytes
+ // The tldCount + 1 entries in tldIndices are indexed by hash value and some
+ // hash cells may be empty: we need to find the last non-empty hash cell.
+ int tail = tldCount;
+ while (tldIndices[tail - 1] == tldIndices[tail])
+ --tail;
+ Q_ASSERT(tldIndices[tail] == tldChunks[tldChunkCount - 1]);
const char *lastGroupFromLastChunk =
- &tldData[tldChunkCount-1][tldIndices[tldCount - 1] - tldChunks[tldChunkCount - 2]];
- QTest::addRow("lastGroupFromLastChunk: %s", lastGroupFromLastChunk)
- << lastGroupFromLastChunk
- << true;
+ &tldData[tldChunkCount-1][tldIndices[tail - 1] - tldChunks[tldChunkCount - 2]];
+ const char *end = &tldData[tldChunkCount-1][tldIndices[tail] - tldChunks[tldChunkCount - 2]];
+ for (const char *entry = lastGroupFromLastChunk; entry < end; entry += strlen(entry) + 1)
+ QTest::addRow("lastGroupFromLastChunk: %s", entry) << entry << true;
}
void tst_QNetworkCookieJar::effectiveTLDs()
diff --git a/tests/auto/network/access/qnetworkreply/test/CMakeLists.txt b/tests/auto/network/access/qnetworkreply/test/CMakeLists.txt
index e60d254651..d1b664e2d6 100644
--- a/tests/auto/network/access/qnetworkreply/test/CMakeLists.txt
+++ b/tests/auto/network/access/qnetworkreply/test/CMakeLists.txt
@@ -20,10 +20,7 @@ list(APPEND test_data "../smb-file.txt")
qt_internal_add_test(tst_qnetworkreply
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" # special case
SOURCES
- ../../../../../shared/emulationdetector.h
../tst_qnetworkreply.cpp
- INCLUDE_DIRECTORIES
- ../../../../../shared
PUBLIC_LIBRARIES
Qt::CorePrivate
Qt::NetworkPrivate
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
index 45fb7778e9..5e8a5420e1 100644
--- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -103,8 +103,6 @@ Q_DECLARE_METATYPE(QAuthenticator*)
Q_DECLARE_METATYPE(QNetworkProxyQuery)
#endif
-#include "emulationdetector.h"
-
typedef QSharedPointer<QNetworkReply> QNetworkReplyPtr;
#ifndef QT_NO_OPENSSL
@@ -2127,14 +2125,6 @@ void tst_QNetworkReply::getErrors()
QSKIP("Running this test as root doesn't make sense");
}
-
- if (EmulationDetector::isRunningArmOnX86()
- && qstrcmp(QTest::currentDataTag(), "file-permissions") == 0) {
- QFileInfo filePermissionFile = QFileInfo(filePermissionFileName.toLatin1());
- if (filePermissionFile.ownerId() == ::geteuid()) {
- QSKIP("Sysroot directories are owned by the current user");
- }
- }
#endif
QNetworkReplyPtr reply(manager.get(request));
diff --git a/tests/auto/network/kernel/CMakeLists.txt b/tests/auto/network/kernel/CMakeLists.txt
index 89526fa14c..11b859011e 100644
--- a/tests/auto/network/kernel/CMakeLists.txt
+++ b/tests/auto/network/kernel/CMakeLists.txt
@@ -14,4 +14,5 @@ endif()
if(QT_FEATURE_private_tests)
add_subdirectory(qauthenticator)
add_subdirectory(qnetworkinformation)
+ add_subdirectory(qnetworkinformation_appless)
endif()
diff --git a/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp b/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp
index 23afb2219c..f462330fdf 100644
--- a/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp
+++ b/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp
@@ -29,6 +29,8 @@
#include <QTest>
+#include <QSignalSpy>
+
#include <QtNetwork/QDnsLookup>
#include <QtNetwork/QHostAddress>
@@ -49,6 +51,7 @@ private slots:
void lookup();
void lookupReuse();
void lookupAbortRetry();
+ void bindingsAndProperties();
};
void tst_QDnsLookup::initTestCase()
@@ -375,5 +378,51 @@ void tst_QDnsLookup::lookupAbortRetry()
QCOMPARE(lookup.hostAddressRecords().first().value(), QHostAddress("2001:db8::1"));
}
+void tst_QDnsLookup::bindingsAndProperties()
+{
+ QFETCH_GLOBAL(const QString, tld);
+ if (tld == QStringLiteral("idn"))
+ return;
+
+ QDnsLookup lookup;
+
+ lookup.setType(QDnsLookup::A);
+ QProperty<QDnsLookup::Type> dnsTypeProp;
+ lookup.bindableType().setBinding(Qt::makePropertyBinding(dnsTypeProp));
+ const QSignalSpy typeChangeSpy(&lookup, &QDnsLookup::typeChanged);
+
+ dnsTypeProp = QDnsLookup::AAAA;
+ QCOMPARE(typeChangeSpy.count(), 1);
+ QCOMPARE(lookup.type(), QDnsLookup::AAAA);
+
+ dnsTypeProp.setBinding(lookup.bindableType().makeBinding());
+ lookup.setType(QDnsLookup::A);
+ QCOMPARE(dnsTypeProp.value(), QDnsLookup::A);
+
+ QProperty<QString> nameProp;
+ lookup.bindableName().setBinding(Qt::makePropertyBinding(nameProp));
+ const QSignalSpy nameChangeSpy(&lookup, &QDnsLookup::nameChanged);
+
+ nameProp = QStringLiteral("a-plus-aaaa");
+ QCOMPARE(nameChangeSpy.count(), 1);
+ QCOMPARE(lookup.name(), QStringLiteral("a-plus-aaaa"));
+
+ nameProp.setBinding(lookup.bindableName().makeBinding());
+ lookup.setName(QStringLiteral("a-single"));
+ QCOMPARE(nameProp.value(), QStringLiteral("a-single"));
+
+ QProperty<QHostAddress> nameserverProp;
+ lookup.bindableNameserver().setBinding(Qt::makePropertyBinding(nameserverProp));
+ const QSignalSpy nameserverChangeSpy(&lookup, &QDnsLookup::nameserverChanged);
+
+ nameserverProp = QHostAddress::LocalHost;
+ QCOMPARE(nameserverChangeSpy.count(), 1);
+ QCOMPARE(lookup.nameserver(), QHostAddress::LocalHost);
+
+ nameserverProp.setBinding(lookup.bindableNameserver().makeBinding());
+ lookup.setNameserver(QHostAddress::Any);
+ QCOMPARE(nameserverProp.value(), QHostAddress::Any);
+}
+
QTEST_MAIN(tst_QDnsLookup)
#include "tst_qdnslookup.moc"
diff --git a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp
index 569782180c..78f072fb54 100644
--- a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp
+++ b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp
@@ -110,14 +110,14 @@ void tst_QHostAddress::constructor_QString()
QTEST(hostAddr.toString(), "resAddr");
if ( protocol == 4 ) {
- QVERIFY( hostAddr.protocol() == QAbstractSocket::IPv4Protocol || hostAddr.protocol() == QAbstractSocket::UnknownNetworkLayerProtocol );
- QVERIFY( hostAddr.protocol() != QAbstractSocket::IPv6Protocol );
+ QVERIFY( hostAddr.protocol() == QHostAddress::IPv4Protocol || hostAddr.protocol() == QHostAddress::UnknownNetworkLayerProtocol );
+ QVERIFY( hostAddr.protocol() != QHostAddress::IPv6Protocol );
} else if ( protocol == 6 ) {
- QVERIFY( hostAddr.protocol() != QAbstractSocket::IPv4Protocol && hostAddr.protocol() != QAbstractSocket::UnknownNetworkLayerProtocol );
- QVERIFY( hostAddr.protocol() == QAbstractSocket::IPv6Protocol );
+ QVERIFY( hostAddr.protocol() != QHostAddress::IPv4Protocol && hostAddr.protocol() != QHostAddress::UnknownNetworkLayerProtocol );
+ QVERIFY( hostAddr.protocol() == QHostAddress::IPv6Protocol );
} else {
QVERIFY( hostAddr.isNull() );
- QVERIFY( hostAddr.protocol() == QAbstractSocket::UnknownNetworkLayerProtocol );
+ QVERIFY( hostAddr.protocol() == QHostAddress::UnknownNetworkLayerProtocol );
}
}
@@ -217,14 +217,14 @@ void tst_QHostAddress::setAddress_QString()
QTEST(hostAddr.toString(), "resAddr");
if ( protocol == 4 ) {
- QVERIFY( hostAddr.protocol() == QAbstractSocket::IPv4Protocol || hostAddr.protocol() == QAbstractSocket::UnknownNetworkLayerProtocol );
- QVERIFY( hostAddr.protocol() != QAbstractSocket::IPv6Protocol );
+ QVERIFY( hostAddr.protocol() == QHostAddress::IPv4Protocol || hostAddr.protocol() == QHostAddress::UnknownNetworkLayerProtocol );
+ QVERIFY( hostAddr.protocol() != QHostAddress::IPv6Protocol );
} else if ( protocol == 6 ) {
- QVERIFY( hostAddr.protocol() != QAbstractSocket::IPv4Protocol && hostAddr.protocol() != QAbstractSocket::UnknownNetworkLayerProtocol );
- QVERIFY( hostAddr.protocol() == QAbstractSocket::IPv6Protocol );
+ QVERIFY( hostAddr.protocol() != QHostAddress::IPv4Protocol && hostAddr.protocol() != QHostAddress::UnknownNetworkLayerProtocol );
+ QVERIFY( hostAddr.protocol() == QHostAddress::IPv6Protocol );
} else {
QVERIFY( hostAddr.isNull() );
- QVERIFY( hostAddr.protocol() == QAbstractSocket::UnknownNetworkLayerProtocol );
+ QVERIFY( hostAddr.protocol() == QHostAddress::UnknownNetworkLayerProtocol );
}
}
@@ -770,7 +770,7 @@ void tst_QHostAddress::convertv4v6()
if (protocol == 4) {
bool ok;
quint32 v4 = source.toIPv4Address(&ok);
- QCOMPARE(ok, result.protocol() == QAbstractSocket::IPv4Protocol);
+ QCOMPARE(ok, result.protocol() == QHostAddress::IPv4Protocol);
if (ok)
QCOMPARE(QHostAddress(v4), result);
} else if (protocol == 6) {
diff --git a/tests/auto/network/kernel/qnetworkinformation_appless/CMakeLists.txt b/tests/auto/network/kernel/qnetworkinformation_appless/CMakeLists.txt
new file mode 100644
index 0000000000..76cbf594c3
--- /dev/null
+++ b/tests/auto/network/kernel/qnetworkinformation_appless/CMakeLists.txt
@@ -0,0 +1,6 @@
+qt_internal_add_test(tst_qnetworkinformation_appless
+ SOURCES
+ tst_qnetworkinformation_appless.cpp
+ PUBLIC_LIBRARIES
+ Qt::Network
+)
diff --git a/tests/auto/network/kernel/qnetworkinformation_appless/tst_qnetworkinformation_appless.cpp b/tests/auto/network/kernel/qnetworkinformation_appless/tst_qnetworkinformation_appless.cpp
new file mode 100644
index 0000000000..ff058e8a9b
--- /dev/null
+++ b/tests/auto/network/kernel/qnetworkinformation_appless/tst_qnetworkinformation_appless.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/qcoreapplication.h>
+#include <QtNetwork/qnetworkinformation.h>
+#include <QtTest/qtest.h>
+
+class tst_QNetworkInformation_appless : public QObject
+{
+ Q_OBJECT
+private slots:
+ void reinit();
+};
+
+void tst_QNetworkInformation_appless::reinit()
+{
+ int argc = 1;
+ char name[] = "./test";
+ char *argv[] = { name, nullptr };
+
+ {
+ QCoreApplication app(argc, argv);
+ if (QNetworkInformation::availableBackends().isEmpty())
+ QSKIP("No backends available!");
+
+ QVERIFY(QNetworkInformation::load(QNetworkInformation::Feature::Reachability));
+ auto info = QNetworkInformation::instance();
+ QVERIFY(info);
+ }
+
+ QVERIFY(!QNetworkInformation::instance());
+
+ {
+ QCoreApplication app(argc, argv);
+ QVERIFY(QNetworkInformation::load(QNetworkInformation::Feature::Reachability));
+ auto info = QNetworkInformation::instance();
+ QVERIFY(info);
+ }
+}
+
+QTEST_APPLESS_MAIN(tst_QNetworkInformation_appless);
+#include "tst_qnetworkinformation_appless.moc"
diff --git a/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp b/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp
index c84120a6e5..8b64788a73 100644
--- a/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp
+++ b/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp
@@ -53,7 +53,7 @@ public:
class QDebugProxyFactory : public QNetworkProxyFactory
{
public:
- virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery())
+ QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery()) override
{
returnedList = QNetworkProxyFactory::systemProxyForQuery(query);
requestCounter++;
@@ -294,7 +294,7 @@ void tst_QNetworkProxyFactory::genericSystemProxy_data()
class QSPFQThread : public QThread
{
protected:
- virtual void run()
+ void run() override
{
proxies = QNetworkProxyFactory::systemProxyForQuery(query);
}
diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
index 4a0f0a27ed..eebbf4ef24 100644
--- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
+++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
@@ -38,6 +38,7 @@
#include <qtextstream.h>
#include <qdatastream.h>
#include <qelapsedtimer.h>
+#include <qproperty.h>
#include <QtNetwork/qlocalsocket.h>
#include <QtNetwork/qlocalserver.h>
@@ -55,6 +56,7 @@
Q_DECLARE_METATYPE(QLocalSocket::LocalSocketError)
Q_DECLARE_METATYPE(QLocalSocket::LocalSocketState)
Q_DECLARE_METATYPE(QLocalServer::SocketOption)
+Q_DECLARE_METATYPE(QLocalSocket::SocketOption)
Q_DECLARE_METATYPE(QFile::Permissions)
class tst_QLocalSocket : public QObject
@@ -76,6 +78,12 @@ private slots:
void listenAndConnect_data();
void listenAndConnect();
+ void listenAndConnectAbstractNamespace_data();
+ void listenAndConnectAbstractNamespace();
+
+ void listenAndConnectAbstractNamespaceTrailingZeros_data();
+ void listenAndConnectAbstractNamespaceTrailingZeros();
+
void connectWithOpen();
void connectWithOldOpen();
@@ -103,6 +111,7 @@ private slots:
void longPath();
void waitForDisconnect();
void waitForDisconnectByServer();
+ void waitForReadyReadOnDisconnected();
void removeServer();
@@ -126,6 +135,7 @@ private slots:
void verifyListenWithDescriptor();
void verifyListenWithDescriptor_data();
+ void serverBindingsAndProperties();
};
tst_QLocalSocket::tst_QLocalSocket()
@@ -133,6 +143,7 @@ tst_QLocalSocket::tst_QLocalSocket()
qRegisterMetaType<QLocalSocket::LocalSocketState>("QLocalSocket::LocalSocketState");
qRegisterMetaType<QLocalSocket::LocalSocketError>("QLocalSocket::LocalSocketError");
qRegisterMetaType<QLocalServer::SocketOption>("QLocalServer::SocketOption");
+ qRegisterMetaType<QLocalServer::SocketOption>("QLocalSocket::SocketOption");
qRegisterMetaType<QFile::Permissions>("QFile::Permissions");
}
@@ -155,7 +166,7 @@ public:
QList<int> hits;
protected:
- void incomingConnection(quintptr socketDescriptor)
+ void incomingConnection(quintptr socketDescriptor) override
{
hits.append(socketDescriptor);
QLocalServer::incomingConnection(socketDescriptor);
@@ -481,6 +492,105 @@ void tst_QLocalSocket::connectWithOpen()
server.close();
}
+void tst_QLocalSocket::listenAndConnectAbstractNamespaceTrailingZeros_data()
+{
+#ifdef Q_OS_LINUX
+ QTest::addColumn<bool>("server_0");
+ QTest::addColumn<bool>("client_0");
+ QTest::addColumn<bool>("success");
+ QTest::newRow("srv0_cli0") << true << true << true;
+ QTest::newRow("srv_cli0") << false << true << false;
+ QTest::newRow("srv0_cli") << true << false << false;
+ QTest::newRow("srv_cli") << false << false << true;
+#else
+ return;
+#endif
+}
+
+void tst_QLocalSocket::listenAndConnectAbstractNamespaceTrailingZeros()
+{
+#ifdef Q_OS_LINUX
+ QFETCH(bool, server_0);
+ QFETCH(bool, client_0);
+ QFETCH(bool, success);
+ bool expectedTimeOut = !success;
+ QString server_path("tst_qlocalsocket");
+ QString client_path("tst_qlocalsocket");
+
+ if (server_0)
+ server_path.append(QChar('\0'));
+ if (client_0)
+ client_path.append(QChar('\0'));
+ LocalServer server;
+ server.setSocketOptions(QLocalServer::AbstractNamespaceOption);
+ QVERIFY(server.listen(server_path));
+ QCOMPARE(server.fullServerName(), server_path);
+
+ LocalSocket socket;
+ socket.setSocketOptions(QLocalSocket::AbstractNamespaceOption);
+ socket.setServerName(client_path);
+ QCOMPARE(socket.open(), success);
+ if (success)
+ QCOMPARE(socket.fullServerName(), client_path);
+ else
+ QVERIFY(socket.fullServerName().isEmpty());
+
+ bool timedOut = true;
+ QCOMPARE(server.waitForNewConnection(3000, &timedOut), success);
+
+#if defined(QT_LOCALSOCKET_TCP)
+ QTest::qWait(250);
+#endif
+ QCOMPARE(timedOut, expectedTimeOut);
+
+ socket.close();
+ server.close();
+#else
+ return;
+#endif
+}
+
+void tst_QLocalSocket::listenAndConnectAbstractNamespace_data()
+{
+ QTest::addColumn<QLocalServer::SocketOption>("serverOption");
+ QTest::addColumn<QLocalSocket::SocketOption>("socketOption");
+ QTest::addColumn<bool>("success");
+ QTest::newRow("abs_abs") << QLocalServer::AbstractNamespaceOption << QLocalSocket::AbstractNamespaceOption << true;
+ QTest::newRow("reg_reg") << QLocalServer::NoOptions << QLocalSocket::NoOptions << true;
+#ifdef Q_OS_LINUX
+ QTest::newRow("reg_abs") << QLocalServer::UserAccessOption << QLocalSocket::AbstractNamespaceOption << false;
+ QTest::newRow("abs_reg") << QLocalServer::AbstractNamespaceOption << QLocalSocket::NoOptions << false;
+#endif
+}
+
+void tst_QLocalSocket::listenAndConnectAbstractNamespace()
+{
+ QFETCH(QLocalServer::SocketOption, serverOption);
+ QFETCH(QLocalSocket::SocketOption, socketOption);
+ QFETCH(bool, success);
+ bool expectedTimeOut = !success;
+
+ LocalServer server;
+ server.setSocketOptions(serverOption);
+ QVERIFY(server.listen("tst_qlocalsocket"));
+
+ LocalSocket socket;
+ socket.setSocketOptions(socketOption);
+ socket.setServerName("tst_qlocalsocket");
+ QCOMPARE(socket.open(), success);
+
+ bool timedOut = true;
+ QCOMPARE(server.waitForNewConnection(3000, &timedOut), success);
+
+#if defined(QT_LOCALSOCKET_TCP)
+ QTest::qWait(250);
+#endif
+ QCOMPARE(timedOut, expectedTimeOut);
+
+ socket.close();
+ server.close();
+}
+
void tst_QLocalSocket::connectWithOldOpen()
{
class OverriddenOpen : public LocalSocket
@@ -637,26 +747,6 @@ void tst_QLocalSocket::readBufferOverflow()
QCOMPARE(client.read(buffer, readBufferSize), qint64(readBufferSize));
// no more bytes available
QCOMPARE(client.bytesAvailable(), 0);
-
-#ifdef Q_OS_WIN
- serverSocket->write(buffer, readBufferSize);
- QVERIFY(serverSocket->waitForBytesWritten());
-
- // ensure the read completion routine is called
- SleepEx(100, true);
- QVERIFY(client.waitForReadyRead());
- QCOMPARE(client.read(buffer, readBufferSize), qint64(readBufferSize));
-
- // Test overflow caused by an asynchronous pipe operation.
- client.setReadBufferSize(1);
- serverSocket->write(buffer, 2);
-
- QVERIFY(client.waitForReadyRead());
- // socket disconnects, if there any error on pipe
- QCOMPARE(client.state(), QLocalSocket::ConnectedState);
- QCOMPARE(client.bytesAvailable(), qint64(2));
- QCOMPARE(client.read(buffer, 2), qint64(2));
-#endif
}
static qint64 writeCommand(const QVariant &command, QIODevice *device, int commandCounter)
@@ -837,7 +927,7 @@ class Client : public QThread
{
public:
- void run()
+ void run() override
{
QString testLine = "test";
LocalSocket socket;
@@ -862,7 +952,7 @@ public:
int clients;
QMutex mutex;
QWaitCondition wc;
- void run()
+ void run() override
{
QString testLine = "test";
LocalServer server;
@@ -1062,6 +1152,40 @@ void tst_QLocalSocket::waitForDisconnectByServer()
QCOMPARE(spy.count(), 1);
}
+void tst_QLocalSocket::waitForReadyReadOnDisconnected()
+{
+ QString name = "tst_localsocket";
+ LocalServer server;
+ QVERIFY(server.listen(name));
+ LocalSocket socket;
+ connect(&socket, &QLocalSocket::readyRead, [&socket]() {
+ QVERIFY(socket.getChar(nullptr));
+ // The next call should not block because the socket was closed
+ // by the peer.
+ QVERIFY(!socket.waitForReadyRead(3000));
+ });
+
+ socket.connectToServer(name);
+ QVERIFY(socket.waitForConnected(3000));
+ QVERIFY(server.waitForNewConnection(3000));
+ QLocalSocket *serverSocket = server.nextPendingConnection();
+ QVERIFY(serverSocket);
+ QVERIFY(serverSocket->putChar(0));
+ QVERIFY(serverSocket->waitForBytesWritten(3000));
+ serverSocket->close();
+
+#ifdef Q_OS_WIN
+ // Ensure that the asynchronously delivered close notification is
+ // already queued up before we consume the data.
+ QTest::qSleep(250);
+#endif
+
+ QElapsedTimer timer;
+ timer.start();
+ QVERIFY(socket.waitForReadyRead(5000));
+ QVERIFY(timer.elapsed() < 2000);
+}
+
void tst_QLocalSocket::removeServer()
{
// this is a hostile takeover, but recovering from a crash results in the same
@@ -1217,7 +1341,8 @@ class WriteThread : public QThread
{
Q_OBJECT
public:
- void run() {
+ void run() override
+ {
QLocalSocket socket;
socket.connectToServer("qlocalsocket_readyread");
@@ -1348,15 +1473,15 @@ void tst_QLocalSocket::verifyListenWithDescriptor()
int listenSocket;
+ // Construct the unix address
+ struct ::sockaddr_un addr;
+ addr.sun_family = PF_UNIX;
+
if (bound) {
// create the unix socket
listenSocket = ::socket(PF_UNIX, SOCK_STREAM, 0);
QVERIFY2(listenSocket != -1, "failed to create test socket");
- // Construct the unix address
- struct ::sockaddr_un addr;
- addr.sun_family = PF_UNIX;
-
QVERIFY2(sizeof(addr.sun_path) > ((uint)path.size() + 1), "path to large to create socket");
::memset(addr.sun_path, 0, sizeof(addr.sun_path));
@@ -1385,12 +1510,12 @@ void tst_QLocalSocket::verifyListenWithDescriptor()
QVERIFY2(server.listen(listenSocket), "failed to start create QLocalServer with local socket");
#ifdef Q_OS_LINUX
- const QChar at(QLatin1Char('@'));
if (!bound) {
- QCOMPARE(server.serverName().at(0), at);
- QCOMPARE(server.fullServerName().at(0), at);
+ QCOMPARE(server.serverName().isEmpty(), true);
+ QCOMPARE(server.fullServerName().isEmpty(), true);
} else if (abstract) {
- QVERIFY2(server.fullServerName().at(0) == at, "abstract sockets should start with a '@'");
+ QVERIFY2(server.fullServerName().at(0) == addr.sun_path[1],
+ "abstract sockets should match server path without leading null");
} else {
QCOMPARE(server.fullServerName(), path);
if (path.contains(QLatin1Char('/'))) {
@@ -1400,8 +1525,17 @@ void tst_QLocalSocket::verifyListenWithDescriptor()
}
}
#else
- QVERIFY(server.serverName().isEmpty());
- QVERIFY(server.fullServerName().isEmpty());
+ if (bound) {
+ QCOMPARE(server.fullServerName(), path);
+ if (path.contains(QLatin1Char('/'))) {
+ QVERIFY2(server.serverName() == path.mid(path.lastIndexOf(QLatin1Char('/'))+1), "server name invalid short name");
+ } else {
+ QVERIFY2(server.serverName() == path, "server name doesn't match the path provided");
+ }
+ } else {
+ QVERIFY(server.serverName().isEmpty());
+ QVERIFY(server.fullServerName().isEmpty());
+ }
#endif
@@ -1426,6 +1560,20 @@ void tst_QLocalSocket::verifyListenWithDescriptor_data()
}
+void tst_QLocalSocket::serverBindingsAndProperties()
+{
+ QLocalServer server;
+
+ QProperty<QLocalServer::SocketOptions> sockOpts;
+ server.bindableSocketOptions().setBinding(Qt::makePropertyBinding(sockOpts));
+ sockOpts = QLocalServer::GroupAccessOption | QLocalServer::UserAccessOption;
+ QCOMPARE(server.socketOptions(), sockOpts.value());
+
+ sockOpts.setBinding(server.bindableSocketOptions().makeBinding());
+ server.setSocketOptions(QLocalServer::OtherAccessOption);
+ QCOMPARE(sockOpts.value(), QLocalServer::OtherAccessOption);
+}
+
QTEST_MAIN(tst_QLocalSocket)
#include "tst_qlocalsocket.moc"
diff --git a/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt b/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt
index 7bd9bd80fb..6a781aadc4 100644
--- a/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt
+++ b/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt
@@ -8,10 +8,9 @@ qt_internal_add_test(tst_qudpsocket
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" # special case
SOURCES
../tst_qudpsocket.cpp
- INCLUDE_DIRECTORIES
- ../../../../../shared
PUBLIC_LIBRARIES
Qt::Network
+ Qt::TestPrivate
QT_TEST_SERVER_LIST "danted" "echo" # special case
)
diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
index 1f3c8583f2..22f5f3f4c7 100644
--- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
+++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
@@ -52,7 +52,7 @@
#include <qstringlist.h>
#include "../../../network-settings.h"
-#include "emulationdetector.h"
+#include <QtTest/private/qemulationdetector_p.h>
#if defined(Q_OS_LINUX)
#define SHOULD_CHECK_SYSCALL_SUPPORT
@@ -302,7 +302,7 @@ void tst_QUdpSocket::initTestCase()
qDebug() << "Will use multicast groups" << multicastGroup4 << multicastGroup6 << linklocalMulticastGroups;
m_workaroundLinuxKernelBug = shouldWorkaroundLinuxKernelBug();
- if (EmulationDetector::isRunningArmOnX86())
+ if (QTestPrivate::isRunningArmOnX86())
QSKIP("This test is unreliable due to QEMU emulation shortcomings.");
}
diff --git a/tests/auto/network/ssl/qdtlscookie/tst_qdtlscookie.cpp b/tests/auto/network/ssl/qdtlscookie/tst_qdtlscookie.cpp
index 1d17f98d82..e4863a8f5a 100644
--- a/tests/auto/network/ssl/qdtlscookie/tst_qdtlscookie.cpp
+++ b/tests/auto/network/ssl/qdtlscookie/tst_qdtlscookie.cpp
@@ -344,7 +344,7 @@ void tst_QDtlsCookie::verifyMultipleClients()
clientsToAdd = clientsToWait = 100;
- testLoop.enterLoop(handshakeTimeoutMS * clientsToWait);
+ testLoop.enterLoopMSecs(handshakeTimeoutMS * clientsToWait);
QVERIFY(!testLoop.timeout());
QVERIFY(clientsToWait == 0);
}
diff --git a/tests/auto/network/ssl/qocsp/tst_qocsp.cpp b/tests/auto/network/ssl/qocsp/tst_qocsp.cpp
index 5ab9817943..37ce9a4f6d 100644
--- a/tests/auto/network/ssl/qocsp/tst_qocsp.cpp
+++ b/tests/auto/network/ssl/qocsp/tst_qocsp.cpp
@@ -32,7 +32,6 @@
#include <QtNetwork/private/qtnetworkglobal_p.h>
#include <QtNetwork/private/qsslsocket_openssl_symbols_p.h>
-#include <QtNetwork/private/qsslsocket_openssl_p.h>
#include <QtNetwork/qsslcertificate.h>
#include <QtNetwork/qtcpserver.h>
diff --git a/tests/auto/network/ssl/qsslkey/tst_qsslkey.cpp b/tests/auto/network/ssl/qsslkey/tst_qsslkey.cpp
index ea5a265af0..e86dcb83e8 100644
--- a/tests/auto/network/ssl/qsslkey/tst_qsslkey.cpp
+++ b/tests/auto/network/ssl/qsslkey/tst_qsslkey.cpp
@@ -42,7 +42,7 @@
#include <QtCore/qlist.h>
#ifdef QT_BUILD_INTERNAL
- #ifndef QT_NO_SSL
+ #if QT_CONFIG(ssl)
#include "private/qsslkey_p.h"
#define TEST_CRYPTO
#endif
@@ -79,7 +79,7 @@ public:
public slots:
void initTestCase();
-#ifndef QT_NO_SSL
+#if QT_CONFIG(ssl)
private slots:
void emptyConstructor();
@@ -107,7 +107,7 @@ private slots:
void encrypt();
#endif
-#endif
+#endif // ssl
private:
QString testDataDir;
@@ -182,7 +182,7 @@ void tst_QSslKey::initTestCase()
}
}
-#ifndef QT_NO_SSL
+#if QT_CONFIG(ssl)
static QByteArray readFile(const QString &absFilePath)
{
@@ -225,7 +225,7 @@ void tst_QSslKey::createPlainTestRows(bool pemOnly)
if (keyInfo.fileInfo.fileName().contains("RC2-64"))
continue; // Schannel treats RC2 as 128 bit
#endif
-#if !defined(QT_NO_SSL) && defined(QT_NO_OPENSSL) // generic backend
+#if QT_CONFIG(ssl) && defined(QT_NO_OPENSSL) // generic backend
if (keyInfo.fileInfo.fileName().contains(QRegularExpression("-aes\\d\\d\\d-")))
continue; // No AES support in the generic back-end
if (keyInfo.fileInfo.fileName().contains("pkcs8-pkcs12"))
@@ -331,7 +331,7 @@ void tst_QSslKey::constructorHandle()
#endif
}
-#endif
+#endif // !QT_NO_OPENSSL
void tst_QSslKey::copyAndAssign_data()
{
@@ -527,11 +527,11 @@ void tst_QSslKey::passphraseChecks_data()
QTest::newRow("DES") << QString(testDataDir + "rsa-with-passphrase-des.pem") << pass;
QTest::newRow("3DES") << QString(testDataDir + "rsa-with-passphrase-3des.pem") << pass;
QTest::newRow("RC2") << QString(testDataDir + "rsa-with-passphrase-rc2.pem") << pass;
-#if (!defined(QT_NO_OPENSSL) && !defined(OPENSSL_NO_AES)) || (defined(QT_NO_OPENSSL) && QT_CONFIG(ssl))
+#if defined(QT_NO_OPENSSL) || !defined(OPENSSL_NO_AES)
QTest::newRow("AES128") << QString(testDataDir + "rsa-with-passphrase-aes128.pem") << aesPass;
QTest::newRow("AES192") << QString(testDataDir + "rsa-with-passphrase-aes192.pem") << aesPass;
QTest::newRow("AES256") << QString(testDataDir + "rsa-with-passphrase-aes256.pem") << aesPass;
-#endif // (OpenSSL && AES) || generic backend
+#endif // Generic backend || OpenSSL built with AES
}
void tst_QSslKey::passphraseChecks()
@@ -614,7 +614,9 @@ Q_DECLARE_METATYPE(QSslKeyPrivate::Cipher)
void tst_QSslKey::encrypt_data()
{
- QTest::addColumn<QSslKeyPrivate::Cipher>("cipher");
+ using QTlsPrivate::Cipher;
+
+ QTest::addColumn<Cipher>("cipher");
QTest::addColumn<QByteArray>("key");
QTest::addColumn<QByteArray>("plainText");
QTest::addColumn<QByteArray>("cipherText");
@@ -622,131 +624,131 @@ void tst_QSslKey::encrypt_data()
QByteArray iv("abcdefgh");
QTest::newRow("DES-CBC, length 0")
- << QSslKeyPrivate::DesCbc << QByteArray("01234567")
+ << Cipher::DesCbc << QByteArray("01234567")
<< QByteArray()
<< QByteArray::fromHex("956585228BAF9B1F")
<< iv;
QTest::newRow("DES-CBC, length 1")
- << QSslKeyPrivate::DesCbc << QByteArray("01234567")
+ << Cipher::DesCbc << QByteArray("01234567")
<< QByteArray(1, 'a')
<< QByteArray::fromHex("E6880AF202BA3C12")
<< iv;
QTest::newRow("DES-CBC, length 2")
- << QSslKeyPrivate::DesCbc << QByteArray("01234567")
+ << Cipher::DesCbc << QByteArray("01234567")
<< QByteArray(2, 'a')
<< QByteArray::fromHex("A82492386EED6026")
<< iv;
QTest::newRow("DES-CBC, length 3")
- << QSslKeyPrivate::DesCbc << QByteArray("01234567")
+ << Cipher::DesCbc << QByteArray("01234567")
<< QByteArray(3, 'a')
<< QByteArray::fromHex("90B76D5B79519CBA")
<< iv;
QTest::newRow("DES-CBC, length 4")
- << QSslKeyPrivate::DesCbc << QByteArray("01234567")
+ << Cipher::DesCbc << QByteArray("01234567")
<< QByteArray(4, 'a')
<< QByteArray::fromHex("63E3DD6FED87052A")
<< iv;
QTest::newRow("DES-CBC, length 5")
- << QSslKeyPrivate::DesCbc << QByteArray("01234567")
+ << Cipher::DesCbc << QByteArray("01234567")
<< QByteArray(5, 'a')
<< QByteArray::fromHex("03ACDB0EACBDFA94")
<< iv;
QTest::newRow("DES-CBC, length 6")
- << QSslKeyPrivate::DesCbc << QByteArray("01234567")
+ << Cipher::DesCbc << QByteArray("01234567")
<< QByteArray(6, 'a')
<< QByteArray::fromHex("7D95024E42A3A88A")
<< iv;
QTest::newRow("DES-CBC, length 7")
- << QSslKeyPrivate::DesCbc << QByteArray("01234567")
+ << Cipher::DesCbc << QByteArray("01234567")
<< QByteArray(7, 'a')
<< QByteArray::fromHex("5003436B8A8E42E9")
<< iv;
QTest::newRow("DES-CBC, length 8")
- << QSslKeyPrivate::DesCbc << QByteArray("01234567")
+ << Cipher::DesCbc << QByteArray("01234567")
<< QByteArray(8, 'a')
<< QByteArray::fromHex("E4C1F054BF5521C0A4A0FD4A2BC6C1B1")
<< iv;
QTest::newRow("DES-EDE3-CBC, length 0")
- << QSslKeyPrivate::DesEde3Cbc << QByteArray("0123456789abcdefghijklmn")
+ << Cipher::DesEde3Cbc << QByteArray("0123456789abcdefghijklmn")
<< QByteArray()
<< QByteArray::fromHex("3B2B4CD0B0FD495F")
<< iv;
QTest::newRow("DES-EDE3-CBC, length 8")
- << QSslKeyPrivate::DesEde3Cbc << QByteArray("0123456789abcdefghijklmn")
+ << Cipher::DesEde3Cbc << QByteArray("0123456789abcdefghijklmn")
<< QByteArray(8, 'a')
<< QByteArray::fromHex("F2A5A87763C54A72A3224103D90CDB03")
<< iv;
QTest::newRow("RC2-40-CBC, length 0")
- << QSslKeyPrivate::Rc2Cbc << QByteArray("01234")
+ << Cipher::Rc2Cbc << QByteArray("01234")
<< QByteArray()
<< QByteArray::fromHex("6D05D52392FF6E7A")
<< iv;
QTest::newRow("RC2-40-CBC, length 8")
- << QSslKeyPrivate::Rc2Cbc << QByteArray("01234")
+ << Cipher::Rc2Cbc << QByteArray("01234")
<< QByteArray(8, 'a')
<< QByteArray::fromHex("75768E64C5749072A5D168F3AFEB0005")
<< iv;
QTest::newRow("RC2-64-CBC, length 0")
- << QSslKeyPrivate::Rc2Cbc << QByteArray("01234567")
+ << Cipher::Rc2Cbc << QByteArray("01234567")
<< QByteArray()
<< QByteArray::fromHex("ADAE6BF70F420130")
<< iv;
QTest::newRow("RC2-64-CBC, length 8")
- << QSslKeyPrivate::Rc2Cbc << QByteArray("01234567")
+ << Cipher::Rc2Cbc << QByteArray("01234567")
<< QByteArray(8, 'a')
<< QByteArray::fromHex("C7BF5C80AFBE9FBEFBBB9FD935F6D0DF")
<< iv;
QTest::newRow("RC2-128-CBC, length 0")
- << QSslKeyPrivate::Rc2Cbc << QByteArray("012345679abcdefg")
+ << Cipher::Rc2Cbc << QByteArray("012345679abcdefg")
<< QByteArray()
<< QByteArray::fromHex("1E965D483A13C8FB")
<< iv;
QTest::newRow("RC2-128-CBC, length 8")
- << QSslKeyPrivate::Rc2Cbc << QByteArray("012345679abcdefg")
+ << Cipher::Rc2Cbc << QByteArray("012345679abcdefg")
<< QByteArray(8, 'a')
<< QByteArray::fromHex("5AEC1A5B295660B02613454232F7DECE")
<< iv;
-#if (!defined(QT_NO_OPENSSL) && !defined(OPENSSL_NO_AES)) || (defined(QT_NO_OPENSSL) && QT_CONFIG(ssl))
+#if defined(QT_NO_OPENSSL) || !defined(OPENSSL_NO_AES)
// AES needs a longer IV
iv = QByteArray("abcdefghijklmnop");
QTest::newRow("AES-128-CBC, length 0")
- << QSslKeyPrivate::Aes128Cbc << QByteArray("012345679abcdefg")
+ << Cipher::Aes128Cbc << QByteArray("012345679abcdefg")
<< QByteArray()
<< QByteArray::fromHex("28DE1A9AA26601C30DD2527407121D1A")
<< iv;
QTest::newRow("AES-128-CBC, length 8")
- << QSslKeyPrivate::Aes128Cbc << QByteArray("012345679abcdefg")
+ << Cipher::Aes128Cbc << QByteArray("012345679abcdefg")
<< QByteArray(8, 'a')
<< QByteArray::fromHex("08E880B1BA916F061C1E801D7F44D0EC")
<< iv;
QTest::newRow("AES-192-CBC, length 0")
- << QSslKeyPrivate::Aes192Cbc << QByteArray("0123456789abcdefghijklmn")
+ << Cipher::Aes192Cbc << QByteArray("0123456789abcdefghijklmn")
<< QByteArray()
<< QByteArray::fromHex("E169E0E205CDC2BA895B7CF6097673B1")
<< iv;
QTest::newRow("AES-192-CBC, length 8")
- << QSslKeyPrivate::Aes192Cbc << QByteArray("0123456789abcdefghijklmn")
+ << Cipher::Aes192Cbc << QByteArray("0123456789abcdefghijklmn")
<< QByteArray(8, 'a')
<< QByteArray::fromHex("3A227D6A3A13237316D30AA17FF9B0A7")
<< iv;
QTest::newRow("AES-256-CBC, length 0")
- << QSslKeyPrivate::Aes256Cbc << QByteArray("0123456789abcdefghijklmnopqrstuv")
+ << Cipher::Aes256Cbc << QByteArray("0123456789abcdefghijklmnopqrstuv")
<< QByteArray()
<< QByteArray::fromHex("4BAACAA0D22199C97DE206C465B7B14A")
<< iv;
QTest::newRow("AES-256-CBC, length 8")
- << QSslKeyPrivate::Aes256Cbc << QByteArray("0123456789abcdefghijklmnopqrstuv")
+ << Cipher::Aes256Cbc << QByteArray("0123456789abcdefghijklmnopqrstuv")
<< QByteArray(8, 'a')
<< QByteArray::fromHex("879C8C25EC135CDF0B14490A0A7C2F67")
<< iv;
-#endif // (OpenSSL && AES) || generic backend
+#endif // Generic backend || OpenSSL built with AES
}
void tst_QSslKey::encrypt()
@@ -769,9 +771,9 @@ void tst_QSslKey::encrypt()
QByteArray decrypted = QSslKeyPrivate::decrypt(cipher, cipherText, key, iv);
QCOMPARE(decrypted, plainText);
}
-#endif
+#endif // TEST_CRYPTO
-#endif
+#endif // ssl
QTEST_MAIN(tst_QSslKey)
#include "tst_qsslkey.moc"
diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
index bb77668b81..d982368086 100644
--- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
+++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
@@ -59,7 +59,6 @@
#include "private/qtlsbackend_p.h"
#ifndef QT_NO_OPENSSL
-#include "private/qsslsocket_openssl_p.h"
#include "private/qsslsocket_openssl_symbols_p.h"
#endif // QT_NO_OPENSSL
@@ -165,6 +164,7 @@ public slots:
#ifndef QT_NO_SSL
private slots:
+ void activeBackend();
void backends();
void constructing();
void configNoOnDemandLoad();
@@ -243,9 +243,6 @@ private slots:
void writeBigChunk();
void blacklistedCertificates();
void versionAccessors();
-#ifndef QT_NO_OPENSSL
- void sslOptions();
-#endif
void encryptWithoutConnecting();
void resume_data();
void resume();
@@ -438,54 +435,6 @@ void tst_QSslSocket::initTestCase()
QSKIP("No network test server available");
#endif // QT_TEST_SERVER
#endif // QT_NO_SSL
-
- // Since a backend can be loaded only once by an application (this test in our case),
- // we do backend testing here.
-
- // Before we tried to load anything, the active is the same thing as the default one:
- QCOMPARE(QSslSocket::activeBackend(), QTlsBackendFactory::defaultBackendName());
-
- const QString nonExistingBackend = QStringLiteral("TheQtTLS");
- QCOMPARE(QSslSocket::setActiveBackend(nonExistingBackend), false);
- QCOMPARE(QSslSocket::supportedProtocols(nonExistingBackend).size(), 0);
- QCOMPARE(QSslSocket::supportedFeatures(nonExistingBackend), QList<QSsl::SupportedFeature>());
- QCOMPARE(QSslSocket::implementedClasses(nonExistingBackend), QList<QSsl::ImplementedClass>());
-
- const QString backendName = QSslSocket::activeBackend();
- // Implemented by all our existing backends:
- const auto implemented = QSsl::ImplementedClass::Socket;
- const auto supportedFt = QSsl::SupportedFeature::ClientSideAlpn;
-
- QVERIFY(QSslSocket::availableBackends().contains(backendName));
- QCOMPARE(QSslSocket::setActiveBackend(backendName), true);
- QCOMPARE(QSslSocket::activeBackend(), backendName);
- QCOMPARE(QSslSocket::setActiveBackend(backendName), true); // We can do it again.
- QCOMPARE(QSslSocket::activeBackend(), backendName);
-
- const auto protocols = QSslSocket::supportedProtocols();
- QVERIFY(protocols.size() > 0);
- // 'Any' and 'Secure', since they are always present:
- QVERIFY(protocols.contains(QSsl::AnyProtocol));
- QVERIFY(protocols.contains(QSsl::SecureProtocols));
-
- const auto protocolsForNamed = QSslSocket::supportedProtocols(backendName);
- QCOMPARE(protocols, protocolsForNamed);
- // Any and secure, new versions are coming, old
- // go away, nothing more specific.
- QVERIFY(protocolsForNamed.contains(QSsl::AnyProtocol));
- QVERIFY(protocolsForNamed.contains(QSsl::SecureProtocols));
- QCOMPARE(QSslSocket::isProtocolSupported(QSsl::SecureProtocols), true);
- QCOMPARE(QSslSocket::isProtocolSupported(QSsl::SecureProtocols, backendName), true);
-
- const auto classes = QSslSocket::implementedClasses();
- QVERIFY(classes.contains(implemented));
- QVERIFY(QSslSocket::isClassImplemented(implemented));
- QVERIFY(QSslSocket::isClassImplemented(implemented, backendName));
-
- const auto features = QSslSocket::supportedFeatures();
- QVERIFY(features.contains(QSsl::SupportedFeature(supportedFt)));
- QVERIFY(QSslSocket::isFeatureSupported(QSsl::SupportedFeature(supportedFt)));
- QVERIFY(QSslSocket::isFeatureSupported(QSsl::SupportedFeature(supportedFt), backendName));
}
void tst_QSslSocket::init()
@@ -564,19 +513,62 @@ void tst_QSslSocket::proxyAuthenticationRequired(const QNetworkProxy &, QAuthent
#ifndef QT_NO_SSL
-struct MockTlsBackend : QTlsBackend
+void tst_QSslSocket::activeBackend()
{
- MockTlsBackend(const QString &n) : name(n) {}
- QString backendName() const override
- {
- return name;
- }
- QString name;
-};
+ QFETCH_GLOBAL(const bool, setProxy);
+ if (setProxy) // Not interesting for backend test.
+ return;
+
+ QCOMPARE(QSslSocket::activeBackend(), QTlsBackend::defaultBackendName());
+
+ // We cannot set non-existing as active:
+ const QString nonExistingBackend = QStringLiteral("TheQtTLS");
+ QCOMPARE(QSslSocket::setActiveBackend(nonExistingBackend), false);
+ QCOMPARE(QSslSocket::supportedProtocols(nonExistingBackend).size(), 0);
+ QCOMPARE(QSslSocket::supportedFeatures(nonExistingBackend), QList<QSsl::SupportedFeature>());
+ QCOMPARE(QSslSocket::implementedClasses(nonExistingBackend), QList<QSsl::ImplementedClass>());
+
+ const QString backendName = QSslSocket::activeBackend();
+ // Implemented by all our existing backends:
+ const auto implemented = QSsl::ImplementedClass::Socket;
+ const auto supportedFt = QSsl::SupportedFeature::ClientSideAlpn;
-struct MockTlsFactory : QTlsBackendFactory
+ QVERIFY(QSslSocket::availableBackends().contains(backendName));
+ QCOMPARE(QSslSocket::setActiveBackend(backendName), true);
+ QCOMPARE(QSslSocket::activeBackend(), backendName);
+ QCOMPARE(QSslSocket::setActiveBackend(backendName), true); // We can do it again.
+ QCOMPARE(QSslSocket::activeBackend(), backendName);
+
+ const auto protocols = QSslSocket::supportedProtocols();
+ QVERIFY(protocols.size() > 0);
+ // 'Any' and 'Secure', since they are always present:
+ QVERIFY(protocols.contains(QSsl::AnyProtocol));
+ QVERIFY(protocols.contains(QSsl::SecureProtocols));
+
+ const auto protocolsForNamed = QSslSocket::supportedProtocols(backendName);
+ QCOMPARE(protocols, protocolsForNamed);
+ // Any and secure, new versions are coming, old
+ // go away, nothing more specific.
+ QVERIFY(protocolsForNamed.contains(QSsl::AnyProtocol));
+ QVERIFY(protocolsForNamed.contains(QSsl::SecureProtocols));
+ QCOMPARE(QSslSocket::isProtocolSupported(QSsl::SecureProtocols), true);
+ QCOMPARE(QSslSocket::isProtocolSupported(QSsl::SecureProtocols, backendName), true);
+
+ const auto classes = QSslSocket::implementedClasses();
+ QVERIFY(classes.contains(implemented));
+ QVERIFY(QSslSocket::isClassImplemented(implemented));
+ QVERIFY(QSslSocket::isClassImplemented(implemented, backendName));
+
+ const auto features = QSslSocket::supportedFeatures();
+ QVERIFY(features.contains(QSsl::SupportedFeature(supportedFt)));
+ QVERIFY(QSslSocket::isFeatureSupported(QSsl::SupportedFeature(supportedFt)));
+ QVERIFY(QSslSocket::isFeatureSupported(QSsl::SupportedFeature(supportedFt), backendName));
+}
+
+namespace {
+struct MockTlsBackend : QTlsBackend
{
- MockTlsFactory(const QString &mockName) : name(mockName)
+ MockTlsBackend(const QString &mockName) : name(mockName)
{
}
QString backendName() const override
@@ -596,26 +588,24 @@ struct MockTlsFactory : QTlsBackendFactory
{
return classes;
}
- QTlsBackend *create() const override
- {
- auto tls = new MockTlsBackend(name);
- return tls;
- }
+
QString name;
QList<QSsl::ImplementedClass> classes;
QList<QSsl::SupportedFeature> features;
QList<QSsl::SslProtocol> protocols;
};
+} // Unnamed backend.
+
void tst_QSslSocket::backends()
{
QFETCH_GLOBAL(const bool, setProxy);
- if (setProxy)
- QSKIP("Proxy is not interesting for backend test");
+ if (setProxy) // Not interesting for backend test.
+ return;
// We are here, protected by !QT_NO_SSL. Some backend must be pre-existing.
// Let's test the 'real' backend:
- auto backendNames = QTlsBackendFactory::availableBackendNames();
+ auto backendNames = QTlsBackend::availableBackendNames();
const auto sizeBefore = backendNames.size();
QVERIFY(sizeBefore > 0);
@@ -628,11 +618,9 @@ void tst_QSslSocket::backends()
const auto builtinFeatures = QSslSocket::supportedFeatures(builtinBackend);
QVERIFY(builtinFeatures.contains(QSsl::SupportedFeature::ClientSideAlpn));
- {
- // Verify that non-dummy backend can be created (and delete it):
- const std::unique_ptr<QTlsBackend> systemBackend(QTlsBackendFactory::create(backendNames.first()));
- QVERIFY(systemBackend.get());
- }
+ // Verify that non-dummy backend can be created (and delete it):
+ auto *systemBackend = QTlsBackend::findBackend(builtinBackend);
+ QVERIFY(systemBackend);
const auto protocols = QList<QSsl::SslProtocol>{QSsl::SecureProtocols};
const auto classes = QList<QSsl::ImplementedClass>{QSsl::ImplementedClass::Socket};
@@ -646,12 +634,16 @@ void tst_QSslSocket::backends()
QVERIFY(!backendNames.contains(nameB));
QVERIFY(!backendNames.contains(nonExisting));
{
- MockTlsFactory factoryA(nameA);
- backendNames = QTlsBackendFactory::availableBackendNames();
+ MockTlsBackend factoryA(nameA);
+ backendNames = QTlsBackend::availableBackendNames();
QVERIFY(backendNames.contains(nameA));
QVERIFY(!backendNames.contains(nameB));
QVERIFY(!backendNames.contains(nonExisting));
+ const auto *backendA = QTlsBackend::findBackend(nameA);
+ QVERIFY(backendA);
+ QCOMPARE(backendA->backendName(), nameA);
+
QCOMPARE(factoryA.supportedFeatures().size(), 0);
QCOMPARE(factoryA.supportedProtocols().size(), 0);
QCOMPARE(factoryA.implementedClasses().size(), 0);
@@ -666,23 +658,19 @@ void tst_QSslSocket::backends()
QCOMPARE(factoryA.implementedClasses(), classes);
// That's a helper function (static member function):
- QCOMPARE(QTlsBackendFactory::supportedProtocols(nameA), protocols);
- QCOMPARE(QTlsBackendFactory::supportedFeatures(nameA), features);
- QCOMPARE(QTlsBackendFactory::implementedClasses(nameA), classes);
+ QCOMPARE(QTlsBackend::supportedProtocols(nameA), protocols);
+ QCOMPARE(QTlsBackend::supportedFeatures(nameA), features);
+ QCOMPARE(QTlsBackend::implementedClasses(nameA), classes);
- MockTlsFactory factoryB(nameB);
- QVERIFY(QTlsBackendFactory::availableBackendNames().contains(nameA));
- QVERIFY(QTlsBackendFactory::availableBackendNames().contains(nameB));
- QVERIFY(!QTlsBackendFactory::availableBackendNames().contains(nonExisting));
-
- const std::unique_ptr<QTlsBackend> backendA(QTlsBackendFactory::create(nameA));
- QVERIFY(backendA.get());
- QCOMPARE(backendA->backendName(), nameA);
+ MockTlsBackend factoryB(nameB);
+ QVERIFY(QTlsBackend::availableBackendNames().contains(nameA));
+ QVERIFY(QTlsBackend::availableBackendNames().contains(nameB));
+ QVERIFY(!QTlsBackend::availableBackendNames().contains(nonExisting));
- const std::unique_ptr<QTlsBackend> nullBackend(QTlsBackendFactory::create(nonExisting));
- QCOMPARE(nullBackend.get(), nullptr);
+ const auto *nullBackend = QTlsBackend::findBackend(nonExisting);
+ QCOMPARE(nullBackend, nullptr);
}
- backendNames = QTlsBackendFactory::availableBackendNames();
+ backendNames = QTlsBackend::availableBackendNames();
QCOMPARE(backendNames.size(), sizeBefore);
// Check we cleaned up our factories:
QVERIFY(!backendNames.contains(nameA));
@@ -3009,60 +2997,6 @@ void tst_QSslSocket::versionAccessors()
qDebug() << QString::number(QSslSocket::sslLibraryVersionNumber(), 16);
}
-#ifndef QT_NO_OPENSSL
-void tst_QSslSocket::sslOptions()
-{
- if (!QSslSocket::supportsSsl())
- return;
-
-#ifdef SSL_OP_NO_COMPRESSION
- QCOMPARE(QSslSocketBackendPrivate::setupOpenSslOptions(QSsl::SecureProtocols,
- QSslConfigurationPrivate::defaultSslOptions),
- long(SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_COMPRESSION|SSL_OP_CIPHER_SERVER_PREFERENCE));
-#else
- QCOMPARE(QSslSocketBackendPrivate::setupOpenSslOptions(QSsl::SecureProtocols,
- QSslConfigurationPrivate::defaultSslOptions),
- long(SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_CIPHER_SERVER_PREFERENCE));
-#endif
-
- QCOMPARE(QSslSocketBackendPrivate::setupOpenSslOptions(QSsl::SecureProtocols,
- QSsl::SslOptionDisableEmptyFragments
- |QSsl::SslOptionDisableLegacyRenegotiation),
- long(SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_CIPHER_SERVER_PREFERENCE));
-
-#ifdef SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION
- QCOMPARE(QSslSocketBackendPrivate::setupOpenSslOptions(QSsl::SecureProtocols,
- QSsl::SslOptionDisableEmptyFragments),
- long((SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION|SSL_OP_CIPHER_SERVER_PREFERENCE)));
-#endif
-
-#ifdef SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
- QCOMPARE(QSslSocketBackendPrivate::setupOpenSslOptions(QSsl::SecureProtocols,
- QSsl::SslOptionDisableLegacyRenegotiation),
- long((SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_CIPHER_SERVER_PREFERENCE) & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS));
-#endif
-
-#ifdef SSL_OP_NO_TICKET
- QCOMPARE(QSslSocketBackendPrivate::setupOpenSslOptions(QSsl::SecureProtocols,
- QSsl::SslOptionDisableEmptyFragments
- |QSsl::SslOptionDisableLegacyRenegotiation
- |QSsl::SslOptionDisableSessionTickets),
- long((SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET|SSL_OP_CIPHER_SERVER_PREFERENCE)));
-#endif
-
-#ifdef SSL_OP_NO_TICKET
-#ifdef SSL_OP_NO_COMPRESSION
- QCOMPARE(QSslSocketBackendPrivate::setupOpenSslOptions(QSsl::SecureProtocols,
- QSsl::SslOptionDisableEmptyFragments
- |QSsl::SslOptionDisableLegacyRenegotiation
- |QSsl::SslOptionDisableSessionTickets
- |QSsl::SslOptionDisableCompression),
- long((SSL_OP_ALL|SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET|SSL_OP_NO_COMPRESSION|SSL_OP_CIPHER_SERVER_PREFERENCE)));
-#endif
-#endif
-}
-#endif
-
void tst_QSslSocket::encryptWithoutConnecting()
{
if (!QSslSocket::supportsSsl())