From b9b48464df15de89d3dccb78944e89c1668466bf Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 20 Aug 2019 14:00:22 +0200 Subject: tst_http2::goaway - run in ALPN mode only I was observing rare crashes on my mac, where I was using SecureTransport. This would imply both the client (the test) and the server were working in h2c mode. But this is against the test's logic - the first request will be HTTP/1.1 (and upgrading protocol) and I wanted to send 3 HTTP/2 requests instead. Fixes: QTBUG-77476 Change-Id: I048ca242e2096ca36dd112277807d1fee530150c Reviewed-by: Edward Welbourne --- tests/auto/network/access/http2/tst_http2.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/auto/network') diff --git a/tests/auto/network/access/http2/tst_http2.cpp b/tests/auto/network/access/http2/tst_http2.cpp index 4b4b8d541a..fe40d1c723 100644 --- a/tests/auto/network/access/http2/tst_http2.cpp +++ b/tests/auto/network/access/http2/tst_http2.cpp @@ -455,6 +455,9 @@ void tst_Http2::goaway_data() // - server waits for some time (enough for ur to init several streams on a // client side); then suddenly it replies with GOAWAY, never processing any // request. + if (clearTextHTTP2) + QSKIP("This test requires TLS with ALPN to work"); + QTest::addColumn("responseTimeoutMS"); QTest::newRow("ImmediateGOAWAY") << 0; QTest::newRow("DelayedGOAWAY") << 1000; -- cgit v1.2.3 From 43983b0b6fe2ca0d6f42edcec19115fb16753b75 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Mon, 2 Sep 2019 16:45:00 +0200 Subject: Remove QOperatingSystemVersion::WindowsVista The minimum supported version is Windows 7. Remove QOperatingSystemVersion::WindowsVista added by b0cd007335853f283c47ffb0f5611d14e6dbe84b and replace with "true" wherever it was used. Change-Id: I08c0208467b655a921b6773f77d8bc099be69031 Reviewed-by: Friedemann Kleint Reviewed-by: Thiago Macieira --- tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'tests/auto/network') diff --git a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp index fc5a7d1fab..849d8b0ed1 100644 --- a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp +++ b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp @@ -881,11 +881,6 @@ void tst_QTcpServer::serverAddress_data() { QTest::addColumn("listenAddress"); QTest::addColumn("serverAddress"); -#ifdef Q_OS_WIN - if (QOperatingSystemVersion::current() < QOperatingSystemVersion::WindowsVista) - QTest::newRow("Any") << QHostAddress(QHostAddress::Any) << QHostAddress(QHostAddress::AnyIPv4); //windows XP doesn't support dual stack sockets - else -#endif if (QtNetworkSettings::hasIPv6()) QTest::newRow("Any") << QHostAddress(QHostAddress::Any) << QHostAddress(QHostAddress::Any); else -- cgit v1.2.3 From 6cee284001adf9da42b347a074cbff3cb92621b2 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 10 Sep 2019 16:39:43 +0200 Subject: Fix mis-handling of actual TLD in qIsEffectiveTLD() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the domain passed down is an actual TLD that's the subject of a * rule, e.g. "ck" subject to *.ck, then we were finding no dot in it and concluding that it couldn't be the subject of a * rule. Added a test for the specific .ck case and commented on where we could get some canonical test data that I tripped over while researching this. Cross-reference the cookie-jar test from the QUrl test, too. Fixes: QTBUG-78097 Change-Id: Id858a9dae22e6b306a68df3fc199e0160f537159 Reviewed-by: Mårten Nordheim Reviewed-by: Thiago Macieira --- tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/auto/network') diff --git a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp index 1ef2c118b9..0924b1e223 100644 --- a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp +++ b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp @@ -166,6 +166,10 @@ void tst_QNetworkCookieJar::setCookiesFromUrl_data() // 2. anything .ck is an effective TLD ('*.ck'), but 'www.ck' is an exception result.clear(); preset.clear(); + cookie.setDomain(".ck"); + QTest::newRow("effective-tld.ck-denied") << preset << cookie << "http://foo.ck" << result << false; + result.clear(); + preset.clear(); cookie.setDomain(".foo.ck"); result += cookie; QTest::newRow("effective-tld2-accepted2") << preset << cookie << "http://foo.ck" << result << true; -- cgit v1.2.3 From 4d289edb14aeb4976218cc306bfc514e37521b82 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 22 Jul 2019 10:45:26 +0200 Subject: Disable debug-and-release builds for MinGW MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The requirement to separate debug and release DLLs on Windows stems from the Visual Studio C run-time library appearing in two different variants (debug and release) and not mixing well. It's possible to perform builds without optimzations and with debug symbols while linking against the release version of the C run-time, but at the same time the debug version of the run-time brings other developer visible advantages. MinGW on the other hand does not have this distinction, does not ship with separate DLLS and does also not require the VS C runtime library. Therefore we do not need this separation for MinGW, which means that our packages can be reduced in size and application developers wishing to debug their applications do not have to use debug builds of the Qt libraries or run into Qt internal debug code. Task-number: QTBUG-78445 Change-Id: Idf588606091298dc44262c4c89e689df18d34747 Reviewed-by: Cristian Adam Reviewed-by: Jörg Bornemann --- tests/auto/network/socket/qudpsocket/test/test.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto/network') diff --git a/tests/auto/network/socket/qudpsocket/test/test.pro b/tests/auto/network/socket/qudpsocket/test/test.pro index 969e4d72cf..994b360370 100644 --- a/tests/auto/network/socket/qudpsocket/test/test.pro +++ b/tests/auto/network/socket/qudpsocket/test/test.pro @@ -6,7 +6,7 @@ QT = core network testlib MOC_DIR=tmp -win32 { +win32:debug_and_release { CONFIG(debug, debug|release) { DESTDIR = ../debug } else { -- cgit v1.2.3 From 65cb6f5f298d9b6f3d36c492757c1b7c5dbe03ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Mon, 23 Sep 2019 15:45:48 +0200 Subject: tst_qsslsocket: Update some QSslConfiguration usage Following the deprecation of add[Default]CaCertificate[s] let's update the uses of it. While we're doing this, let's also use QSslConfiguration more in some places where it makes sense. Change-Id: I2c9e7c73fee8a405492410378f2babe67d3a3f25 Reviewed-by: Jesus Fernandez --- .../auto/network/ssl/qsslsocket/tst_qsslsocket.cpp | 52 +++++++++++++--------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'tests/auto/network') diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp index 4e02320362..2fef31cdc2 100644 --- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -823,7 +823,9 @@ void tst_QSslSocket::connectToHostEncrypted() socket->setProtocol(QSsl::SslProtocol::TlsV1_1); #endif this->socket = socket.data(); - QVERIFY(socket->addCaCertificates(httpServerCertChainPath())); + auto config = socket->sslConfiguration(); + QVERIFY(config.addCaCertificates(httpServerCertChainPath())); + socket->setSslConfiguration(config); #ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND connect(socket.data(), SIGNAL(sslErrors(QList)), this, SLOT(untrustedWorkaroundSlot(QList))); @@ -860,7 +862,9 @@ void tst_QSslSocket::connectToHostEncryptedWithVerificationPeerName() #endif this->socket = socket.data(); - socket->addCaCertificates(httpServerCertChainPath()); + auto config = socket->sslConfiguration(); + config.addCaCertificates(httpServerCertChainPath()); + socket->setSslConfiguration(config); #ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND connect(socket.data(), SIGNAL(sslErrors(QList)), this, SLOT(untrustedWorkaroundSlot(QList))); @@ -965,7 +969,9 @@ void tst_QSslSocket::peerCertificateChain() this->socket = socket.data(); QList caCertificates = QSslCertificate::fromPath(httpServerCertChainPath()); QCOMPARE(caCertificates.count(), 1); - socket->addCaCertificates(caCertificates); + auto config = socket->sslConfiguration(); + config.addCaCertificates(caCertificates); + socket->setSslConfiguration(config); #ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND connect(socket.data(), SIGNAL(sslErrors(QList)), this, SLOT(untrustedWorkaroundSlot(QList))); @@ -1224,10 +1230,10 @@ signals: protected: void incomingConnection(qintptr socketDescriptor) { + QSslConfiguration configuration = config; socket = new QSslSocket(this); - socket->setSslConfiguration(config); - socket->setPeerVerifyMode(peerVerifyMode); - socket->setProtocol(protocol); + configuration.setPeerVerifyMode(peerVerifyMode); + configuration.setProtocol(protocol); if (ignoreSslErrors) connect(socket, SIGNAL(sslErrors(QList)), this, SLOT(ignoreErrorSlot())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SIGNAL(socketError(QAbstractSocket::SocketError))); @@ -1236,14 +1242,14 @@ protected: QVERIFY(file.open(QIODevice::ReadOnly)); QSslKey key(file.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey); QVERIFY(!key.isNull()); - socket->setPrivateKey(key); + configuration.setPrivateKey(key); // Add CA certificates to verify client certificate if (!addCaCertificates.isEmpty()) { QList caCert = QSslCertificate::fromPath(addCaCertificates); QVERIFY(!caCert.isEmpty()); QVERIFY(!caCert.first().isNull()); - socket->addCaCertificates(caCert); + configuration.addCaCertificates(caCert); } // If we have a cert issued directly from the CA @@ -1251,9 +1257,8 @@ protected: QList localCert = QSslCertificate::fromPath(m_certFile); QVERIFY(!localCert.isEmpty()); QVERIFY(!localCert.first().isNull()); - socket->setLocalCertificate(localCert.first()); - } - else { + configuration.setLocalCertificate(localCert.first()); + } else { QList localCert = QSslCertificate::fromPath(m_certFile); QVERIFY(!localCert.isEmpty()); QVERIFY(!localCert.first().isNull()); @@ -1262,14 +1267,12 @@ protected: QVERIFY(!interCert.isEmpty()); QVERIFY(!interCert.first().isNull()); - socket->setLocalCertificateChain(localCert + interCert); + configuration.setLocalCertificateChain(localCert + interCert); } - if (!ciphers.isEmpty()) { - auto sslConfig = socket->sslConfiguration(); - sslConfig.setCiphers(ciphers); - socket->setSslConfiguration(sslConfig); - } + if (!ciphers.isEmpty()) + configuration.setCiphers(ciphers); + socket->setSslConfiguration(configuration); QVERIFY(socket->setSocketDescriptor(socketDescriptor, QAbstractSocket::ConnectedState)); QVERIFY(!socket->peerAddress().isNull()); @@ -1748,7 +1751,8 @@ void tst_QSslSocket::addDefaultCaCertificate() QCOMPARE(flukeCerts.size(), 1); QList globalCerts = QSslConfiguration::defaultConfiguration().caCertificates(); QVERIFY(!globalCerts.contains(flukeCerts.first())); - QSslSocket::addDefaultCaCertificate(flukeCerts.first()); + sslConfig.addCaCertificate(flukeCerts.first()); + QSslConfiguration::setDefaultConfiguration(sslConfig); QCOMPARE(QSslConfiguration::defaultConfiguration().caCertificates().size(), globalCerts.size() + 1); QVERIFY(QSslConfiguration::defaultConfiguration().caCertificates() @@ -1941,7 +1945,9 @@ void tst_QSslSocket::wildcard() // responds with the wildcard, and QSslSocket should accept that as a // valid connection. This was broken in 4.3.0. QSslSocketPtr socket = newSocket(); - socket->addCaCertificates(QLatin1String("certs/aspiriniks.ca.crt")); + auto config = socket->sslConfiguration(); + config.addCaCertificates(QLatin1String("certs/aspiriniks.ca.crt")); + socket->setSslConfiguration(config); this->socket = socket.data(); #ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND connect(socket, SIGNAL(sslErrors(QList)), @@ -2572,7 +2578,9 @@ void tst_QSslSocket::resetProxy() // make sure the connection works, and then set a nonsense proxy, and then // make sure it does not work anymore QSslSocket socket; - socket.addCaCertificates(httpServerCertChainPath()); + auto config = socket.sslConfiguration(); + config.addCaCertificates(httpServerCertChainPath()); + socket.setSslConfiguration(config); socket.setProxy(goodProxy); socket.connectToHostEncrypted(QtNetworkSettings::httpServerName(), 443); QVERIFY2(socket.waitForConnected(10000), qPrintable(socket.errorString())); @@ -2591,7 +2599,9 @@ void tst_QSslSocket::resetProxy() // set the nonsense proxy and make sure the connection does not work, // and then set the right proxy and make sure it works QSslSocket socket2; - socket2.addCaCertificates(httpServerCertChainPath()); + auto config2 = socket.sslConfiguration(); + config2.addCaCertificates(httpServerCertChainPath()); + socket2.setSslConfiguration(config2); socket2.setProxy(badProxy); socket2.connectToHostEncrypted(QtNetworkSettings::httpServerName(), 443); QVERIFY(! socket2.waitForConnected(10000)); -- cgit v1.2.3 From 13e0a36626bd75e631dd9536e795a494432b1945 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 10 Sep 2019 09:04:17 +0200 Subject: Retire SPDY protocol implementation (Qt6) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As it was superseded by HTTP/2. Bye, Speedy. Since it's Qt 6, we also fix the attribute's enumerator to fit our coding convention with HTTP2AllowedAttribute becoming Http2AllowedAttribute, and the same for HTTP2WasUsedAttribute. tst_qnetworkreply in 'benchmark' directory of qtbase/tests was updated - we have the logic they tested in preConnectEncrypted in tst_http2 now. Manual qnetworkreply test was updated (instead of SPDY in NPN failure we can use H2, the second test was deleted - again, auto-tested in tst_http2). Change-Id: I559c140c333ddf72664911c6e275b1d0d2b980a9 Task-number: QTBUG-78255 Reviewed-by: Mårten Nordheim --- tests/auto/network/access/access.pro | 1 - tests/auto/network/access/http2/tst_http2.cpp | 25 +- tests/auto/network/access/spdy/BLACKLIST | 7 - tests/auto/network/access/spdy/spdy.pro | 7 - tests/auto/network/access/spdy/tst_spdy.cpp | 693 -------------------------- 5 files changed, 9 insertions(+), 724 deletions(-) delete mode 100644 tests/auto/network/access/spdy/BLACKLIST delete mode 100644 tests/auto/network/access/spdy/spdy.pro delete mode 100644 tests/auto/network/access/spdy/tst_spdy.cpp (limited to 'tests/auto/network') diff --git a/tests/auto/network/access/access.pro b/tests/auto/network/access/access.pro index b140b5e9f2..d2b4d97b21 100644 --- a/tests/auto/network/access/access.pro +++ b/tests/auto/network/access/access.pro @@ -7,7 +7,6 @@ SUBDIRS=\ qnetworkrequest \ qhttpnetworkconnection \ qnetworkreply \ - spdy \ qnetworkcachemetadata \ qftp \ qhttpnetworkreply \ diff --git a/tests/auto/network/access/http2/tst_http2.cpp b/tests/auto/network/access/http2/tst_http2.cpp index c264956d7b..904cfd52b0 100644 --- a/tests/auto/network/access/http2/tst_http2.cpp +++ b/tests/auto/network/access/http2/tst_http2.cpp @@ -219,12 +219,12 @@ void tst_Http2::singleRequest_data() // 'Clear text' that should always work, either via the protocol upgrade // or as direct. - QTest::addRow("h2c-upgrade") << QNetworkRequest::HTTP2AllowedAttribute << H2Type::h2c; + QTest::addRow("h2c-upgrade") << QNetworkRequest::Http2AllowedAttribute << H2Type::h2c; QTest::addRow("h2c-direct") << QNetworkRequest::Http2DirectAttribute << H2Type::h2cDirect; if (!clearTextHTTP2) { // Qt with TLS where TLS-backend supports ALPN. - QTest::addRow("h2-ALPN") << QNetworkRequest::HTTP2AllowedAttribute << H2Type::h2Alpn; + QTest::addRow("h2-ALPN") << QNetworkRequest::Http2AllowedAttribute << H2Type::h2Alpn; } #if QT_CONFIG(ssl) @@ -429,7 +429,7 @@ void tst_Http2::pushPromise() url.setPath("/index.html"); QNetworkRequest request(url); - request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, QVariant(true)); + request.setAttribute(QNetworkRequest::Http2AllowedAttribute, QVariant(true)); request.setHttp2Configuration(params); auto reply = manager->get(request); @@ -455,7 +455,7 @@ void tst_Http2::pushPromise() url.setPath("/script.js"); QNetworkRequest promisedRequest(url); - promisedRequest.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, QVariant(true)); + promisedRequest.setAttribute(QNetworkRequest::Http2AllowedAttribute, QVariant(true)); reply = manager->get(promisedRequest); connect(reply, &QNetworkReply::finished, this, &tst_Http2::replyFinished); reply->ignoreSslErrors(); @@ -509,7 +509,7 @@ void tst_Http2::goaway() for (int i = 0; i < nRequests; ++i) { url.setPath(QString("/%1").arg(i)); QNetworkRequest request(url); - request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, QVariant(true)); + request.setAttribute(QNetworkRequest::Http2AllowedAttribute, QVariant(true)); replies[i] = manager->get(request); QCOMPARE(replies[i]->error(), QNetworkReply::NoError); void (QNetworkReply::*errorSignal)(QNetworkReply::NetworkError) = @@ -582,7 +582,7 @@ void tst_Http2::connectToHost_data() #if QT_CONFIG(ssl) QTest::addRow("encrypted-h2-direct") << QNetworkRequest::Http2DirectAttribute << H2Type::h2Direct; if (!clearTextHTTP2) - QTest::addRow("encrypted-h2-ALPN") << QNetworkRequest::HTTP2AllowedAttribute << H2Type::h2Alpn; + QTest::addRow("encrypted-h2-ALPN") << QNetworkRequest::Http2AllowedAttribute << H2Type::h2Alpn; #endif // QT_CONFIG(ssl) // This works for all configurations, tests 'preconnect-http' scheme: // h2 with protocol upgrade is not working for now (the logic is a bit @@ -725,7 +725,7 @@ void tst_Http2::maxFrameSize() #endif // QT_CONFIG(securetransport) auto connectionType = H2Type::h2Alpn; - auto attribute = QNetworkRequest::HTTP2AllowedAttribute; + auto attribute = QNetworkRequest::Http2AllowedAttribute; if (clearTextHTTP2) { connectionType = H2Type::h2Direct; attribute = QNetworkRequest::Http2DirectAttribute; @@ -825,7 +825,7 @@ void tst_Http2::sendRequest(int streamNumber, url.setPath(QString("/stream%1.html").arg(streamNumber)); QNetworkRequest request(url); - request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, QVariant(true)); + request.setAttribute(QNetworkRequest::Http2AllowedAttribute, QVariant(true)); request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, QVariant(true)); request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/plain")); request.setPriority(priority); @@ -932,20 +932,13 @@ void tst_Http2::replyFinished() QCOMPARE(reply->error(), QNetworkReply::NoError); - const QVariant http2Used(reply->attribute(QNetworkRequest::HTTP2WasUsedAttribute)); + const QVariant http2Used(reply->attribute(QNetworkRequest::Http2WasUsedAttribute)); if (!http2Used.isValid() || !http2Used.toBool()) stopEventLoop(); QVERIFY(http2Used.isValid()); QVERIFY(http2Used.toBool()); - const QVariant spdyUsed(reply->attribute(QNetworkRequest::SpdyWasUsedAttribute)); - if (!spdyUsed.isValid() || spdyUsed.toBool()) - stopEventLoop(); - - QVERIFY(spdyUsed.isValid()); - QVERIFY(!spdyUsed.toBool()); - const QVariant code(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute)); if (!code.isValid() || !code.canConvert() || code.value() != 200) stopEventLoop(); diff --git a/tests/auto/network/access/spdy/BLACKLIST b/tests/auto/network/access/spdy/BLACKLIST deleted file mode 100644 index 5cf79327be..0000000000 --- a/tests/auto/network/access/spdy/BLACKLIST +++ /dev/null @@ -1,7 +0,0 @@ -[download] -opensuse-leap -[upload] -opensuse-leap -ubuntu-18.04 -b2qt - diff --git a/tests/auto/network/access/spdy/spdy.pro b/tests/auto/network/access/spdy/spdy.pro deleted file mode 100644 index cdbe60a19b..0000000000 --- a/tests/auto/network/access/spdy/spdy.pro +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG += testcase -TARGET = tst_spdy -SOURCES += tst_spdy.cpp - -QT = core core-private network network-private testlib - -win32:CONFIG += insignificant_test # QTBUG-47128 diff --git a/tests/auto/network/access/spdy/tst_spdy.cpp b/tests/auto/network/access/spdy/tst_spdy.cpp deleted file mode 100644 index f4a5976558..0000000000 --- a/tests/auto/network/access/spdy/tst_spdy.cpp +++ /dev/null @@ -1,693 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 BlackBerry Limited. All rights reserved. -** 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 -#include -#include -#include -#include -#include -#include -#if defined(QT_BUILD_INTERNAL) && !defined(QT_NO_OPENSSL) -#include -#endif // QT_BUILD_INTERNAL && !QT_NO_OPENSSL - -#include "../../../network-settings.h" - -Q_DECLARE_METATYPE(QAuthenticator*) - -class tst_Spdy: public QObject -{ - Q_OBJECT - -public: - tst_Spdy(); - ~tst_Spdy(); - -private Q_SLOTS: - void initTestCase(); - void settingsAndNegotiation_data(); - void settingsAndNegotiation(); -#ifndef QT_NO_NETWORKPROXY - void download_data(); - void download(); -#endif // !QT_NO_NETWORKPROXY - void headerFields(); -#ifndef QT_NO_NETWORKPROXY - void upload_data(); - void upload(); - void errors_data(); - void errors(); -#endif // !QT_NO_NETWORKPROXY - void multipleRequests_data(); - void multipleRequests(); - -private: - QNetworkAccessManager m_manager; - int m_multipleRequestsCount; - int m_multipleRepliesFinishedCount; - const QString m_rfc3252FilePath; - -protected Q_SLOTS: - void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *authenticator); - void multipleRequestsFinishedSlot(); -}; - -tst_Spdy::tst_Spdy() - : m_rfc3252FilePath(QFINDTESTDATA("../qnetworkreply/rfc3252.txt")) -{ -#if defined(QT_BUILD_INTERNAL) && !defined(QT_NO_SSL) && OPENSSL_VERSION_NUMBER >= 0x1000100fL && !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG) - qRegisterMetaType(); // for QSignalSpy - qRegisterMetaType(); - - connect(&m_manager, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)), - this, SLOT(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *))); -#else - QSKIP("Qt built withouth OpenSSL, or the OpenSSL version is too old"); -#endif // defined(QT_BUILD_INTERNAL) && !defined(QT_NO_SSL) ... -} - -tst_Spdy::~tst_Spdy() -{ -} - -void tst_Spdy::initTestCase() -{ - QVERIFY(!m_rfc3252FilePath.isEmpty()); - QVERIFY(QtNetworkSettings::verifyTestNetworkSettings()); -} - -void tst_Spdy::settingsAndNegotiation_data() -{ - QTest::addColumn("url"); - QTest::addColumn("setAttribute"); - QTest::addColumn("enabled"); - QTest::addColumn("expectedProtocol"); - QTest::addColumn("expectedContent"); - - QTest::newRow("default-settings") << QUrl("https://" + QtNetworkSettings::serverName() - + "/qtest/cgi-bin/echo.cgi?1") - << false << false << QByteArray() - << QByteArray("1"); - - QTest::newRow("http-url") << QUrl("http://" + QtNetworkSettings::serverName() - + "/qtest/cgi-bin/echo.cgi?1") - << true << true << QByteArray() - << QByteArray("1"); - - QTest::newRow("spdy-disabled") << QUrl("https://" + QtNetworkSettings::serverName() - + "/qtest/cgi-bin/echo.cgi?1") - << true << false << QByteArray() - << QByteArray("1"); - -#ifndef QT_NO_OPENSSL - QTest::newRow("spdy-enabled") << QUrl("https://" + QtNetworkSettings::serverName() - + "/qtest/cgi-bin/echo.cgi?1") - << true << true << QByteArray(QSslConfiguration::NextProtocolSpdy3_0) - << QByteArray("1"); -#endif // QT_NO_OPENSSL -} - -void tst_Spdy::settingsAndNegotiation() -{ - QFETCH(QUrl, url); - QFETCH(bool, setAttribute); - QFETCH(bool, enabled); - - QNetworkRequest request(url); - - if (setAttribute) { - request.setAttribute(QNetworkRequest::SpdyAllowedAttribute, QVariant(enabled)); - } - - QNetworkReply *reply = m_manager.get(request); - reply->ignoreSslErrors(); - QSignalSpy metaDataChangedSpy(reply, SIGNAL(metaDataChanged())); - QSignalSpy readyReadSpy(reply, SIGNAL(readyRead())); - QSignalSpy finishedSpy(reply, SIGNAL(finished())); - - QObject::connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QSignalSpy finishedManagerSpy(&m_manager, SIGNAL(finished(QNetworkReply*))); - - QTestEventLoop::instance().enterLoop(15); - QVERIFY(!QTestEventLoop::instance().timeout()); - - QFETCH(QByteArray, expectedProtocol); - -#ifndef QT_NO_OPENSSL - bool expectedSpdyUsed = (expectedProtocol == QSslConfiguration::NextProtocolSpdy3_0); - QCOMPARE(reply->attribute(QNetworkRequest::SpdyWasUsedAttribute).toBool(), expectedSpdyUsed); -#endif // QT_NO_OPENSSL - - QCOMPARE(metaDataChangedSpy.count(), 1); - QCOMPARE(finishedSpy.count(), 1); - - int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - QCOMPARE(statusCode, 200); - - QByteArray content = reply->readAll(); - - QFETCH(QByteArray, expectedContent); - QCOMPARE(expectedContent, content); - -#ifndef QT_NO_OPENSSL - QSslConfiguration::NextProtocolNegotiationStatus expectedStatus = - (expectedProtocol.isEmpty()) - ? QSslConfiguration::NextProtocolNegotiationNone - : QSslConfiguration::NextProtocolNegotiationNegotiated; - QCOMPARE(reply->sslConfiguration().nextProtocolNegotiationStatus(), - expectedStatus); - - QCOMPARE(reply->sslConfiguration().nextNegotiatedProtocol(), expectedProtocol); -#endif // QT_NO_OPENSSL -} - -void tst_Spdy::proxyAuthenticationRequired(const QNetworkProxy &/*proxy*/, - QAuthenticator *authenticator) -{ - authenticator->setUser("qsockstest"); - authenticator->setPassword("password"); -} - -#ifndef QT_NO_NETWORKPROXY -void tst_Spdy::download_data() -{ - QTest::addColumn("url"); - QTest::addColumn("fileName"); - QTest::addColumn("proxy"); - - QTest::newRow("mediumfile") << QUrl("https://" + QtNetworkSettings::serverName() - + "/qtest/rfc3252.txt") - << m_rfc3252FilePath - << QNetworkProxy(); - - QHostInfo hostInfo = QHostInfo::fromName(QtNetworkSettings::serverName()); - QString proxyserver = hostInfo.addresses().first().toString(); - - QTest::newRow("mediumfile-http-proxy") << QUrl("https://" + QtNetworkSettings::serverName() - + "/qtest/rfc3252.txt") - << m_rfc3252FilePath - << QNetworkProxy(QNetworkProxy::HttpProxy, proxyserver, 3128); - - QTest::newRow("mediumfile-http-proxy-auth") << QUrl("https://" + QtNetworkSettings::serverName() - + "/qtest/rfc3252.txt") - << m_rfc3252FilePath - << QNetworkProxy(QNetworkProxy::HttpProxy, - proxyserver, 3129); - - QTest::newRow("mediumfile-socks-proxy") << QUrl("https://" + QtNetworkSettings::serverName() - + "/qtest/rfc3252.txt") - << m_rfc3252FilePath - << QNetworkProxy(QNetworkProxy::Socks5Proxy, proxyserver, 1080); - - QTest::newRow("mediumfile-socks-proxy-auth") << QUrl("https://" + QtNetworkSettings::serverName() - + "/qtest/rfc3252.txt") - << m_rfc3252FilePath - << QNetworkProxy(QNetworkProxy::Socks5Proxy, - proxyserver, 1081); - - QTest::newRow("bigfile") << QUrl("https://" + QtNetworkSettings::serverName() - + "/qtest/bigfile") - << QFINDTESTDATA("../qnetworkreply/bigfile") - << QNetworkProxy(); -} - -void tst_Spdy::download() -{ - QFETCH(QUrl, url); - QFETCH(QString, fileName); - QFETCH(QNetworkProxy, proxy); - - QNetworkRequest request(url); - request.setAttribute(QNetworkRequest::SpdyAllowedAttribute, true); - - if (proxy.type() != QNetworkProxy::DefaultProxy) { - m_manager.setProxy(proxy); - } - QNetworkReply *reply = m_manager.get(request); - reply->ignoreSslErrors(); - QSignalSpy metaDataChangedSpy(reply, SIGNAL(metaDataChanged())); - QSignalSpy downloadProgressSpy(reply, SIGNAL(downloadProgress(qint64, qint64))); - QSignalSpy readyReadSpy(reply, SIGNAL(readyRead())); - QSignalSpy finishedSpy(reply, SIGNAL(finished())); - - QObject::connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QSignalSpy finishedManagerSpy(&m_manager, SIGNAL(finished(QNetworkReply*))); - QSignalSpy proxyAuthRequiredSpy(&m_manager, SIGNAL( - proxyAuthenticationRequired(const QNetworkProxy &, - QAuthenticator *))); - - QTestEventLoop::instance().enterLoop(15); - QVERIFY(!QTestEventLoop::instance().timeout()); - - QCOMPARE(finishedManagerSpy.count(), 1); - QCOMPARE(metaDataChangedSpy.count(), 1); - QCOMPARE(finishedSpy.count(), 1); - QVERIFY(downloadProgressSpy.count() > 0); - QVERIFY(readyReadSpy.count() > 0); - - QVERIFY(proxyAuthRequiredSpy.count() <= 1); - - QCOMPARE(reply->error(), QNetworkReply::NoError); - QCOMPARE(reply->attribute(QNetworkRequest::SpdyWasUsedAttribute).toBool(), true); - QCOMPARE(reply->attribute(QNetworkRequest::ConnectionEncryptedAttribute).toBool(), true); - QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); - - QFile file(fileName); - QVERIFY(file.open(QIODevice::ReadOnly)); - - qint64 contentLength = reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(); - qint64 expectedContentLength = file.bytesAvailable(); - QCOMPARE(contentLength, expectedContentLength); - - QByteArray expectedContent = file.readAll(); - QByteArray content = reply->readAll(); - QCOMPARE(content, expectedContent); - - reply->deleteLater(); - m_manager.setProxy(QNetworkProxy()); // reset -} -#endif // !QT_NO_NETWORKPROXY - -void tst_Spdy::headerFields() -{ - QUrl url(QUrl("https://" + QtNetworkSettings::serverName())); - QNetworkRequest request(url); - request.setAttribute(QNetworkRequest::SpdyAllowedAttribute, true); - - QNetworkReply *reply = m_manager.get(request); - reply->ignoreSslErrors(); - - QObject::connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - - QTestEventLoop::instance().enterLoop(15); - QVERIFY(!QTestEventLoop::instance().timeout()); - - QCOMPARE(reply->rawHeader("Content-Type"), QByteArray("text/html")); - QVERIFY(reply->rawHeader("Content-Length").toInt() > 0); - QVERIFY(reply->rawHeader("server").contains("Apache")); - - QCOMPARE(reply->header(QNetworkRequest::ContentTypeHeader).toByteArray(), QByteArray("text/html")); - QVERIFY(reply->header(QNetworkRequest::ContentLengthHeader).toLongLong() > 0); - QVERIFY(reply->header(QNetworkRequest::LastModifiedHeader).toDateTime().isValid()); - QVERIFY(reply->header(QNetworkRequest::ServerHeader).toByteArray().contains("Apache")); -} - -static inline QByteArray md5sum(const QByteArray &data) -{ - return QCryptographicHash::hash(data, QCryptographicHash::Md5).toHex().append('\n'); -} - -#ifndef QT_NO_NETWORKPROXY -void tst_Spdy::upload_data() -{ - QTest::addColumn("url"); - QTest::addColumn("data"); - QTest::addColumn("uploadMethod"); - QTest::addColumn("uploadObject"); - QTest::addColumn("md5sum"); - QTest::addColumn("proxy"); - - - // 1. test uploading of byte arrays - - QUrl md5Url("https://" + QtNetworkSettings::serverName() + "/qtest/cgi-bin/md5sum.cgi"); - - QByteArray data; - data = ""; - QObject *dummyObject = 0; - QTest::newRow("empty") << md5Url << data << QByteArray("POST") << dummyObject - << md5sum(data) << QNetworkProxy(); - - data = "This is a normal message."; - QTest::newRow("generic") << md5Url << data << QByteArray("POST") << dummyObject - << md5sum(data) << QNetworkProxy(); - - data = "This is a message to show that Qt rocks!\r\n\n"; - QTest::newRow("small") << md5Url << data << QByteArray("POST") << dummyObject - << md5sum(data) << QNetworkProxy(); - - data = QByteArray("abcd\0\1\2\abcd",12); - QTest::newRow("with-nul") << md5Url << data << QByteArray("POST") << dummyObject - << md5sum(data) << QNetworkProxy(); - - data = QByteArray(4097, '\4'); - QTest::newRow("4k+1") << md5Url << data << QByteArray("POST") << dummyObject - << md5sum(data)<< QNetworkProxy(); - - QHostInfo hostInfo = QHostInfo::fromName(QtNetworkSettings::serverName()); - QString proxyserver = hostInfo.addresses().first().toString(); - - QTest::newRow("4k+1-with-http-proxy") << md5Url << data << QByteArray("POST") << dummyObject - << md5sum(data) - << QNetworkProxy(QNetworkProxy::HttpProxy, proxyserver, 3128); - - QTest::newRow("4k+1-with-http-proxy-auth") << md5Url << data << QByteArray("POST") << dummyObject - << md5sum(data) - << QNetworkProxy(QNetworkProxy::HttpProxy, - proxyserver, 3129); - - QTest::newRow("4k+1-with-socks-proxy") << md5Url << data << QByteArray("POST") << dummyObject - << md5sum(data) - << QNetworkProxy(QNetworkProxy::Socks5Proxy, proxyserver, 1080); - - QTest::newRow("4k+1-with-socks-proxy-auth") << md5Url << data << QByteArray("POST") << dummyObject - << md5sum(data) - << QNetworkProxy(QNetworkProxy::Socks5Proxy, - proxyserver, 1081); - - data = QByteArray(128*1024+1, '\177'); - QTest::newRow("128k+1") << md5Url << data << QByteArray("POST") << dummyObject - << md5sum(data) << QNetworkProxy(); - - data = QByteArray(128*1024+1, '\177'); - QTest::newRow("128k+1-put") << md5Url << data << QByteArray("PUT") << dummyObject - << md5sum(data) << QNetworkProxy(); - - data = QByteArray(2*1024*1024+1, '\177'); - QTest::newRow("2MB+1") << md5Url << data << QByteArray("POST") << dummyObject - << md5sum(data) << QNetworkProxy(); - - - // 2. test uploading of files - - QFile *file = new QFile(m_rfc3252FilePath); - file->open(QIODevice::ReadOnly); - QTest::newRow("file-26K") << md5Url << QByteArray() << QByteArray("POST") - << static_cast(file) - << QByteArray("b3e32ac459b99d3f59318f3ac31e4bee\n") << QNetworkProxy(); - - QFile *file2 = new QFile(QFINDTESTDATA("../qnetworkreply/image1.jpg")); - file2->open(QIODevice::ReadOnly); - QTest::newRow("file-1MB") << md5Url << QByteArray() << QByteArray("POST") - << static_cast(file2) - << QByteArray("87ef3bb319b004ba9e5e9c9fa713776e\n") << QNetworkProxy(); - - - // 3. test uploading of multipart - - QUrl multiPartUrl("https://" + QtNetworkSettings::serverName() + "/qtest/cgi-bin/multipart.cgi"); - - QHttpPart imagePart31; - imagePart31.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); - imagePart31.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"testImage1\"")); - imagePart31.setRawHeader("Content-Location", "http://my.test.location.tld"); - imagePart31.setRawHeader("Content-ID", "my@id.tld"); - QFile *file31 = new QFile(QFINDTESTDATA("../qnetworkreply/image1.jpg")); - file31->open(QIODevice::ReadOnly); - imagePart31.setBodyDevice(file31); - QHttpMultiPart *imageMultiPart3 = new QHttpMultiPart(QHttpMultiPart::FormDataType); - imageMultiPart3->append(imagePart31); - file31->setParent(imageMultiPart3); - QHttpPart imagePart32; - imagePart32.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); - imagePart32.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"testImage2\"")); - QFile *file32 = new QFile(QFINDTESTDATA("../qnetworkreply/image2.jpg")); - file32->open(QIODevice::ReadOnly); - imagePart32.setBodyDevice(file31); // check that resetting works - imagePart32.setBodyDevice(file32); - imageMultiPart3->append(imagePart32); - file32->setParent(imageMultiPart3); - QHttpPart imagePart33; - imagePart33.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); - imagePart33.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"testImage3\"")); - QFile *file33 = new QFile(QFINDTESTDATA("../qnetworkreply/image3.jpg")); - file33->open(QIODevice::ReadOnly); - imagePart33.setBodyDevice(file33); - imageMultiPart3->append(imagePart33); - file33->setParent(imageMultiPart3); - QByteArray expectedData = "content type: multipart/form-data; boundary=\"" - + imageMultiPart3->boundary(); - expectedData.append("\"\nkey: testImage1, value: 87ef3bb319b004ba9e5e9c9fa713776e\n" - "key: testImage2, value: 483761b893f7fb1bd2414344cd1f3dfb\n" - "key: testImage3, value: ab0eb6fd4fcf8b4436254870b4513033\n"); - - QTest::newRow("multipart-3images") << multiPartUrl << QByteArray() << QByteArray("POST") - << static_cast(imageMultiPart3) << expectedData - << QNetworkProxy(); -} - -void tst_Spdy::upload() -{ - QFETCH(QUrl, url); - QNetworkRequest request(url); - request.setAttribute(QNetworkRequest::SpdyAllowedAttribute, true); - - QFETCH(QByteArray, data); - QFETCH(QByteArray, uploadMethod); - QFETCH(QObject *, uploadObject); - QFETCH(QNetworkProxy, proxy); - - if (proxy.type() != QNetworkProxy::DefaultProxy) { - m_manager.setProxy(proxy); - } - - QNetworkReply *reply; - QHttpMultiPart *multiPart = 0; - - if (uploadObject) { - // upload via device - if (QIODevice *device = qobject_cast(uploadObject)) { - reply = m_manager.post(request, device); - } else if ((multiPart = qobject_cast(uploadObject))) { - reply = m_manager.post(request, multiPart); - } else { - QFAIL("got unknown upload device"); - } - } else { - // upload via byte array - if (uploadMethod == "PUT") { - reply = m_manager.put(request, data); - } else { - reply = m_manager.post(request, data); - } - } - - reply->ignoreSslErrors(); - QSignalSpy metaDataChangedSpy(reply, SIGNAL(metaDataChanged())); - QSignalSpy uploadProgressSpy(reply, SIGNAL(uploadProgress(qint64, qint64))); - QSignalSpy readyReadSpy(reply, SIGNAL(readyRead())); - QSignalSpy finishedSpy(reply, SIGNAL(finished())); - - QObject::connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QSignalSpy finishedManagerSpy(&m_manager, SIGNAL(finished(QNetworkReply*))); - - QTestEventLoop::instance().enterLoop(20); - QVERIFY(!QTestEventLoop::instance().timeout()); - - QCOMPARE(finishedManagerSpy.count(), 1); - QCOMPARE(metaDataChangedSpy.count(), 1); - QCOMPARE(finishedSpy.count(), 1); - QVERIFY(uploadProgressSpy.count() > 0); - QVERIFY(readyReadSpy.count() > 0); - - QCOMPARE(reply->error(), QNetworkReply::NoError); - QCOMPARE(reply->attribute(QNetworkRequest::SpdyWasUsedAttribute).toBool(), true); - QCOMPARE(reply->attribute(QNetworkRequest::ConnectionEncryptedAttribute).toBool(), true); - QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); - - qint64 contentLength = reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(); - if (!multiPart) // script to test multiparts does not return a content length - QCOMPARE(contentLength, 33); // 33 bytes for md5 sums (including new line) - - QFETCH(QByteArray, md5sum); - QByteArray content = reply->readAll(); - QCOMPARE(content, md5sum); - - reply->deleteLater(); - if (uploadObject) - uploadObject->deleteLater(); - - m_manager.setProxy(QNetworkProxy()); // reset -} - -void tst_Spdy::errors_data() -{ - QTest::addColumn("url"); - QTest::addColumn("proxy"); - QTest::addColumn("ignoreSslErrors"); - QTest::addColumn("expectedReplyError"); - - QTest::newRow("http-404") << QUrl("https://" + QtNetworkSettings::serverName() + "/non-existent-url") - << QNetworkProxy() << true << int(QNetworkReply::ContentNotFoundError); - - QTest::newRow("ssl-errors") << QUrl("https://" + QtNetworkSettings::serverName()) - << QNetworkProxy() << false << int(QNetworkReply::SslHandshakeFailedError); - - QTest::newRow("host-not-found") << QUrl("https://this-host-does-not.exist") - << QNetworkProxy() - << true << int(QNetworkReply::HostNotFoundError); - - QTest::newRow("proxy-not-found") << QUrl("https://" + QtNetworkSettings::serverName()) - << QNetworkProxy(QNetworkProxy::HttpProxy, - "https://this-host-does-not.exist", 3128) - << true << int(QNetworkReply::HostNotFoundError); - - QHostInfo hostInfo = QHostInfo::fromName(QtNetworkSettings::serverName()); - QString proxyserver = hostInfo.addresses().first().toString(); - - QTest::newRow("proxy-unavailable") << QUrl("https://" + QtNetworkSettings::serverName()) - << QNetworkProxy(QNetworkProxy::HttpProxy, proxyserver, 10) - << true << int(QNetworkReply::UnknownNetworkError); - - QTest::newRow("no-proxy-credentials") << QUrl("https://" + QtNetworkSettings::serverName()) - << QNetworkProxy(QNetworkProxy::HttpProxy, proxyserver, 3129) - << true << int(QNetworkReply::ProxyAuthenticationRequiredError); -} - -void tst_Spdy::errors() -{ - QFETCH(QUrl, url); - QFETCH(QNetworkProxy, proxy); - QFETCH(bool, ignoreSslErrors); - QFETCH(int, expectedReplyError); - - QNetworkRequest request(url); - request.setAttribute(QNetworkRequest::SpdyAllowedAttribute, true); - - disconnect(&m_manager, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)), - 0, 0); - if (proxy.type() != QNetworkProxy::DefaultProxy) { - m_manager.setProxy(proxy); - } - QNetworkReply *reply = m_manager.get(request); - if (ignoreSslErrors) - reply->ignoreSslErrors(); - QSignalSpy finishedSpy(reply, SIGNAL(finished())); - QSignalSpy errorSpy(reply, SIGNAL(error(QNetworkReply::NetworkError))); - - QObject::connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - - QTestEventLoop::instance().enterLoop(15); - QVERIFY(!QTestEventLoop::instance().timeout()); - - QCOMPARE(finishedSpy.count(), 1); - QCOMPARE(errorSpy.count(), 1); - - QCOMPARE(reply->error(), static_cast(expectedReplyError)); - - m_manager.setProxy(QNetworkProxy()); // reset - m_manager.clearAccessCache(); // e.g. to get an SSL error we need a new connection - connect(&m_manager, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)), - this, SLOT(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)), - Qt::UniqueConnection); // reset -} -#endif // !QT_NO_NETWORKPROXY - -void tst_Spdy::multipleRequests_data() -{ - QTest::addColumn >("urls"); - - QString baseUrl = "https://" + QtNetworkSettings::serverName() + "/qtest/cgi-bin/echo.cgi?"; - QList urls; - for (int a = 1; a <= 50; ++a) - urls.append(QUrl(baseUrl + QLatin1String(QByteArray::number(a)))); - - QTest::newRow("one-request") << urls.mid(0, 1); - QTest::newRow("two-requests") << urls.mid(0, 2); - QTest::newRow("ten-requests") << urls.mid(0, 10); - QTest::newRow("twenty-requests") << urls.mid(0, 20); - QTest::newRow("fifty-requests") << urls; -} - -void tst_Spdy::multipleRequestsFinishedSlot() -{ - m_multipleRepliesFinishedCount++; - if (m_multipleRepliesFinishedCount == m_multipleRequestsCount) - QTestEventLoop::instance().exitLoop(); -} - -void tst_Spdy::multipleRequests() -{ - QFETCH(QList, urls); - m_multipleRequestsCount = urls.count(); - m_multipleRepliesFinishedCount = 0; - - QList replies; - QList metaDataChangedSpies; - QList readyReadSpies; - QList finishedSpies; - - foreach (const QUrl &url, urls) { - QNetworkRequest request(url); - request.setAttribute(QNetworkRequest::SpdyAllowedAttribute, true); - QNetworkReply *reply = m_manager.get(request); - replies.append(reply); - reply->ignoreSslErrors(); - QObject::connect(reply, SIGNAL(finished()), this, SLOT(multipleRequestsFinishedSlot())); - QSignalSpy *metaDataChangedSpy = new QSignalSpy(reply, SIGNAL(metaDataChanged())); - metaDataChangedSpies << metaDataChangedSpy; - QSignalSpy *readyReadSpy = new QSignalSpy(reply, SIGNAL(readyRead())); - readyReadSpies << readyReadSpy; - QSignalSpy *finishedSpy = new QSignalSpy(reply, SIGNAL(finished())); - finishedSpies << finishedSpy; - } - - QSignalSpy finishedManagerSpy(&m_manager, SIGNAL(finished(QNetworkReply*))); - - QTestEventLoop::instance().enterLoop(15); - QVERIFY(!QTestEventLoop::instance().timeout()); - - QCOMPARE(finishedManagerSpy.count(), m_multipleRequestsCount); - - for (int a = 0; a < replies.count(); ++a) { - -#ifndef QT_NO_OPENSSL - QCOMPARE(replies.at(a)->sslConfiguration().nextProtocolNegotiationStatus(), - QSslConfiguration::NextProtocolNegotiationNegotiated); - QCOMPARE(replies.at(a)->sslConfiguration().nextNegotiatedProtocol(), - QByteArray(QSslConfiguration::NextProtocolSpdy3_0)); -#endif // QT_NO_OPENSSL - - QCOMPARE(replies.at(a)->error(), QNetworkReply::NoError); - QCOMPARE(replies.at(a)->attribute(QNetworkRequest::SpdyWasUsedAttribute).toBool(), true); - QCOMPARE(replies.at(a)->attribute(QNetworkRequest::ConnectionEncryptedAttribute).toBool(), true); - QCOMPARE(replies.at(a)->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); - - // using the echo script, a request to "echo.cgi?1" will return a body of "1" - QByteArray expectedContent = replies.at(a)->url().query().toUtf8(); - QByteArray content = replies.at(a)->readAll(); - QCOMPARE(expectedContent, content); - - QCOMPARE(metaDataChangedSpies.at(a)->count(), 1); - metaDataChangedSpies.at(a)->deleteLater(); - - QCOMPARE(finishedSpies.at(a)->count(), 1); - finishedSpies.at(a)->deleteLater(); - - QVERIFY(readyReadSpies.at(a)->count() > 0); - readyReadSpies.at(a)->deleteLater(); - - replies.at(a)->deleteLater(); - } -} - -QTEST_MAIN(tst_Spdy) - -#include "tst_spdy.moc" -- cgit v1.2.3 From 936444d8596e9417e716302a31342d9884dba307 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Wed, 2 Oct 2019 11:09:45 +0200 Subject: tst_qnetworkreply: Remove getFromHttp:success-external MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test fails because the server (reasonably) sends a https redirect. Let's not rely on external servers serving http indefinitely. Fixes: QTBUG-71953 Change-Id: I20937b2c6f268519636349bae8c99c1afe64fcf9 Reviewed-by: Mårten Nordheim --- tests/auto/network/access/qnetworkreply/BLACKLIST | 2 -- tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp | 4 ---- 2 files changed, 6 deletions(-) (limited to 'tests/auto/network') diff --git a/tests/auto/network/access/qnetworkreply/BLACKLIST b/tests/auto/network/access/qnetworkreply/BLACKLIST index 2a0651f96f..18450f1853 100644 --- a/tests/auto/network/access/qnetworkreply/BLACKLIST +++ b/tests/auto/network/access/qnetworkreply/BLACKLIST @@ -15,8 +15,6 @@ linux # QTBUG-71953 [getFromHttp] * !android !winrt -[getFromHttp:success-external] -* [getFromHttpIntoBuffer] osx [getFromHttpIntoBuffer2] diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index 418e1caf68..04bda567ed 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -1910,10 +1910,6 @@ void tst_QNetworkReply::getFromHttp_data() << testDataDir + "/rfc3252.txt" << "http://" + QtNetworkSettings::httpServerName() + "/qtest/rfc3252.txt"; - QTest::newRow("success-external") - << testDataDir + "/rfc3252.txt" - << "http://www.ietf.org/rfc/rfc3252.txt"; - QTest::newRow("bigfile-internal") << testDataDir + "/bigfile" << "http://" + QtNetworkSettings::httpServerName() + "/qtest/bigfile"; -- cgit v1.2.3