diff options
author | Peter Hartmann <peter.hartmann@nokia.com> | 2011-01-24 13:22:57 (GMT) |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2011-01-26 07:40:32 (GMT) |
commit | 374aa39abf0fc14eadb59346c5fb9d6dd763e592 (patch) | |
tree | 39abda76654e3a84e49c6f99c59c109f4c05c8bb | |
parent | af44e4ff66558b4ae03248270557eb120c3b7d7c (diff) | |
download | Qt-374aa39abf0fc14eadb59346c5fb9d6dd763e592.zip Qt-374aa39abf0fc14eadb59346c5fb9d6dd763e592.tar.gz Qt-374aa39abf0fc14eadb59346c5fb9d6dd763e592.tar.bz2 |
add autotest for digest authentication
Reviewed-by: Markus Goetz
Task-number: QTBUG-15070
(cherry picked from commit c6a6448272168f0105c973bef5e531114533fc90)
-rw-r--r-- | tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index bd22837..8274140 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -212,6 +212,7 @@ private Q_SLOTS: void ioGetFromBuiltinHttp(); void ioGetFromHttpWithReuseParallel(); void ioGetFromHttpWithReuseSequential(); + void ioGetFromHttpWithAuth_data(); void ioGetFromHttpWithAuth(); void ioGetFromHttpWithAuthSynchronous(); void ioGetFromHttpWithProxyAuth(); @@ -2163,15 +2164,27 @@ void tst_QNetworkReply::ioGetFromHttpWithReuseSequential() } } +void tst_QNetworkReply::ioGetFromHttpWithAuth_data() +{ + QTest::addColumn<QUrl>("url"); + QTest::addColumn<QByteArray>("expectedData"); + + QFile reference(SRCDIR "/rfc3252.txt"); + reference.open(QIODevice::ReadOnly); + QByteArray referenceData = reference.readAll(); + QTest::newRow("basic") << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfcs-auth/rfc3252.txt") << referenceData; + QTest::newRow("digest") << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/auth-digest/") << QByteArray("digest authentication successful\n"); +} + void tst_QNetworkReply::ioGetFromHttpWithAuth() { // This test sends three requests // The first two in parallel // The third after the first two finished - QFile reference(SRCDIR "/rfc3252.txt"); - QVERIFY(reference.open(QIODevice::ReadOnly)); - QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfcs-auth/rfc3252.txt")); + QFETCH(QUrl, url); + QFETCH(QByteArray, expectedData); + QNetworkRequest request(url); { QNetworkReplyPtr reply1 = manager.get(request); QNetworkReplyPtr reply2 = manager.get(request); @@ -2196,14 +2209,12 @@ void tst_QNetworkReply::ioGetFromHttpWithAuth() QCOMPARE(reply1->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); QCOMPARE(reply2->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); - QByteArray referenceData = reference.readAll(); - QCOMPARE(reader1.data, referenceData); - QCOMPARE(reader2.data, referenceData); + QCOMPARE(reader1.data, expectedData); + QCOMPARE(reader2.data, expectedData); QCOMPARE(authspy.count(), 1); } - reference.seek(0); // rinse and repeat: { QNetworkReplyPtr reply = manager.get(request); @@ -2219,13 +2230,12 @@ void tst_QNetworkReply::ioGetFromHttpWithAuth() this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); - QCOMPARE(reader.data, reference.readAll()); + QCOMPARE(reader.data, expectedData); QCOMPARE(authspy.count(), 0); } // now check with synchronous calls: - reference.seek(0); { request.setAttribute( static_cast<QNetworkRequest::Attribute>(SynchronousRequestAttribute), @@ -2241,7 +2251,7 @@ void tst_QNetworkReply::ioGetFromHttpWithAuth() // the only thing we check here is that the auth cache was used when using synchronous requests QCOMPARE(replySync->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); - QCOMPARE(replySync->readAll(), reference.readAll()); + QCOMPARE(replySync->readAll(), expectedData); } } |