Credentials validation now happens in the UserManager

This commit is contained in:
Kovid Goyal 2015-11-14 17:05:56 +05:30
parent 75753b5318
commit bf676ffe86
3 changed files with 2 additions and 16 deletions

View File

@ -11,7 +11,7 @@ from hashlib import md5, sha256
from itertools import permutations
from threading import Lock
from calibre.srv.errors import HTTPAuthRequired, HTTPSimpleResponse, InvalidCredentials
from calibre.srv.errors import HTTPAuthRequired, HTTPSimpleResponse
from calibre.srv.http_request import parse_uri
from calibre.srv.utils import parse_http_dict, encode_path
from calibre.utils.monotonic import monotonic
@ -196,13 +196,6 @@ class AuthController(object):
self.realm = realm
if '"' in realm:
raise ValueError('Double-quotes are not allowed in the authentication realm')
for k, v in self.user_credentials.iteritems():
if '"' in k:
raise ValueError('Double-quotes are not allowed in usernames')
try:
k.encode('ascii'), v.encode('ascii')
except ValueError:
raise InvalidCredentials('Only ASCII characters are allowed in usernames and passwords')
def check(self, un, pw):
return pw and self.user_credentials.get(un) == pw

View File

@ -43,6 +43,3 @@ class HTTPBadRequest(HTTPSimpleResponse):
def __init__(self, message, close_connection=False):
HTTPSimpleResponse.__init__(self, httplib.BAD_REQUEST, message, close_connection)
class InvalidCredentials(ValueError):
pass

View File

@ -10,7 +10,6 @@ import sys, os, signal
from calibre import as_unicode, prints
from calibre.constants import plugins, iswindows, preferred_encoding
from calibre.srv.errors import InvalidCredentials
from calibre.srv.loop import ServerLoop
from calibre.srv.bonjour import BonJour
from calibre.srv.opts import opts_to_parser
@ -227,10 +226,7 @@ def main(args=sys.argv):
except NoAutoReload as e:
raise SystemExit(e.message)
opts.auto_reload_port=int(os.environ.get('CALIBRE_AUTORELOAD_PORT', 0))
try:
server=Server(libraries, opts)
except InvalidCredentials as e:
raise SystemExit(e.message)
server=Server(libraries, opts)
if opts.daemonize:
if not opts.log and not iswindows:
raise SystemExit('In order to daemonize you must specify a log file, you can use /dev/stdout to log to screen even as a daemon')