Preventing caching of null authenticator

In some cases, e.g. when bad credentials are provided in an ftp URI,
QNetworkAccessAuthenticationManager::cacheCredentials is called with a
null authenticator. This authenticator should not be cached, because
it is useless, and leads to inconsistencies in the use of the cache

Task-number: QTBUG-40622
Change-Id: If2a0a422b915f268648f5eef1d68601446123371
Reviewed-by: Peter Hartmann <phartmann@blackberry.com>
This commit is contained in:
Eric Lemanissier 2014-09-01 19:57:51 +02:00 committed by Giuseppe D'Angelo
parent 529a31c967
commit 3e80497668
2 changed files with 25 additions and 0 deletions

View File

@ -231,6 +231,8 @@ void QNetworkAccessAuthenticationManager::cacheCredentials(const QUrl &url,
const QAuthenticator *authenticator)
{
Q_ASSERT(authenticator);
if (authenticator->isNull())
return;
QString domain = QString::fromLatin1("/"); // FIXME: make QAuthenticator return the domain
QString realm = authenticator->realm();

View File

@ -219,6 +219,7 @@ private Q_SLOTS:
void putToFile();
void putToFtp_data();
void putToFtp();
void putToFtpWithInvalidCredentials(); // QTBUG-40622
void putToHttp_data();
void putToHttp();
void putToHttpSynchronous_data();
@ -2075,6 +2076,28 @@ void tst_QNetworkReply::putToFtp()
QObject::disconnect(r, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
}
void tst_QNetworkReply::putToFtpWithInvalidCredentials()
{
QUrl url("ftp://" + QtNetworkSettings::serverName());
url.setPath(QString("/qtest/upload/qnetworkaccess-putToFtp-%1-%2")
.arg(QTest::currentDataTag())
.arg(uniqueExtension));
url.setUserName("invalidUser");
url.setPassword("InvalidPassword");
QNetworkRequest req(url);
QNetworkReplyPtr r;
for (int i = 0; i < 2; i++)
{
runSimpleRequest(QNetworkAccessManager::PutOperation, req, r, QByteArray());
QVERIFY(r->isFinished());
QCOMPARE(r->url(), url);
QCOMPARE(r->error(), QNetworkReply::AuthenticationRequiredError);
r->close();
}
}
void tst_QNetworkReply::putToHttp_data()
{
putToFile_data();