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.
This commit is contained in:
Sean Geoghegan 2012-12-17 10:49:29 +10:30
parent 77811ca9ba
commit 96e79e4a2f
2 changed files with 18 additions and 3 deletions

View File

@ -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

View File

@ -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) {