Permalink
Browse files

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.
  • Loading branch information...
seangeo committed Dec 17, 2012
1 parent 77811ca commit 96e79e4a2f8f3e65f5ecfa458082ecc3ee3b7bc7
Showing with 18 additions and 3 deletions.
  1. +14 −1 spec/driver_spec.rb
  2. +4 −2 src/NetworkAccessManager.cpp
View
@@ -1865,7 +1865,7 @@ def which_for(character)
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 @@ def which_for(character)
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
@@ -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) {

0 comments on commit 96e79e4

Please sign in to comment.