Adding the ability to configure password strength in the local_settings. Fixes bug 948317
Change-Id: I96e3838ab6675e7282172e56be3f0359065caccb
This commit is contained in:
parent
e165416a12
commit
24f6bc59b2
1
AUTHORS
1
AUTHORS
@ -23,6 +23,7 @@ Jay Pipes <jaypipes@gmail.com>
|
|||||||
Jeffrey Wilcox <jeffjapan@gmail.com>
|
Jeffrey Wilcox <jeffjapan@gmail.com>
|
||||||
Jesse Andrews <anotherjesse@gmail.com>
|
Jesse Andrews <anotherjesse@gmail.com>
|
||||||
Jim Yeh <lemonlatte@gmail.com>
|
Jim Yeh <lemonlatte@gmail.com>
|
||||||
|
John Postlethwait <john.postlethwait@nebula.com>
|
||||||
Joseph Heck <heckj@mac.com>
|
Joseph Heck <heckj@mac.com>
|
||||||
Joshua McKenty <joshua@pistoncloud.com>
|
Joshua McKenty <joshua@pistoncloud.com>
|
||||||
Julien Danjou <julien.danjou@enovance.com>
|
Julien Danjou <julien.danjou@enovance.com>
|
||||||
|
@ -28,6 +28,7 @@ from django.forms import ValidationError
|
|||||||
from horizon import api
|
from horizon import api
|
||||||
from horizon import exceptions
|
from horizon import exceptions
|
||||||
from horizon import forms
|
from horizon import forms
|
||||||
|
from horizon.utils import validators
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -61,10 +62,14 @@ class BaseUserForm(forms.SelfHandlingForm):
|
|||||||
class CreateUserForm(BaseUserForm):
|
class CreateUserForm(BaseUserForm):
|
||||||
name = forms.CharField(label=_("Name"))
|
name = forms.CharField(label=_("Name"))
|
||||||
email = forms.EmailField(label=_("Email"))
|
email = forms.EmailField(label=_("Email"))
|
||||||
password = forms.CharField(label=_("Password"),
|
password = forms.RegexField(
|
||||||
widget=forms.PasswordInput(render_value=False))
|
label=_("Password"),
|
||||||
|
widget=forms.PasswordInput(render_value=False),
|
||||||
|
regex=validators.password_validator(),
|
||||||
|
error_messages={'invalid': validators.password_validator_msg()})
|
||||||
confirm_password = forms.CharField(
|
confirm_password = forms.CharField(
|
||||||
label=_("Confirm Password"),
|
label=_("Confirm Password"),
|
||||||
|
required=False,
|
||||||
widget=forms.PasswordInput(render_value=False))
|
widget=forms.PasswordInput(render_value=False))
|
||||||
tenant_id = forms.ChoiceField(label=_("Primary Project"))
|
tenant_id = forms.ChoiceField(label=_("Primary Project"))
|
||||||
|
|
||||||
|
@ -82,10 +82,25 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
'confirm_password': "doesntmatch"}
|
'confirm_password': "doesntmatch"}
|
||||||
|
|
||||||
res = self.client.post(USER_CREATE_URL, formData)
|
res = self.client.post(USER_CREATE_URL, formData)
|
||||||
self.assertFormError(res,
|
self.assertFormError(res, "form", None, ['Passwords do not match.'])
|
||||||
"form",
|
|
||||||
None,
|
def test_user_password_validation(self):
|
||||||
['Passwords do not match.'])
|
user = self.users.get(id="1")
|
||||||
|
self.mox.StubOutWithMock(api, 'tenant_list')
|
||||||
|
api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
|
||||||
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
|
formData = {'method': 'CreateUserForm',
|
||||||
|
'name': user.name,
|
||||||
|
'email': user.email,
|
||||||
|
'password': 'four',
|
||||||
|
'tenant_id': self.tenant.id,
|
||||||
|
'confirm_password': "four"}
|
||||||
|
|
||||||
|
res = self.client.post(USER_CREATE_URL, formData)
|
||||||
|
self.assertFormError(
|
||||||
|
res, "form", 'password',
|
||||||
|
['Your password must be at least 6 characters long.'])
|
||||||
|
|
||||||
def test_enable_user(self):
|
def test_enable_user(self):
|
||||||
user = self.users.get(id="2")
|
user = self.users.get(id="2")
|
||||||
|
@ -89,6 +89,10 @@ SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
|
|||||||
HORIZON_CONFIG = {
|
HORIZON_CONFIG = {
|
||||||
'dashboards': ('nova', 'syspanel', 'settings',),
|
'dashboards': ('nova', 'syspanel', 'settings',),
|
||||||
'default_dashboard': 'nova',
|
'default_dashboard': 'nova',
|
||||||
|
"password_validator": {
|
||||||
|
"regex": '.{6,}',
|
||||||
|
"help_text": "Your password must be at least 6 characters long."
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
AVAILABLE_REGIONS = [
|
AVAILABLE_REGIONS = [
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
@ -31,3 +33,15 @@ validate_ipv4_cidr = validators.RegexValidator(ipv4_cidr_re)
|
|||||||
def validate_port_range(port):
|
def validate_port_range(port):
|
||||||
if port not in range(-1, 65535):
|
if port not in range(-1, 65535):
|
||||||
raise ValidationError("Not a valid port number")
|
raise ValidationError("Not a valid port number")
|
||||||
|
|
||||||
|
|
||||||
|
def password_validator():
|
||||||
|
config = getattr(settings, "HORIZON_CONFIG", {})
|
||||||
|
password_config = config.get("password_validator", {})
|
||||||
|
return password_config.get("regex", ".*")
|
||||||
|
|
||||||
|
|
||||||
|
def password_validator_msg():
|
||||||
|
config = getattr(settings, "HORIZON_CONFIG", {})
|
||||||
|
password_config = config.get("password_validator", {})
|
||||||
|
return password_config.get("help_text", None)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
TEMPLATE_DEBUG = DEBUG
|
TEMPLATE_DEBUG = DEBUG
|
||||||
PROD = False
|
PROD = False
|
||||||
@ -8,6 +10,14 @@ USE_SSL = False
|
|||||||
# Note: You should change this value
|
# Note: You should change this value
|
||||||
SECRET_KEY = 'elj1IWiLoWHgcyYxFVLj7cM5rGOOxWl0'
|
SECRET_KEY = 'elj1IWiLoWHgcyYxFVLj7cM5rGOOxWl0'
|
||||||
|
|
||||||
|
# Specify a regular expression to validate user passwords.
|
||||||
|
# HORIZON_CONFIG = {
|
||||||
|
# "password_validator": {
|
||||||
|
# "regex": '.*',
|
||||||
|
# "help_text": _("Your password does not meet the requirements.")
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
||||||
LOCAL_PATH = os.path.dirname(os.path.abspath(__file__))
|
LOCAL_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
# We recommend you use memcached for development; otherwise after every reload
|
# We recommend you use memcached for development; otherwise after every reload
|
||||||
|
Loading…
x
Reference in New Issue
Block a user