def test_host_tuple(qurl, tpl): """Test host_tuple(). Args: qurl: The QUrl to pass. tpl: The expected tuple, or None if a ValueError is expected. """ if tpl is None: with pytest.raises(ValueError): urlutils.host_tuple(qurl) else: assert urlutils.host_tuple(qurl) == tpl
def on_ssl_errors(self, reply, errors): # pragma: no mccabe """Decide if SSL errors should be ignored or not. This slot is called on SSL/TLS errors by the self.sslErrors signal. Args: reply: The QNetworkReply that is encountering the errors. errors: A list of errors. """ errors = [SslError(e) for e in errors] ssl_strict = config.get('network', 'ssl-strict') log.webview.debug("SSL errors {!r}, strict {}".format( errors, ssl_strict)) try: host_tpl = urlutils.host_tuple(reply.url()) except ValueError: host_tpl = None is_accepted = False is_rejected = False else: is_accepted = set(errors).issubset( self._accepted_ssl_errors[host_tpl]) is_rejected = set(errors).issubset( self._rejected_ssl_errors[host_tpl]) log.webview.debug("Already accepted: {} / " "rejected {}".format(is_accepted, is_rejected)) if (ssl_strict and ssl_strict != 'ask') or is_rejected: return elif is_accepted: reply.ignoreSslErrors() return if ssl_strict == 'ask': err_string = '\n'.join('- ' + err.errorString() for err in errors) answer = self._ask('SSL errors - continue?\n{}'.format(err_string), mode=usertypes.PromptMode.yesno, owner=reply) log.webview.debug("Asked for SSL errors, answer {}".format(answer)) if answer: reply.ignoreSslErrors() err_dict = self._accepted_ssl_errors else: err_dict = self._rejected_ssl_errors if host_tpl is not None: err_dict[host_tpl] += errors else: log.webview.debug("ssl-strict is False, only warning about errors") for err in errors: # FIXME we might want to use warn here (non-fatal error) # https://github.com/The-Compiler/qutebrowser/issues/114 message.error(self._win_id, 'SSL error: {}'.format(err.errorString())) reply.ignoreSslErrors() self._accepted_ssl_errors[host_tpl] += errors
def on_ssl_errors(self, reply, errors): # pragma: no mccabe """Decide if SSL errors should be ignored or not. This slot is called on SSL/TLS errors by the self.sslErrors signal. Args: reply: The QNetworkReply that is encountering the errors. errors: A list of errors. """ errors = [SslError(e) for e in errors] ssl_strict = config.get('network', 'ssl-strict') log.webview.debug("SSL errors {!r}, strict {}".format( errors, ssl_strict)) try: host_tpl = urlutils.host_tuple(reply.url()) except ValueError: host_tpl = None is_accepted = False is_rejected = False else: is_accepted = set(errors).issubset( self._accepted_ssl_errors[host_tpl]) is_rejected = set(errors).issubset( self._rejected_ssl_errors[host_tpl]) log.webview.debug("Already accepted: {} / " "rejected {}".format(is_accepted, is_rejected)) if (ssl_strict and ssl_strict != 'ask') or is_rejected: return elif is_accepted: reply.ignoreSslErrors() return if ssl_strict == 'ask': err_string = '\n'.join('- ' + err.errorString() for err in errors) answer = self._ask('SSL errors - continue?\n{}'.format(err_string), mode=usertypes.PromptMode.yesno, owner=reply) log.webview.debug("Asked for SSL errors, answer {}".format(answer)) if answer: reply.ignoreSslErrors() err_dict = self._accepted_ssl_errors else: err_dict = self._rejected_ssl_errors if host_tpl is not None: err_dict[host_tpl] += errors else: log.webview.debug("ssl-strict is False, only warning about errors") for err in errors: # FIXME we might want to use warn here (non-fatal error) # https://github.com/The-Compiler/qutebrowser/issues/114 message.error(self._win_id, 'SSL error: {}'.format( err.errorString())) reply.ignoreSslErrors() self._accepted_ssl_errors[host_tpl] += errors
def on_ssl_errors(self, reply, errors): # pragma: no mccabe """Decide if SSL errors should be ignored or not. This slot is called on SSL/TLS errors by the self.sslErrors signal. Args: reply: The QNetworkReply that is encountering the errors. errors: A list of errors. """ errors = [SslError(e) for e in errors] ssl_strict = config.get('network', 'ssl-strict') if ssl_strict == 'ask': try: host_tpl = urlutils.host_tuple(reply.url()) except ValueError: host_tpl = None is_accepted = False is_rejected = False else: is_accepted = set(errors).issubset( self._accepted_ssl_errors[host_tpl]) is_rejected = set(errors).issubset( self._rejected_ssl_errors[host_tpl]) if is_accepted: reply.ignoreSslErrors() elif is_rejected: pass else: err_string = '\n'.join('- ' + err.errorString() for err in errors) answer = self._ask( 'SSL errors - continue?\n{}'.format(err_string), mode=usertypes.PromptMode.yesno, owner=reply) if answer: reply.ignoreSslErrors() d = self._accepted_ssl_errors else: d = self._rejected_ssl_errors if host_tpl is not None: d[host_tpl] += errors elif ssl_strict: pass else: for err in errors: # FIXME we might want to use warn here (non-fatal error) # https://github.com/The-Compiler/qutebrowser/issues/114 message.error(self._win_id, 'SSL error: {}'.format(err.errorString())) reply.ignoreSslErrors()
def on_ssl_errors(self, reply, qt_errors): # noqa: C901 pragma: no mccabe """Decide if SSL errors should be ignored or not. This slot is called on SSL/TLS errors by the self.sslErrors signal. Args: reply: The QNetworkReply that is encountering the errors. qt_errors: A list of errors. """ errors = certificateerror.CertificateErrorWrapper(qt_errors) log.network.debug("Certificate errors: {!r}".format(errors)) try: host_tpl: Optional[urlutils.HostTupleType] = urlutils.host_tuple( reply.url()) except ValueError: host_tpl = None is_accepted = False is_rejected = False else: assert host_tpl is not None is_accepted = errors in self._accepted_ssl_errors[host_tpl] is_rejected = errors in self._rejected_ssl_errors[host_tpl] log.network.debug("Already accepted: {} / " "rejected {}".format(is_accepted, is_rejected)) if is_rejected: return elif is_accepted: reply.ignoreSslErrors() return abort_on = self._get_abort_signals(reply) tab = self._get_tab() first_party_url = QUrl( ) if tab is None else tab.data.last_navigation.url ignore = shared.ignore_certificate_error( request_url=reply.url(), first_party_url=first_party_url, error=errors, abort_on=abort_on, ) if ignore: reply.ignoreSslErrors() if host_tpl is not None: self._accepted_ssl_errors[host_tpl].add(errors) elif host_tpl is not None: self._rejected_ssl_errors[host_tpl].add(errors)
def on_ssl_errors(self, reply, errors): # pragma: no mccabe """Decide if SSL errors should be ignored or not. This slot is called on SSL/TLS errors by the self.sslErrors signal. Args: reply: The QNetworkReply that is encountering the errors. errors: A list of errors. """ errors = [SslError(e) for e in errors] ssl_strict = config.get('network', 'ssl-strict') if ssl_strict == 'ask': try: host_tpl = urlutils.host_tuple(reply.url()) except ValueError: host_tpl = None is_accepted = False is_rejected = False else: is_accepted = set(errors).issubset( self._accepted_ssl_errors[host_tpl]) is_rejected = set(errors).issubset( self._rejected_ssl_errors[host_tpl]) if is_accepted: reply.ignoreSslErrors() elif is_rejected: pass else: err_string = '\n'.join('- ' + err.errorString() for err in errors) answer = self._ask('SSL errors - continue?\n{}'.format( err_string), mode=usertypes.PromptMode.yesno, owner=reply) if answer: reply.ignoreSslErrors() d = self._accepted_ssl_errors else: d = self._rejected_ssl_errors if host_tpl is not None: d[host_tpl] += errors elif ssl_strict: pass else: for err in errors: # FIXME we might want to use warn here (non-fatal error) # https://github.com/The-Compiler/qutebrowser/issues/114 message.error(self._win_id, 'SSL error: {}'.format(err.errorString())) reply.ignoreSslErrors()
def on_ssl_errors(self, reply, errors): # noqa: C901 pragma: no mccabe """Decide if SSL errors should be ignored or not. This slot is called on SSL/TLS errors by the self.sslErrors signal. Args: reply: The QNetworkReply that is encountering the errors. errors: A list of errors. """ errors = [certificateerror.CertificateErrorWrapper(e) for e in errors] log.webview.debug("Certificate errors: {!r}".format(' / '.join( str(err) for err in errors))) try: host_tpl = urlutils.host_tuple( reply.url()) # type: typing.Optional[urlutils.HostTupleType] except ValueError: host_tpl = None is_accepted = False is_rejected = False else: assert host_tpl is not None is_accepted = set(errors).issubset( self._accepted_ssl_errors[host_tpl]) is_rejected = set(errors).issubset( self._rejected_ssl_errors[host_tpl]) log.webview.debug("Already accepted: {} / " "rejected {}".format(is_accepted, is_rejected)) if is_rejected: return elif is_accepted: reply.ignoreSslErrors() return abort_on = self._get_abort_signals(reply) ignore = shared.ignore_certificate_errors(reply.url(), errors, abort_on=abort_on) if ignore: reply.ignoreSslErrors() err_dict = self._accepted_ssl_errors else: err_dict = self._rejected_ssl_errors if host_tpl is not None: err_dict[host_tpl] += errors
def on_ssl_errors(self, reply, errors): # pragma: no mccabe """Decide if SSL errors should be ignored or not. This slot is called on SSL/TLS errors by the self.sslErrors signal. Args: reply: The QNetworkReply that is encountering the errors. errors: A list of errors. """ errors = [certificateerror.CertificateErrorWrapper(e) for e in errors] log.webview.debug("Certificate errors: {!r}".format( ' / '.join(str(err) for err in errors))) try: host_tpl = urlutils.host_tuple(reply.url()) except ValueError: host_tpl = None is_accepted = False is_rejected = False else: is_accepted = set(errors).issubset( self._accepted_ssl_errors[host_tpl]) is_rejected = set(errors).issubset( self._rejected_ssl_errors[host_tpl]) log.webview.debug("Already accepted: {} / " "rejected {}".format(is_accepted, is_rejected)) if is_rejected: return elif is_accepted: reply.ignoreSslErrors() return abort_on = self._get_abort_signals(reply) ignore = shared.ignore_certificate_errors(reply.url(), errors, abort_on=abort_on) if ignore: reply.ignoreSslErrors() err_dict = self._accepted_ssl_errors else: err_dict = self._rejected_ssl_errors if host_tpl is not None: err_dict[host_tpl] += errors
def test_host_tuple_invalid(qurl, expected): with pytest.raises(expected): urlutils.host_tuple(qurl)
def test_host_tuple_valid(qurl, expected): assert urlutils.host_tuple(qurl) == expected