mirror of
https://github.com/chatmail/relay.git
synced 2026-05-20 12:58:04 +00:00
first test for python chatctl part and applying black
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
Chat Mail pyinfra deploy.
|
Chat Mail pyinfra deploy.
|
||||||
"""
|
"""
|
||||||
import importlib.resources
|
import importlib.resources
|
||||||
from io import StringIO
|
|
||||||
|
|
||||||
from pyinfra import host, logger
|
from pyinfra import host, logger
|
||||||
from pyinfra.operations import apt, files, server, systemd, python
|
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:
|
def deploy_chatmail(mail_domain: str, mail_server: str, dkim_selector: str) -> None:
|
||||||
"""Deploy a chat-mail instance.
|
"""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 mail_server: the DNS name under which your mail server is reachable
|
||||||
:param dkim_selector:
|
:param dkim_selector:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -9,17 +9,30 @@ def get_user_data(user):
|
|||||||
homedir="/home/vmail/link2xt",
|
homedir="/home/vmail/link2xt",
|
||||||
uid="vmail",
|
uid="vmail",
|
||||||
gid="vmail",
|
gid="vmail",
|
||||||
password=b"Ahyei6ie"
|
password=b"Ahyei6ie",
|
||||||
)
|
)
|
||||||
return {}
|
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):
|
def verify_user(user, password):
|
||||||
userdata = get_user_data(user)
|
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"
|
userdata["status"] = "ok"
|
||||||
return userdata
|
|
||||||
return dict(status="fail")
|
return userdata
|
||||||
|
|
||||||
|
|
||||||
def lookup_user(user):
|
def lookup_user(user):
|
||||||
@@ -36,13 +49,13 @@ def dump_result(res):
|
|||||||
print(f"{key}={value}")
|
print(f"{key}={value}")
|
||||||
|
|
||||||
|
|
||||||
if sys.argv[1] == "hexauth":
|
if __name__ == "__main__":
|
||||||
login = base64.b16decode(sys.argv[2])
|
if sys.argv[1] == "hexauth":
|
||||||
password = base64.b16decode(sys.argv[3])
|
login = base64.b16decode(sys.argv[2])
|
||||||
res = verify_user(login, password)
|
password = base64.b16decode(sys.argv[3])
|
||||||
dump_result(res)
|
res = verify_user(login, password)
|
||||||
elif sys.argv[1] == "hexlookup":
|
dump_result(res)
|
||||||
login = base64.b16decode(sys.argv[2])
|
elif sys.argv[1] == "hexlookup":
|
||||||
res = lookup_user(login)
|
login = base64.b16decode(sys.argv[2])
|
||||||
dump_result(res)
|
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