python tests work

This commit is contained in:
holger krekel
2023-10-13 14:05:24 +02:00
committed by missytake
parent a907da9907
commit db6df34703
5 changed files with 20 additions and 19 deletions

View File

@@ -15,4 +15,4 @@ def main():
deploy_chatmail(mail_domain, mail_server, dkim_selector)
main()
main()

View File

@@ -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)

View File

@@ -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)

View File

@@ -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")

View File

@@ -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"