summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMÃ¥rten Nordheim <marten.nordheim@qt.io>2020-09-10 16:30:36 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-09-12 16:15:34 +0000
commit5a23cdd3f51410b556e146a8136ef7a0fa3ee942 (patch)
tree7e59e2ce736733acc06b711c376a9ddc3184d4f9
parent6e7c416391889461f035219ad1b80cb8c4617bbc (diff)
tst_QNetworkReply: Avoid race in ioGetFromHttpWithAuth
Our authentication code is race-y by design: 1. When two requests are fired off and queued at the same time in the same QHttpNetworkConnection then if one of them encounters "authentication required" then it will copy whatever credentials it got to all the other channels in the connection. This is likely what the first part of the test is testing. 2. If a later request is fired off and it includes credentials in the url then the newly included credentials should be used instead of the cached ones. The race here can occurr when one socket either takes too long to connect or the connected signal is not received early enough. Then the first socket is used for both requests and then we can hit case #2 when the url contains credentials. Change-Id: I646a5378d8c1256b2de98b51912953df29f68cb2 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> (cherry picked from commit 5a47939d5c07a968f27562a3ebc800fcc2b225bc) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
index c8fe33f482..058b28f04e 100644
--- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -3508,7 +3508,11 @@ void tst_QNetworkReply::ioGetFromHttpWithAuth()
QNetworkRequest request(url);
{
QNetworkReplyPtr reply1(manager.get(request));
- QNetworkReplyPtr reply2(manager.get(request));
+ QUrl copy = url;
+ copy.setUserName(QString());
+ copy.setPassword(QString());
+ QNetworkRequest request2(copy);
+ QNetworkReplyPtr reply2(manager.get(request2));
DataReader reader1(reply1);
DataReader reader2(reply2);
QSignalSpy finishedspy(reply1.data(), SIGNAL(finished()));