dav_auth: test if autogenerated password actually are configurable
Run tests / Execute tox to run the test suite (push) Successful in 3m40s
Run tests / Execute tox to run the test suite (push) Successful in 3m40s
This commit is contained in:
@@ -283,11 +283,28 @@ class ViewsTestCase(TestCase):
|
|||||||
def test_new_password_length(self):
|
def test_new_password_length(self):
|
||||||
location = self.recreate_password_url
|
location = self.recreate_password_url
|
||||||
|
|
||||||
default_password_length = 32
|
expected_password_length = 32
|
||||||
|
|
||||||
response = self.client.post(location, {'username': self.user.username})
|
response = self.client.post(location, {'username': self.user.username})
|
||||||
new_password = response.context['password']
|
new_password = response.context['password']
|
||||||
self.assertEqual(len(new_password), default_password_length)
|
self.assertEqual(len(new_password), expected_password_length)
|
||||||
|
|
||||||
|
expected_password_length = 12
|
||||||
|
self.app_settings.auto_password_length = expected_password_length
|
||||||
|
|
||||||
|
response = self.client.post(location, {'username': self.user.username})
|
||||||
|
new_password = response.context['password']
|
||||||
|
self.assertEqual(len(new_password), expected_password_length)
|
||||||
|
|
||||||
|
def test_new_password_chars(self):
|
||||||
|
location = self.recreate_password_url
|
||||||
|
|
||||||
|
password_chars = 'xYz0'
|
||||||
|
self.app_settings.auto_password_characters = password_chars
|
||||||
|
|
||||||
|
response = self.client.post(location, {'username': self.user.username})
|
||||||
|
new_password = response.context['password']
|
||||||
|
self.assertTrue(all(c in password_chars for c in new_password))
|
||||||
|
|
||||||
def test_new_password_is_valid(self):
|
def test_new_password_is_valid(self):
|
||||||
location = self.recreate_password_url
|
location = self.recreate_password_url
|
||||||
|
|||||||
+4
-5
@@ -79,14 +79,13 @@ class CreateAndSendPasswordView(generic.FormView):
|
|||||||
form_class = forms.CreateAndSendPasswordForm
|
form_class = forms.CreateAndSendPasswordForm
|
||||||
template_name = 'dav_auth/forms/recreate_password.html'
|
template_name = 'dav_auth/forms/recreate_password.html'
|
||||||
success_url = reverse_lazy('dav_auth:login')
|
success_url = reverse_lazy('dav_auth:login')
|
||||||
password_length = app_config.settings.auto_password_length
|
|
||||||
password_chars = app_config.settings.auto_password_characters
|
|
||||||
|
|
||||||
def _create_new_password(self, length=None, characters=None):
|
@staticmethod
|
||||||
|
def _create_new_password(length=None, characters=None):
|
||||||
if length is None:
|
if length is None:
|
||||||
length = self.password_length
|
length = app_config.settings.auto_password_length
|
||||||
if characters is None:
|
if characters is None:
|
||||||
characters = self.password_chars
|
characters = app_config.settings.auto_password_characters
|
||||||
return ''.join(secrets.choice(characters) for i in range(length))
|
return ''.join(secrets.choice(characters) for i in range(length))
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
|||||||
Reference in New Issue
Block a user