summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPeter Hartmann <peter.hartmann@trolltech.com>2009-05-14 11:21:25 +0200
committerPeter Hartmann <peter.hartmann@trolltech.com>2009-05-15 14:10:19 +0200
commitd216c0fd62a879fd1eb84e087f70c7f542d75d58 (patch)
tree47e2f920a35ed7ea9095a14a9575b3cace8ba694 /tests
parent9c3f5040bc9b80619ebe167c352ac8f0394f9b41 (diff)
HTTP authentication: return error if authentication cannot be handled
return error upon receiving an unknown authentication method (e.g. WSSE); before we were just silently returning. Reviewed-by: Thiago Macieira
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index 4be0863eec..bb199b9074 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -217,6 +217,8 @@ private Q_SLOTS:
void httpProxyCommands_data();
void httpProxyCommands();
void proxyChange();
+ void authorizationError_data();
+ void authorizationError();
};
QT_BEGIN_NAMESPACE
@@ -3012,5 +3014,55 @@ void tst_QNetworkReply::proxyChange()
QVERIFY(int(reply3->error()) > 0);
}
+void tst_QNetworkReply::authorizationError_data()
+{
+
+ QTest::addColumn<QString>("url");
+ QTest::addColumn<int>("errorSignalCount");
+ QTest::addColumn<int>("finishedSignalCount");
+ QTest::addColumn<int>("error");
+ QTest::addColumn<int>("httpStatusCode");
+ QTest::addColumn<QString>("httpBody");
+
+ QTest::newRow("unknown-authorization-method") << "http://" + QtNetworkSettings::serverName() +
+ "/cgi-bin/http-unknown-authentication-method.cgi?401-authorization-required" << 1 << 1
+ << int(QNetworkReply::AuthenticationRequiredError) << 401 << "authorization required";
+ QTest::newRow("unknown-proxy-authorization-method") << "http://" + QtNetworkSettings::serverName() +
+ "/cgi-bin/http-unknown-authentication-method.cgi?407-proxy-authorization-required" << 1 << 1
+ << int(QNetworkReply::ProxyAuthenticationRequiredError) << 407
+ << "authorization required";
+}
+
+void tst_QNetworkReply::authorizationError()
+{
+ QFETCH(QString, url);
+ QNetworkRequest request(url);
+ QNetworkReplyPtr reply = manager.get(request);
+
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+
+ qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError");
+ QSignalSpy errorSpy(reply, SIGNAL(error(QNetworkReply::NetworkError)));
+ QSignalSpy finishedSpy(reply, SIGNAL(finished()));
+ // now run the request:
+ connect(reply, SIGNAL(finished()),
+ &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QTestEventLoop::instance().enterLoop(10);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ QFETCH(int, errorSignalCount);
+ QCOMPARE(errorSpy.count(), errorSignalCount);
+ QFETCH(int, finishedSignalCount);
+ QCOMPARE(finishedSpy.count(), finishedSignalCount);
+ QFETCH(int, error);
+ QCOMPARE(reply->error(), QNetworkReply::NetworkError(error));
+
+ QFETCH(int, httpStatusCode);
+ QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), httpStatusCode);
+
+ QFETCH(QString, httpBody);
+ QCOMPARE(QString(reply->readAll()), httpBody);
+}
+
QTEST_MAIN(tst_QNetworkReply)
#include "tst_qnetworkreply.moc"