summaryrefslogtreecommitdiffstats
path: root/tests/auto/network
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-10-17 10:19:31 +0200
committerLiang Qi <liang.qi@qt.io>2017-10-17 10:34:24 +0200
commitd0a0a3c0418a0fdd2ed84b2a5f7e6565537715c6 (patch)
treed6aeb4d51caf30ccf23eadb806a09295cbf679cd /tests/auto/network
parent9f405f98a4247cd263b9c5d35659a4ba89e282de (diff)
parentac35f9c44c0fb3b2f40ae5585c497200b2ba743d (diff)
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts: examples/network/fortuneclient/client.cpp examples/network/fortuneserver/server.cpp src/platformsupport/platformcompositor/qopenglcompositorbackingstore_p.h src/plugins/platforms/cocoa/qcocoabackingstore.h src/plugins/platforms/cocoa/qcocoaintegration.h src/plugins/platforms/cocoa/qcocoascreen.h src/plugins/platforms/ios/qiosbackingstore.h src/plugins/sqldrivers/oci/qsql_oci.cpp src/widgets/kernel/qwidgetwindow.cpp Change-Id: Ia6dd2c52d4a691b671cf9a2ffca70deccece8f10
Diffstat (limited to 'tests/auto/network')
-rw-r--r--tests/auto/network/access/http2/tst_http2.cpp4
-rw-r--r--tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp28
-rw-r--r--tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp2
-rw-r--r--tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp4
-rw-r--r--tests/auto/network/ssl/qsslsocket_onDemandCertificates_member/tst_qsslsocket_onDemandCertificates_member.cpp64
5 files changed, 77 insertions, 25 deletions
diff --git a/tests/auto/network/access/http2/tst_http2.cpp b/tests/auto/network/access/http2/tst_http2.cpp
index e433293a2c..9befb7276e 100644
--- a/tests/auto/network/access/http2/tst_http2.cpp
+++ b/tests/auto/network/access/http2/tst_http2.cpp
@@ -124,6 +124,7 @@ private:
const Http2Settings tst_Http2::defaultServerSettings{{Http2::Settings::MAX_CONCURRENT_STREAMS_ID, 100}};
const Http2Settings tst_Http2::defaultClientSettings{{Http2::Settings::MAX_FRAME_SIZE_ID, quint32(Http2::maxFrameSize)},
+ {Http2::Settings::INITIAL_WINDOW_SIZE_ID, quint32(Http2::initialStreamReceiveWindowSize)},
{Http2::Settings::ENABLE_PUSH_ID, quint32(0)}};
namespace {
@@ -274,7 +275,7 @@ void tst_Http2::flowControlClientSide()
ServerPtr srv(newServer(serverSettings));
- const QByteArray respond(int(Http2::defaultSessionWindowSize * 50), 'x');
+ const QByteArray respond(int(Http2::initialStreamReceiveWindowSize * 5), 'x');
srv->setResponseBody(respond);
QMetaObject::invokeMethod(srv.data(), "startServer", Qt::QueuedConnection);
@@ -342,6 +343,7 @@ void tst_Http2::pushPromise()
const EnvVarGuard env("QT_HTTP2_ENABLE_PUSH_PROMISE", "1");
const Http2Settings clientSettings{{Settings::MAX_FRAME_SIZE_ID, quint32(Http2::maxFrameSize)},
+ {Http2::Settings::INITIAL_WINDOW_SIZE_ID, quint32(Http2::initialStreamReceiveWindowSize)},
{Settings::ENABLE_PUSH_ID, quint32(1)}};
ServerPtr srv(newServer(defaultServerSettings, clientSettings));
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
index 40e909113e..49abbede35 100644
--- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -488,6 +488,7 @@ private Q_SLOTS:
void ioHttpRedirectPolicyErrors();
void ioHttpUserVerifiedRedirect_data();
void ioHttpUserVerifiedRedirect();
+ void ioHttpCookiesDuringRedirect();
#ifndef QT_NO_SSL
void putWithServerClosingConnectionImmediately();
#endif
@@ -8456,6 +8457,33 @@ void tst_QNetworkReply::ioHttpUserVerifiedRedirect()
QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), statusCode);
}
+void tst_QNetworkReply::ioHttpCookiesDuringRedirect()
+{
+ MiniHttpServer target(httpEmpty200Response, false);
+
+ const QString cookieHeader = QStringLiteral("Set-Cookie: hello=world; Path=/;\r\n");
+ QString redirect = tempRedirectReplyStr();
+ // Insert 'cookieHeader' before the final \r\n
+ redirect.insert(redirect.length() - 2, cookieHeader);
+
+ QUrl url("http://localhost/");
+ url.setPort(target.serverPort());
+ redirect = redirect.arg(url.toString());
+ MiniHttpServer redirectServer(redirect.toLatin1(), false);
+
+ url = QUrl("http://localhost/");
+ url.setPort(redirectServer.serverPort());
+ QNetworkRequest request(url);
+ auto oldRedirectPolicy = manager.redirectPolicy();
+ manager.setRedirectPolicy(QNetworkRequest::RedirectPolicy::NoLessSafeRedirectPolicy);
+ QNetworkReplyPtr reply(manager.get(request));
+ // Set policy back to whatever it was
+ manager.setRedirectPolicy(oldRedirectPolicy);
+
+ QVERIFY(waitForFinish(reply) == Success);
+ QVERIFY(target.receivedData.contains("\r\nCookie: hello=world\r\n"));
+}
+
#ifndef QT_NO_SSL
class PutWithServerClosingConnectionImmediatelyHandler: public QObject
diff --git a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
index 94c355aadc..36dcec0a82 100644
--- a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
+++ b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
@@ -195,7 +195,7 @@ void tst_QNetworkInterface::localAddress()
QHostAddress local = socket.localAddress();
- // test that we can find the address that QTcpSocket reported
+ // test that we can find the address that QUdpSocket reported
QList<QHostAddress> all = QNetworkInterface::allAddresses();
QVERIFY(all.contains(local));
}
diff --git a/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp b/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp
index f3a1ac84ff..90da0b64e2 100644
--- a/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp
+++ b/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp
@@ -256,8 +256,8 @@ void tst_QNetworkProxyFactory::genericSystemProxy()
QFETCH(QString, hostName);
QFETCH(int, port);
-// The generic system proxy is only available on the following platforms
-#if (!defined Q_OS_WIN) && (!defined Q_OS_OSX) && !QT_CONFIG(libproxy)
+// We can only use the generic system proxy where available:
+#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS) && !QT_CONFIG(libproxy)
qputenv(envVar, url);
const QList<QNetworkProxy> systemProxy = QNetworkProxyFactory::systemProxyForQuery();
QCOMPARE(systemProxy.size(), 1);
diff --git a/tests/auto/network/ssl/qsslsocket_onDemandCertificates_member/tst_qsslsocket_onDemandCertificates_member.cpp b/tests/auto/network/ssl/qsslsocket_onDemandCertificates_member/tst_qsslsocket_onDemandCertificates_member.cpp
index b5bfde3cab..25c2701f69 100644
--- a/tests/auto/network/ssl/qsslsocket_onDemandCertificates_member/tst_qsslsocket_onDemandCertificates_member.cpp
+++ b/tests/auto/network/ssl/qsslsocket_onDemandCertificates_member/tst_qsslsocket_onDemandCertificates_member.cpp
@@ -168,29 +168,59 @@ void tst_QSslSocket_onDemandCertificates_member::proxyAuthenticationRequired(con
#ifndef QT_NO_OPENSSL
+static bool waitForEncrypted(QSslSocket *socket)
+{
+ Q_ASSERT(socket);
+
+ QEventLoop eventLoop;
+
+ QTimer connectionTimeoutWatcher;
+ connectionTimeoutWatcher.setSingleShot(true);
+ connectionTimeoutWatcher.connect(&connectionTimeoutWatcher, &QTimer::timeout,
+ [&eventLoop]() {
+ eventLoop.exit();
+ });
+
+ bool encrypted = false;
+ socket->connect(socket, &QSslSocket::encrypted, [&eventLoop, &encrypted](){
+ eventLoop.exit();
+ encrypted = true;
+ });
+
+ socket->connect(socket, QOverload<const QList<QSslError>&>::of(&QSslSocket::sslErrors),
+ [&eventLoop](){
+ eventLoop.exit();
+ });
+
+ // Wait for 30 s. maximum - the default timeout in our QSslSocket::waitForEncrypted ...
+ connectionTimeoutWatcher.start(30000);
+ eventLoop.exec();
+ return encrypted;
+}
+
void tst_QSslSocket_onDemandCertificates_member::onDemandRootCertLoadingMemberMethods()
{
- QString host("www.qt.io");
+ const QString host("www.qt.io");
// not using any root certs -> should not work
QSslSocketPtr socket2 = newSocket();
this->socket = socket2.data();
socket2->setCaCertificates(QList<QSslCertificate>());
socket2->connectToHostEncrypted(host, 443);
- QVERIFY(!socket2->waitForEncrypted());
+ QVERIFY(!waitForEncrypted(socket2.data()));
// default: using on demand loading -> should work
QSslSocketPtr socket = newSocket();
this->socket = socket.data();
socket->connectToHostEncrypted(host, 443);
- QVERIFY2(socket->waitForEncrypted(), qPrintable(socket->errorString()));
+ QVERIFY2(waitForEncrypted(socket.data()), qPrintable(socket->errorString()));
// not using any root certs again -> should not work
QSslSocketPtr socket3 = newSocket();
this->socket = socket3.data();
socket3->setCaCertificates(QList<QSslCertificate>());
socket3->connectToHostEncrypted(host, 443);
- QVERIFY(!socket3->waitForEncrypted());
+ QVERIFY(!waitForEncrypted(socket3.data()));
// setting empty SSL configuration explicitly -> depends on on-demand loading
QSslSocketPtr socket4 = newSocket();
@@ -199,24 +229,16 @@ void tst_QSslSocket_onDemandCertificates_member::onDemandRootCertLoadingMemberMe
socket4->setSslConfiguration(conf);
socket4->connectToHostEncrypted(host, 443);
#ifdef QT_BUILD_INTERNAL
- bool rootCertLoadingAllowed = QSslSocketPrivate::rootCertOnDemandLoadingSupported();
-#if defined(Q_OS_LINUX)
- QCOMPARE(rootCertLoadingAllowed, true);
+ const bool works = QSslSocketPrivate::rootCertOnDemandLoadingSupported();
+#if defined(Q_OS_LINUX) || defined(Q_OS_WIN)
+ QCOMPARE(works, true);
#elif defined(Q_OS_MAC)
- QCOMPARE(rootCertLoadingAllowed, false);
-#endif // other platforms: undecided (Windows: depends on the version)
- // when we allow on demand loading, it is enabled by default,
- // so on Unix it will work without setting any certificates. Otherwise,
- // the configuration contains an empty set of certificates
- // and will fail.
- bool works;
-#if defined (Q_OS_WIN)
- works = false; // on Windows, this won't work even though we use on demand loading
- Q_UNUSED(rootCertLoadingAllowed)
-#else
- works = rootCertLoadingAllowed;
-#endif
- QCOMPARE(socket4->waitForEncrypted(), works);
+ QCOMPARE(works, false);
+#endif // other platforms: undecided.
+ // When we *allow* on-demand loading, we enable it by default; so, on Unix,
+ // it will work without setting any certificates. Otherwise, the configuration
+ // contains an empty set of certificates, so on-demand loading shall fail.
+ QCOMPARE(waitForEncrypted(socket4.data()), works);
#endif // QT_BUILD_INTERNAL
}