Skip to content

Commit 518d12f

Browse files
committed
doveauth: invite token doesn't overwrite nocreate file, must be at beginning of password
1 parent 887b647 commit 518d12f

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

chatmaild/src/chatmaild/doveauth.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ def encrypt_password(password: str):
2424
def is_allowed_to_create(config: Config, user, cleartext_password) -> bool:
2525
"""Return True if user and password are admissable."""
2626
if os.path.exists(NOCREATE_FILE):
27-
if not config.invite_token or config.invite_token not in cleartext_password:
28-
logging.warning(
29-
f"blocked account creation because {NOCREATE_FILE!r} exists."
30-
)
31-
return False
27+
logging.warning(
28+
f"blocked account creation because {NOCREATE_FILE!r} exists."
29+
)
30+
return False
31+
if cleartext_password.startswith(config.invite_token):
32+
password_length = len(cleartext_password) - len(config.invite_token)
33+
else:
34+
logging.warning(
35+
f"blocked account creation because password didn't contain invite token(s)."
36+
)
37+
return False
3238

33-
if (
34-
len(cleartext_password.replace(config.invite_token, ""))
35-
< config.password_min_length
36-
):
39+
if password_length < config.password_min_length:
3740
logging.warning(
3841
"Password needs to be at least %s characters long",
3942
config.password_min_length,

chatmaild/src/chatmaild/tests/test_doveauth.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ def test_dont_overwrite_password_on_wrong_login(dictproxy):
6868
["nocreate_file", "account", "invite_token", "password"],
6969
[
7070
(False, True, "asdf", "asdfasdmaimfelsgwerw"),
71-
(False, True, "asdf", "z9873240187420913798"),
71+
(False, False, "asdf", "z9873240187420913798"),
7272
(False, True, "", "dsaiujfw9fjiwf9w"),
73-
(True, True, "asdf", "asdfmosadkdkfwdofkw"),
73+
(False, False, "asdf", "z987324018742asdf0913798"),
74+
(True, False, "asdf", "asdfmosadkdkfwdofkw"),
7475
(True, False, "asdf", "z9873240187420913798"),
7576
(True, False, "", "dsaiujfw9fjiwf9w"),
7677
],

0 commit comments

Comments
 (0)