summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWater-Team <water@pad.test.qt.nokia.com>2011-11-11 01:00:12 +0100
committerWater-Team <water@pad.test.qt.nokia.com>2011-11-11 01:00:12 +0100
commitfa1dbb123c69cf1078c56a0473ef8d6f2eea5d4d (patch)
tree91c458836ea5e619da92f9b4ed50224a690cf82f /tests
parentfe9b1390573b760aec573bbf2de2e1edf1caa52a (diff)
parentde0dcfdb1133dcee7b6d0d50a2bcd95f5bdf2515 (diff)
downloadqt4-tools-fa1dbb123c69cf1078c56a0473ef8d6f2eea5d4d.tar.gz
Merge branch '4.8-upstream' into master-water
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qnetworkcookiejar/tst_qnetworkcookiejar.cpp6
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp89
2 files changed, 90 insertions, 5 deletions
diff --git a/tests/auto/qnetworkcookiejar/tst_qnetworkcookiejar.cpp b/tests/auto/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
index d1c376adde..0125fc0970 100644
--- a/tests/auto/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
+++ b/tests/auto/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
@@ -417,6 +417,12 @@ void tst_QNetworkCookieJar::effectiveTLDs_data()
QTest::newRow("yes7") << "org.ws" << true;
QTest::newRow("yes8") << "co.uk" << true;
QTest::newRow("yes9") << "wallonie.museum" << true;
+ QTest::newRow("yes10") << "dyndns-at-home.com" << true;
+ QTest::newRow("yes11") << "forgot.her.name" << true;
+ QTest::newRow("yes12") << "is-a-llama.com" << true;
+ QTest::newRow("yes13") << "gov.uk" << true;
+ QTest::newRow("yes14") << "manchester.museum" << true;
+ QTest::newRow("yes15") << "gov.ir" << true;
QTest::newRow("no1") << "anything.com" << false;
QTest::newRow("no2") << "anything.de" << false;
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index 3d1e35ed25..9df820a2b1 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -378,6 +378,7 @@ private Q_SLOTS:
void httpAbort();
void dontInsertPartialContentIntoTheCache();
+ void synchronousAuthenticationCache();
// NOTE: This test must be last!
void parentingRepliesToTheApp();
@@ -499,6 +500,14 @@ protected:
client->setParent(this);
++totalConnections;
}
+
+ virtual void reply() {
+ // we need to emulate the bytesWrittenSlot call if the data is empty.
+ if (dataToTransmit.size() == 0)
+ QMetaObject::invokeMethod(this, "bytesWrittenSlot", Qt::QueuedConnection);
+ else
+ client->write(dataToTransmit);
+ }
private:
void connectSocketSignals()
{
@@ -532,11 +541,7 @@ public slots:
if (multiple)
receivedData.remove(0, doubleEndlPos+4);
- // we need to emulate the bytesWrittenSlot call if the data is empty.
- if (dataToTransmit.size() == 0)
- QMetaObject::invokeMethod(this, "bytesWrittenSlot", Qt::QueuedConnection);
- else
- client->write(dataToTransmit);
+ reply();
}
}
@@ -6344,6 +6349,80 @@ void tst_QNetworkReply::dontInsertPartialContentIntoTheCache()
QCOMPARE(memoryCache->m_insertedUrls.count(), 0);
}
+void tst_QNetworkReply::synchronousAuthenticationCache()
+{
+ class MiniAuthServer : public MiniHttpServer {
+ public:
+ MiniAuthServer(QThread *thread) : MiniHttpServer(QByteArray(), false, thread) {};
+ virtual void reply() {
+
+ dataToTransmit =
+ "HTTP/1.0 401 Unauthorized\r\n"
+ "WWW-Authenticate: Basic realm=\"QNetworkAccessManager Test Realm\"\r\n"
+ "Content-Length: 4\r\n"
+ "Connection: close\r\n"
+ "Content-Type: text/plain\r\n"
+ "\r\n"
+ "auth";
+ QRegExp rx("Authorization: Basic ([^\r\n]*)\r\n");
+ if (rx.indexIn(receivedData) > 0) {
+ if (QByteArray::fromBase64(rx.cap(1).toLatin1()) == "login:password") {
+ dataToTransmit =
+ "HTTP/1.0 200 OK\r\n"
+ "Content-Type: text/plain\r\n"
+ "Content-Length: 2\r\n"
+ "\r\n"
+ "OK";
+ }
+ }
+ receivedData.clear();
+ MiniHttpServer::reply();
+ }
+ };
+
+ // when using synchronous commands, we need a different event loop for
+ // the server thread, because the client is never returning to the
+ // event loop
+ QScopedPointer<QThread, QThreadCleanup> serverThread(new QThread);
+ QScopedPointer<MiniHttpServer, QDeleteLaterCleanup> server(new MiniAuthServer(serverThread.data()));
+ server->doClose = true;
+
+ //1) URL without credentials, we are not authenticated
+ {
+ QUrl url = "http://localhost:" + QString::number(server->serverPort()) + "/path";
+ QNetworkRequest request(url);
+ request.setAttribute(QNetworkRequest::SynchronousRequestAttribute, true);
+
+ QNetworkReplyPtr reply = manager.get(request);
+ QVERIFY(reply->isFinished());
+ QCOMPARE(reply->error(), QNetworkReply::AuthenticationRequiredError);
+ }
+
+ //2) URL with credentials, we are authenticated
+ {
+ QUrl url = "http://login:password@localhost:" + QString::number(server->serverPort()) + "/path2";
+ QNetworkRequest request(url);
+ request.setAttribute(QNetworkRequest::SynchronousRequestAttribute, true);
+
+ QNetworkReplyPtr reply = manager.get(request);
+ QVERIFY(reply->isFinished());
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+ QCOMPARE(reply->readAll().constData(), "OK");
+ }
+
+ //3) URL without credentials, we are authenticated because they are cached
+ {
+ QUrl url = "http://localhost:" + QString::number(server->serverPort()) + "/path3";
+ QNetworkRequest request(url);
+ request.setAttribute(QNetworkRequest::SynchronousRequestAttribute, true);
+
+ QNetworkReplyPtr reply = manager.get(request);
+ QVERIFY(reply->isFinished());
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+ QCOMPARE(reply->readAll().constData(), "OK");
+ }
+}
+
// NOTE: This test must be last testcase in tst_qnetworkreply!
void tst_QNetworkReply::parentingRepliesToTheApp()
{