Add warning about unsupported HTTP authentication, and revert the realm changes.

This commit is contained in:
Bastian Kleineidam 2010-10-25 22:41:31 +02:00
parent d811269d03
commit 4375d35328
5 changed files with 20 additions and 13 deletions

View file

@ -1,5 +1,3 @@
- [HTTP] Allow multi-realm auth configuration
SF bug #3028302
- [GUI] Allow login URL to be configured.
- [GUI] Show detailed URL properties
- [GUI] Save options in qsettings or in external file (for each URL?).

View file

@ -90,6 +90,7 @@ WARN_HTTP_EMPTY_CONTENT = "http-empty-content"
WARN_HTTP_COOKIE_STORE_ERROR = "http-cookie-store-error"
WARN_HTTP_DECOMPRESS_ERROR = "http-decompress-error"
WARN_HTTP_UNSUPPORTED_ENCODING = "http-unsupported-encoding"
WARN_HTTP_AUTH_UNKNOWN = "http-auth-unknonwn"
WARN_IGNORE_URL = "ignore-url"
WARN_MAIL_NO_MX_HOST = "mail-no-mx-host"
WARN_MAIL_UNVERIFIED_ADDRESS = "mail-unverified-address"
@ -126,6 +127,8 @@ Warnings = {
_("An error occurred while decompressing the URL content."),
WARN_HTTP_UNSUPPORTED_ENCODING:
_("The URL content is encoded with an unknown encoding."),
WARN_HTTP_AUTH_UNKNOWN:
_("Unsupported HTTP authentication method."),
WARN_IGNORE_URL: _("The URL has been ignored."),
WARN_MAIL_NO_MX_HOST: _("The mail MX host could not be found."),
WARN_MAIL_UNVERIFIED_ADDRESS:

View file

@ -34,7 +34,8 @@ from . import (internpaturl, proxysupport, httpheaders as headers, urlbase,
from .const import WARN_HTTP_ROBOTS_DENIED, \
WARN_HTTP_WRONG_REDIRECT, WARN_HTTP_MOVED_PERMANENT, \
WARN_HTTP_EMPTY_CONTENT, WARN_HTTP_COOKIE_STORE_ERROR, \
WARN_HTTP_DECOMPRESS_ERROR, WARN_HTTP_UNSUPPORTED_ENCODING
WARN_HTTP_DECOMPRESS_ERROR, WARN_HTTP_UNSUPPORTED_ENCODING, \
WARN_HTTP_AUTH_UNKNOWN
# helper alias
unicode_safe = strformat.unicode_safe
@ -182,8 +183,8 @@ class HttpUrl (internpaturl.InternPatternUrl, proxysupport.ProxySupport):
if not self.allows_robots(self.url):
# remove all previously stored results
self.add_warning(
_("Access denied by robots.txt, skipping content checks."),
tag=WARN_HTTP_ROBOTS_DENIED)
_("Access denied by robots.txt, skipping content checks."),
tag=WARN_HTTP_ROBOTS_DENIED)
self.method_get_allowed = False
# first try with HEAD
self.method = "HEAD"
@ -288,6 +289,15 @@ Use URL `%(newurl)s' instead for checking.""") % {
return response
# user authentication
if response.status == 401:
authenticate = self.headers.get('WWW-Authenticate')
if not authenticate or not authenticate.startswith("Basic"):
# LinkChecker only supports Basic authorization
args = {"auth": authenticate},
self.add_warning(
_("Unsupported HTTP authentication `%(auth)s', " \
"only `Basic' authentication is supported.") % args,
tag=WARN_HTTP_AUTH_UNKNOWN)
return
if not self.auth:
import base64
_user, _password = self.get_user_password()

View file

@ -871,11 +871,11 @@ class UrlBase (object):
"""
self.parse_html()
def get_user_password (self, realm=None):
def get_user_password (self):
"""Get tuple (user, password) from configured authentication.
Both user and password can be None.
"""
return self.aggregate.config.get_user_password(self.url, realm=realm)
return self.aggregate.config.get_user_password(self.url)
def parse_html (self):
"""Parse into HTML content and search for URLs to check.

View file

@ -255,7 +255,7 @@ class Configuration (dict):
confparse.LCConfigParser(self).read(cfiles)
self.sanitize()
def add_auth (self, user=None, password=None, pattern=None, realm=None):
def add_auth (self, user=None, password=None, pattern=None):
if not user or not pattern:
log.warn(LOG_CHECK,
_("warning: missing user or URL pattern in authentication data."))
@ -264,11 +264,10 @@ class Configuration (dict):
user=user,
password=password,
pattern=re.compile(pattern),
realm=realm
)
self["authentication"].append(entry)
def get_user_password (self, url, realm=None):
def get_user_password (self, url):
"""Get tuple (user, password) from configured authentication
that matches the given URL.
Both user and password can be None if not specified, or no
@ -276,9 +275,6 @@ class Configuration (dict):
"""
for auth in self["authentication"]:
if auth['pattern'].match(url):
if realm is not None and auth['realm'] is not None \
and realm != auth['realm']:
continue
return (auth['user'], auth['password'])
return (None, None)