mirror of
https://github.com/chatmail/relay.git
synced 2026-05-10 16:04:37 +00:00
first test for python chatctl part and applying black
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
Chat Mail pyinfra deploy.
|
||||
"""
|
||||
import importlib.resources
|
||||
from io import StringIO
|
||||
|
||||
from pyinfra import host, logger
|
||||
from pyinfra.operations import apt, files, server, systemd, python
|
||||
@@ -118,7 +117,7 @@ def _configure_dovecot(mail_server: str) -> bool:
|
||||
def deploy_chatmail(mail_domain: str, mail_server: str, dkim_selector: str) -> None:
|
||||
"""Deploy a chat-mail instance.
|
||||
|
||||
:param mail_domain: the domain part of your future email addresses, so "example.org" in user@example.org
|
||||
:param mail_domain: domain part of your future email addresses
|
||||
:param mail_server: the DNS name under which your mail server is reachable
|
||||
:param dkim_selector:
|
||||
"""
|
||||
|
||||
@@ -9,17 +9,30 @@ def get_user_data(user):
|
||||
homedir="/home/vmail/link2xt",
|
||||
uid="vmail",
|
||||
gid="vmail",
|
||||
password=b"Ahyei6ie"
|
||||
password=b"Ahyei6ie",
|
||||
)
|
||||
return {}
|
||||
|
||||
|
||||
def create_user(user, password):
|
||||
assert isinstance(password, bytes)
|
||||
return dict(
|
||||
homedir=f"/home/vmail/{user}", uid="vmail", gid="vmail", password=password
|
||||
)
|
||||
|
||||
|
||||
def verify_user(user, password):
|
||||
userdata = get_user_data(user)
|
||||
if userdata.get("password") == password:
|
||||
if userdata:
|
||||
if userdata.get("password") == password:
|
||||
userdata["status"] = "ok"
|
||||
else:
|
||||
userdata["status"] = "fail"
|
||||
else:
|
||||
userdata = create_user(user, password)
|
||||
userdata["status"] = "ok"
|
||||
return userdata
|
||||
return dict(status="fail")
|
||||
|
||||
return userdata
|
||||
|
||||
|
||||
def lookup_user(user):
|
||||
@@ -36,13 +49,13 @@ def dump_result(res):
|
||||
print(f"{key}={value}")
|
||||
|
||||
|
||||
if sys.argv[1] == "hexauth":
|
||||
login = base64.b16decode(sys.argv[2])
|
||||
password = base64.b16decode(sys.argv[3])
|
||||
res = verify_user(login, password)
|
||||
dump_result(res)
|
||||
elif sys.argv[1] == "hexlookup":
|
||||
login = base64.b16decode(sys.argv[2])
|
||||
res = lookup_user(login)
|
||||
dump_result(res)
|
||||
|
||||
if __name__ == "__main__":
|
||||
if sys.argv[1] == "hexauth":
|
||||
login = base64.b16decode(sys.argv[2])
|
||||
password = base64.b16decode(sys.argv[3])
|
||||
res = verify_user(login, password)
|
||||
dump_result(res)
|
||||
elif sys.argv[1] == "hexlookup":
|
||||
login = base64.b16decode(sys.argv[2])
|
||||
res = lookup_user(login)
|
||||
dump_result(res)
|
||||
|
||||
16
src/chatmail/chatctl/test_chatctl.py
Normal file
16
src/chatmail/chatctl/test_chatctl.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import pytest
|
||||
|
||||
from chatctl import get_user_data, verify_user
|
||||
|
||||
|
||||
def test_basic():
|
||||
data = get_user_data(b"link2xt@instant2.testrun.org")
|
||||
assert data
|
||||
|
||||
|
||||
@pytest.mark.xfail(reason="no persistence yet")
|
||||
def test_verify_or_create():
|
||||
res = verify_user(b"newuser1@something.org", b"kajdlkajsldk12l3kj1983")
|
||||
assert res["status"] == "ok"
|
||||
res = verify_user(b"newuser1@something.org", b"kajdlqweqwe")
|
||||
assert res["status"] == "fail"
|
||||
Reference in New Issue
Block a user