tests: adjust to dictproxy, test /tmp/nocreate

This commit is contained in:
missytake 2023-10-17 19:16:06 +02:00
parent 040b7a74a6
commit 75e7c85e61

View File

@ -1,7 +1,8 @@
import os
import pytest import pytest
from .dictproxy import get_user_data from .dictproxy import get_user_data, lookup_passdb
from .doveauth import verify_user
from .database import Database, DBError from .database import Database, DBError
@ -13,16 +14,29 @@ def db(tmpdir):
def test_basic(db): def test_basic(db):
verify_user(db, "link2xt@c1.testrun.org", "asdf") if os.path.exists("/tmp/nocreate"):
os.remove("/tmp/nocreate")
lookup_passdb(db, "link2xt@c1.testrun.org", "asdf")
data = get_user_data(db, "link2xt@c1.testrun.org") data = get_user_data(db, "link2xt@c1.testrun.org")
assert data assert data
def test_verify_or_create(db): def test_dont_overwrite_password_on_wrong_login(db):
res = verify_user(db, "newuser1@something.org", "kajdlkajsldk12l3kj1983") """Test that logging in with a different password doesn't create a new user"""
assert res["status"] == "ok" res = lookup_passdb(db, "newuser1@something.org", "kajdlkajsldk12l3kj1983")
res = verify_user(db, "newuser1@something.org", "kajdlqweqwe") assert res["password"]
assert res["status"] == "fail" res2 = lookup_passdb(db, "newuser1@something.org", "kajdlqweqwe")
# this function always returns a password hash, which is actually compared by dovecot.
assert res["password"] == res2["password"]
def test_nocreate_file(db):
with open("/tmp/nocreate", "w+") as f:
f.write("")
assert os.path.exists("/tmp/nocreate")
lookup_passdb(db, "newuser1@something.org", "kajdlqweqwe")
assert not get_user_data(db, "newuser1@something.org")
os.remove("/tmp/nocreate")
def test_db_version(db): def test_db_version(db):