From db6df347039f63c503be67599b3d2aef4add8935 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Fri, 13 Oct 2023 14:05:24 +0200 Subject: [PATCH] python tests work --- deploy.py | 2 +- src/chatmail/dovecot/doveauth.lua | 4 +++- src/chatmail/dovecot/doveauth.py | 15 ++++++--------- src/chatmail/dovecot/test_doveauth.lua | 12 +++++++----- src/chatmail/dovecot/test_doveauth.py | 6 +++--- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/deploy.py b/deploy.py index 452fcad3..402b2a27 100644 --- a/deploy.py +++ b/deploy.py @@ -15,4 +15,4 @@ def main(): deploy_chatmail(mail_domain, mail_server, dkim_selector) -main() \ No newline at end of file +main() diff --git a/src/chatmail/dovecot/doveauth.lua b/src/chatmail/dovecot/doveauth.lua index fd019ee4..f2f0df94 100644 --- a/src/chatmail/dovecot/doveauth.lua +++ b/src/chatmail/dovecot/doveauth.lua @@ -8,7 +8,9 @@ end -- call out to python program to actually manage authentication for dovecot function chatctl_verify(user, password) - local handle = io.popen("python3 /home/vmail/chatctl hexauth "..escape(user).." "..escape(password)) + local cmd = "python3 /home/vmail/chatctl hexauth "..escape(user).." "..escape(password) + print("executing: "..cmd) + local handle = io.popen(cmd) local result = handle:read("*a") handle:close() return split_chatctl(result) diff --git a/src/chatmail/dovecot/doveauth.py b/src/chatmail/dovecot/doveauth.py index 9c361b2e..9741f2fa 100644 --- a/src/chatmail/dovecot/doveauth.py +++ b/src/chatmail/dovecot/doveauth.py @@ -4,20 +4,17 @@ import sys def get_user_data(user): - if user == b"link2xt@c1.testrun.org": + if user == "link2xt@c1.testrun.org": return dict( uid="vmail", gid="vmail", - password=b"Ahyei6ie", + password="Ahyei6ie", ) return {} def create_user(user, password): - assert isinstance(password, bytes) - return dict( - home=f"/home/vmail/{user}", uid="vmail", gid="vmail", password=password - ) + return dict(home=f"/home/vmail/{user}", uid="vmail", gid="vmail", password=password) def verify_user(user, password): @@ -50,11 +47,11 @@ def dump_result(res): if __name__ == "__main__": if sys.argv[1] == "hexauth": - login = base64.b16decode(sys.argv[2]) - password = base64.b16decode(sys.argv[3]) + login = base64.b16decode(sys.argv[2]).decode() + password = base64.b16decode(sys.argv[3]).decode() res = verify_user(login, password) dump_result(res) elif sys.argv[1] == "hexlookup": - login = base64.b16decode(sys.argv[2]) + login = base64.b16decode(sys.argv[2]).decode() res = lookup_user(login) dump_result(res) diff --git a/src/chatmail/dovecot/test_doveauth.lua b/src/chatmail/dovecot/test_doveauth.lua index 1b0b4da7..aeec88ef 100644 --- a/src/chatmail/dovecot/test_doveauth.lua +++ b/src/chatmail/dovecot/test_doveauth.lua @@ -67,10 +67,12 @@ function test_split_chatctl() end test_split_chatctl() -test_password_verify_ok("link2xt@instant2.testrun.org", "Ahyei6ie") -test_password_verify_mismatch("link2xt@instant2.testrun.org", "Aqwlek") -test_userdb_lookup_ok("link2xt@instant2.testrun.org") +test_password_verify_ok("link2xt@c1.testrun.org", "Ahyei6ie") +test_password_verify_mismatch("link2xt@c1.testrun.org", "Aqwlek") +test_userdb_lookup_ok("link2xt@c1.testrun.org") test_userdb_lookup_mismatch("wlekqjlew@xyz.org") -test_passdb_lookup_ok("link2xt@instant2.testrun.org") -test_passdb_lookup_mismatch("llqkwjelqwe@xyz.org") + +-- probably not needed by dovecot? +-- test_passdb_lookup_ok("link2xt@c1.testrun.org") +-- test_passdb_lookup_mismatch("llqkwjelqwe@xyz.org") diff --git a/src/chatmail/dovecot/test_doveauth.py b/src/chatmail/dovecot/test_doveauth.py index f9cfdacd..cfd2cb33 100644 --- a/src/chatmail/dovecot/test_doveauth.py +++ b/src/chatmail/dovecot/test_doveauth.py @@ -5,15 +5,15 @@ from doveauth import get_user_data, verify_user def test_basic(): - data = get_user_data(b"link2xt@instant2.testrun.org") + data = get_user_data("link2xt@c1.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") + res = verify_user("newuser1@something.org", "kajdlkajsldk12l3kj1983") assert res["status"] == "ok" - res = verify_user(b"newuser1@something.org", b"kajdlqweqwe") + res = verify_user("newuser1@something.org", "kajdlqweqwe") assert res["status"] == "fail"