mirror of
https://github.com/chatmail/relay.git
synced 2026-05-19 20:38:05 +00:00
tests: ensure valid invite token in password overrides nocreate file
This commit is contained in:
@@ -24,7 +24,7 @@ def encrypt_password(password: str):
|
|||||||
def is_allowed_to_create(config: Config, user, cleartext_password) -> bool:
|
def is_allowed_to_create(config: Config, user, cleartext_password) -> bool:
|
||||||
"""Return True if user and password are admissable."""
|
"""Return True if user and password are admissable."""
|
||||||
if os.path.exists(NOCREATE_FILE):
|
if os.path.exists(NOCREATE_FILE):
|
||||||
if config.invite_token and config.invite_token not in cleartext_password:
|
if not config.invite_token or config.invite_token not in cleartext_password:
|
||||||
logging.warning(
|
logging.warning(
|
||||||
f"blocked account creation because {NOCREATE_FILE!r} exists."
|
f"blocked account creation because {NOCREATE_FILE!r} exists."
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -64,12 +64,34 @@ def test_dont_overwrite_password_on_wrong_login(dictproxy):
|
|||||||
assert res["password"] == res2["password"]
|
assert res["password"] == res2["password"]
|
||||||
|
|
||||||
|
|
||||||
def test_nocreate_file(monkeypatch, tmpdir, dictproxy):
|
@pytest.mark.parametrize(
|
||||||
p = tmpdir.join("nocreate")
|
["nocreate_file", "account", "invite_token", "password"],
|
||||||
p.write("")
|
[
|
||||||
monkeypatch.setattr(chatmaild.doveauth, "NOCREATE_FILE", str(p))
|
(False, True, "asdf", "asdfasdmaimfelsgwerw"),
|
||||||
dictproxy.lookup_passdb("newuser12@chat.example.org", "zequ0Aimuchoodaechik")
|
(False, True, "asdf", "z9873240187420913798"),
|
||||||
assert not dictproxy.lookup_userdb("newuser12@chat.example.org")
|
(False, True, "", "dsaiujfw9fjiwf9w"),
|
||||||
|
(True, True, "asdf", "asdfmosadkdkfwdofkw"),
|
||||||
|
(True, False, "asdf", "z9873240187420913798"),
|
||||||
|
(True, False, "", "dsaiujfw9fjiwf9w"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_nocreate_file(
|
||||||
|
monkeypatch,
|
||||||
|
tmpdir,
|
||||||
|
dictproxy,
|
||||||
|
example_config,
|
||||||
|
nocreate_file: bool,
|
||||||
|
account: bool,
|
||||||
|
invite_token: str,
|
||||||
|
password: str,
|
||||||
|
):
|
||||||
|
if nocreate_file:
|
||||||
|
p = tmpdir.join("nocreate")
|
||||||
|
p.write("")
|
||||||
|
monkeypatch.setattr(chatmaild.doveauth, "NOCREATE_FILE", str(p))
|
||||||
|
example_config.invite_token = invite_token
|
||||||
|
dictproxy.lookup_passdb("newuser12@chat.example.org", password)
|
||||||
|
assert bool(dictproxy.lookup_userdb("newuser12@chat.example.org")) == account
|
||||||
|
|
||||||
|
|
||||||
def test_handle_dovecot_request(dictproxy):
|
def test_handle_dovecot_request(dictproxy):
|
||||||
|
|||||||
Reference in New Issue
Block a user