From 96e79e4a2f8f3e65f5ecfa458082ecc3ee3b7bc7 Mon Sep 17 00:00:00 2001 From: Sean Geoghegan Date: Mon, 17 Dec 2012 10:49:29 +1030 Subject: [PATCH] Fix authentication time outs. If the incorrect credentials are provided QNetworkAccessManager just keeps firing the same signal and it gets stuck in a infinite loop. This change only sets the user name and password if they are different to the current user name and password, causing the event to not be continuously triggered after failed authentications. --- spec/driver_spec.rb | 15 ++++++++++++++- src/NetworkAccessManager.cpp | 6 ++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index 596935b..1f571ce 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -1865,7 +1865,7 @@ describe Capybara::Webkit::Driver do let(:driver) do driver_for_app do get "/" do - if env["HTTP_AUTHORIZATION"] + if env["HTTP_AUTHORIZATION"] == "Basic #{Base64.encode64("user:password").strip}" env["HTTP_AUTHORIZATION"] else headers "WWW-Authenticate" => 'Basic realm="Secure Area"' @@ -1881,6 +1881,19 @@ describe Capybara::Webkit::Driver do visit("/") driver.html.should include("Basic "+Base64.encode64("user:password").strip) end + + it "returns 401 for incorrectly authenticated request" do + driver.browser.authenticate('user1', 'password1') + driver.browser.timeout = 2 + lambda { visit("/") }.should_not raise_error(Capybara::TimeoutError) + driver.status_code.should == 401 + end + + it "returns 401 for unauthenticated request" do + driver.browser.timeout = 2 + lambda { visit("/") }.should_not raise_error(Capybara::TimeoutError) + driver.status_code.should == 401 + end end describe "url blacklisting" do diff --git a/src/NetworkAccessManager.cpp b/src/NetworkAccessManager.cpp index 288a67a..438aae0 100644 --- a/src/NetworkAccessManager.cpp +++ b/src/NetworkAccessManager.cpp @@ -62,8 +62,10 @@ void NetworkAccessManager::setPassword(const QString &password) { void NetworkAccessManager::provideAuthentication(QNetworkReply *reply, QAuthenticator *authenticator) { Q_UNUSED(reply); - authenticator->setUser(m_userName); - authenticator->setPassword(m_password); + if (m_userName != authenticator->user()) + authenticator->setUser(m_userName); + if (m_password != authenticator->password()) + authenticator->setPassword(m_password); } int NetworkAccessManager::statusFor(QUrl url) {