From 23cc774f96b86b863733ebd3209d970b5187d247 Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Fri, 24 Aug 2012 00:27:22 -0400 Subject: [PATCH] Add error for bad configuration --- flask_security/utils.py | 6 ++++++ tests/functional_tests.py | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/flask_security/utils.py b/flask_security/utils.py index 2385277..9a8fa6d 100644 --- a/flask_security/utils.py +++ b/flask_security/utils.py @@ -80,6 +80,12 @@ def logout_user(): def get_hmac(password): if _security.password_hash == 'plaintext': return password + + if _security.password_salt is None: + raise RuntimeError('The configuration value `SECURITY_PASSWORD_SALT` ' + 'must not be None when the value of `SECURITY_PASSWORD_HASH` is ' + 'set to "%s"' % _security.password_hash) + h = hmac.new(_security.password_salt, password, hashlib.sha512) return base64.b64encode(h.digest()) diff --git a/tests/functional_tests.py b/tests/functional_tests.py index 51e5f00..9415fea 100644 --- a/tests/functional_tests.py +++ b/tests/functional_tests.py @@ -204,7 +204,6 @@ class ConfiguredSecurityTests(SecurityTest): AUTH_CONFIG = { 'SECURITY_PASSWORD_HASH': 'bcrypt', 'SECURITY_PASSWORD_SALT': 'so-salty', - 'SECURITY_PASSWORD_HMAC': True, 'SECURITY_REGISTERABLE': True, 'SECURITY_LOGOUT_URL': '/custom_logout', 'SECURITY_LOGIN_URL': '/custom_login', @@ -262,6 +261,16 @@ class ConfiguredSecurityTests(SecurityTest): self.assertEquals('Basic realm="Custom Realm"', r.headers['WWW-Authenticate']) +class BadConfiguredSecurityTests(SecurityTest): + + AUTH_CONFIG = { + 'SECURITY_PASSWORD_HASH': 'bcrypt', + } + + def test_bad_configuration_raises_runtimer_error(self): + self.assertRaises(RuntimeError, self.authenticate) + + class RegisterableTests(SecurityTest): AUTH_CONFIG = { 'SECURITY_REGISTERABLE': True