QNetworkAccessFtpBackend: remove entry from QNetworkAccessCache

When FTP login fails we fail to remove the entry from the cache.
This is because the cache key is created from the url with the
userInfo. So this needs to be set again to match the key used
when inserted.

Task-number: QTBUG-11824
Change-Id: Ib3fd2d737581653ae59c56d0810d42e2d8dc2176
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
This commit is contained in:
Martin Petersson 2012-03-27 17:14:24 +02:00 committed by Qt by Nokia
parent e6f7852bb4
commit 3dbf98c715
2 changed files with 37 additions and 0 deletions

View File

@ -223,6 +223,7 @@ void QNetworkAccessFtpBackend::ftpDone()
if (ftp->state() == QFtp::Connected) {
// the login did not succeed
QUrl newUrl = url();
QString userInfo = newUrl.userInfo();
newUrl.setUserInfo(QString());
setUrl(newUrl);
@ -236,6 +237,10 @@ void QNetworkAccessFtpBackend::ftpDone()
return;
}
// Re insert the user info so that we can remove the cache entry.
newUrl.setUserInfo(userInfo);
setUrl(newUrl);
error(QNetworkReply::AuthenticationRequiredError,
tr("Logging in to %1 failed: authentication required")
.arg(url().host()));

View File

@ -401,6 +401,9 @@ private Q_SLOTS:
void closeDuringDownload_data();
void closeDuringDownload();
void ftpAuthentication_data();
void ftpAuthentication();
// NOTE: This test must be last!
void parentingRepliesToTheApp();
private:
@ -6776,6 +6779,35 @@ void tst_QNetworkReply::closeDuringDownload()
QTest::qWait(1000); //cancelling ftp takes some time, this avoids a warning caused by test's cleanup() destroying the connection cache before the abort is finished
}
void tst_QNetworkReply::ftpAuthentication_data()
{
QTest::addColumn<QString>("referenceName");
QTest::addColumn<QString>("url");
QTest::addColumn<int>("error");
QTest::newRow("invalidPassword") << (testDataDir + "/rfc3252.txt") << "ftp://ftptest:invalid@" + QtNetworkSettings::serverName() + "/home/qt-test-server/ftp/qtest/rfc3252.txt" << int(QNetworkReply::AuthenticationRequiredError);
QTest::newRow("validPassword") << (testDataDir + "/rfc3252.txt") << "ftp://ftptest:password@" + QtNetworkSettings::serverName() + "/home/qt-test-server/ftp/qtest/rfc3252.txt" << int(QNetworkReply::NoError);
}
void tst_QNetworkReply::ftpAuthentication()
{
QFETCH(QString, referenceName);
QFETCH(QString, url);
QFETCH(int, error);
QFile reference(referenceName);
QVERIFY(reference.open(QIODevice::ReadOnly));
QNetworkRequest request(url);
QNetworkReplyPtr reply;
runSimpleRequest(QNetworkAccessManager::GetOperation, request, reply);
QCOMPARE(reply->url(), request.url());
QCOMPARE(reply->error(), QNetworkReply::NetworkError(error));
}
// NOTE: This test must be last testcase in tst_qnetworkreply!
void tst_QNetworkReply::parentingRepliesToTheApp()
{