Make it possible to cancel authentication with QtWebEngine

Fixes #2156
This commit is contained in:
Florian Bruhin 2016-12-06 07:45:03 +01:00
parent 717fc97f05
commit df5ce12ed8
3 changed files with 30 additions and 4 deletions

View File

@ -66,6 +66,7 @@ def authentication_required(url, authenticator, abort_on):
if answer is not None:
authenticator.setUser(answer.user)
authenticator.setPassword(answer.password)
return answer
def javascript_confirm(url, js_msg, abort_on):

View File

@ -37,7 +37,7 @@ from qutebrowser.browser.webengine import (webview, webengineelem, tabhistory,
interceptor, webenginequtescheme,
webenginedownloads)
from qutebrowser.utils import (usertypes, qtutils, log, javascript, utils,
objreg)
objreg, jinja)
_qute_scheme_handler = None
@ -604,9 +604,18 @@ class WebEngineTab(browsertab.AbstractTab):
@pyqtSlot(QUrl, 'QAuthenticator*')
def _on_authentication_required(self, url, authenticator):
# FIXME:qtwebengine support .netrc
shared.authentication_required(url, authenticator,
abort_on=[self.shutting_down,
self.load_started])
answer = shared.authentication_required(
url, authenticator, abort_on=[self.shutting_down,
self.load_started])
if answer is None:
# WORKAROUND for
# https://www.riverbankcomputing.com/pipermail/pyqt/2016-December/038400.html
url_string = url.toDisplayString()
error_page = jinja.render(
'error.html',
title="Error loading page: {}".format(url_string),
url=url_string, error="Authentication required", icon='')
self.set_html(error_page)
def _connect_signals(self):
view = self._widget

View File

@ -353,6 +353,22 @@ Feature: Prompts
"user": "user4"
}
# https://github.com/The-Compiler/qutebrowser/issues/2156
@qtwebkit_skip
Scenario: Cancellling webpage authentification with QtWebEngine
When I open basic-auth/user5/password5 without waiting
And I wait for a prompt
And I run :leave-mode
And I wait for "Changing title for idx * to 'Error loading page: *'" in the log
Then the page should contain the plaintext "Authentication required"
@qtwebengine_skip
Scenario: Cancellling webpage authentification with QtWebKit
When I open basic-auth/user6/password6 without waiting
And I wait for a prompt
And I run :leave-mode
Then basic-auth/user6/password6 should be loaded
# :prompt-accept with value argument
Scenario: Javascript alert with value