Skip to content

Commit e3d53b1

Browse files
committed
tests: ensure valid invite token in password overrides nocreate file
1 parent 3fd11a4 commit e3d53b1

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

chatmaild/src/chatmaild/doveauth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ 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 config.invite_token and config.invite_token not in cleartext_password:
27+
if not config.invite_token or config.invite_token not in cleartext_password:
2828
logging.warning(
2929
f"blocked account creation because {NOCREATE_FILE!r} exists."
3030
)

chatmaild/src/chatmaild/tests/test_doveauth.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,34 @@ def test_dont_overwrite_password_on_wrong_login(dictproxy):
6464
assert res["password"] == res2["password"]
6565

6666

67-
def test_nocreate_file(monkeypatch, tmpdir, dictproxy):
68-
p = tmpdir.join("nocreate")
69-
p.write("")
70-
monkeypatch.setattr(chatmaild.doveauth, "NOCREATE_FILE", str(p))
71-
dictproxy.lookup_passdb("[email protected]", "zequ0Aimuchoodaechik")
72-
assert not dictproxy.lookup_userdb("[email protected]")
67+
@pytest.mark.parametrize(
68+
["nocreate_file", "account", "invite_token", "password"],
69+
[
70+
(False, True, "asdf", "asdfasdmaimfelsgwerw"),
71+
(False, True, "asdf", "z9873240187420913798"),
72+
(False, True, "", "dsaiujfw9fjiwf9w"),
73+
(True, True, "asdf", 'asdfmosadkdkfwdofkw'),
74+
(True, False, "asdf", "z9873240187420913798"),
75+
(True, False, "", "dsaiujfw9fjiwf9w"),
76+
],
77+
)
78+
def test_nocreate_file(
79+
monkeypatch,
80+
tmpdir,
81+
dictproxy,
82+
example_config,
83+
nocreate_file: bool,
84+
account: bool,
85+
invite_token: str,
86+
password: str,
87+
):
88+
if nocreate_file:
89+
p = tmpdir.join("nocreate")
90+
p.write("")
91+
monkeypatch.setattr(chatmaild.doveauth, "NOCREATE_FILE", str(p))
92+
example_config.invite_token = invite_token
93+
dictproxy.lookup_passdb("[email protected]", password)
94+
assert bool(dictproxy.lookup_userdb("[email protected]")) == account
7395

7496

7597
def test_handle_dovecot_request(dictproxy):

0 commit comments

Comments
 (0)