From 93023c5bfcbf5d6135bc3840832826894f6b4000 Mon Sep 17 00:00:00 2001 From: bendikro Date: Wed, 30 Dec 2015 22:26:56 +0100 Subject: [PATCH] [Core] Fix bug and add error testing to AuthManager --- deluge/core/authmanager.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/deluge/core/authmanager.py b/deluge/core/authmanager.py index bed29c970..ee94f003e 100644 --- a/deluge/core/authmanager.py +++ b/deluge/core/authmanager.py @@ -51,7 +51,7 @@ class Account(object): def __repr__(self): return ('' % - self.__dict__) + {"username": self.username, "authlevel": self.authlevel}) class AuthManager(component.Component): @@ -127,6 +127,8 @@ class AuthManager(component.Component): def create_account(self, username, password, authlevel): if username in self.__auth: raise AuthManagerError("Username in use.", username) + if authlevel not in AUTH_LEVELS_MAPPING: + raise AuthManagerError("Invalid auth level: '%s'" % authlevel) try: self.__auth[username] = Account(username, password, AUTH_LEVELS_MAPPING[authlevel]) @@ -139,6 +141,8 @@ class AuthManager(component.Component): def update_account(self, username, password, authlevel): if username not in self.__auth: raise AuthManagerError("Username not known", username) + if authlevel not in AUTH_LEVELS_MAPPING: + raise AuthManagerError("Invalid auth level: '%s'" % authlevel) try: self.__auth[username].username = username self.__auth[username].password = password