Added tests

This commit is contained in:
Spitfireap
2025-06-23 10:05:34 +02:00
committed by Antoine Nguyen
parent 8965e7ea78
commit 8ea5928869
2 changed files with 23 additions and 16 deletions
+20 -14
View File
@@ -292,26 +292,32 @@ def domain_has_authorized_mx(name):
def make_password():
"""Create a random password."""
length = int(param_tools.get_global_parameter("random_password_length", app="core"))
allow_special_characters = bool(param_tools.get_global_parameter("allow_special_characters", app="core"))
possible_chars_types = [string.ascii_letters, string.digits]
all_possible_chars = ''
certain_chars = ''
for i in range(10): # limit tries
if allow_special_characters: # add special characters in random passwd
password_length = int(
param_tools.get_global_parameter("random_password_length", app="core")
)
allow_special_characters = bool(
param_tools.get_global_parameter("allow_special_characters", app="core")
)
for i in range(10): # limit tries
all_possible_chars = ""
possible_chars_types = [string.ascii_letters, string.digits]
certain_chars = ""
if allow_special_characters: # add special characters in random passwd
possible_chars_types.append(string.punctuation)
# make it so there is always one character of each type in password
# and then will randomize their placement
for possible_chars in possible_chars_types:
all_possible_chars += possible_chars
certain_chars += random.SystemRandom().choice(possible_chars)
password = "".join(
random.SystemRandom().choice(all_possible_chars) \
for _ in range(length - len(possible_chars_types))
) + certain_chars
li_password = list(password)
random.shuffle(li_password)
password = "".join(li_password)
password = (
"".join(
random.SystemRandom().choice(all_possible_chars)
for _ in range(password_length - len(possible_chars_types))
)
+ certain_chars
)
random.shuffle(list(password))
password = "".join(password)
try:
password_validation.validate_password(password)
except ValidationError:
+3 -2
View File
@@ -1,14 +1,15 @@
from unittest import skipIf
import string
from django.test import override_settings
from django.urls import reverse
from modoboa.core import factories as core_factories
from modoboa.core.models import User
from modoboa.core.models import User, LocalConfig
from modoboa.core.tests import test_ldap
from modoboa.lib.tests import NO_LDAP, ModoAPITestCase
from modoboa.limits import utils as limits_utils
from .. import factories, models
from .. import factories, models, lib
class AuthenticationTestCase(ModoAPITestCase):