tests: replace make_config with example_config, add default config params
This commit is contained in:
parent
74f9e7536b
commit
98fd4b61c9
@ -1,27 +1,31 @@
|
||||
from chatmaild.config import read_config
|
||||
|
||||
|
||||
def test_read_config_basic(make_config):
|
||||
config = make_config("chat.example.org")
|
||||
assert config.mail_domain == "chat.example.org"
|
||||
assert not config.privacy_supervisor and not config.privacy_mail
|
||||
assert not config.privacy_pdo and not config.privacy_postal
|
||||
def test_read_config_basic(example_config):
|
||||
assert example_config.mail_domain == "chat.example.org"
|
||||
assert not example_config.privacy_supervisor and not example_config.privacy_mail
|
||||
assert not example_config.privacy_pdo and not example_config.privacy_postal
|
||||
|
||||
inipath = config._inipath
|
||||
inipath = example_config._inipath
|
||||
inipath.write_text(inipath.read_text().replace("60", "37"))
|
||||
config = read_config(inipath)
|
||||
assert config.max_user_send_per_minute == 37
|
||||
assert config.mail_domain == "chat.example.org"
|
||||
example_config = read_config(inipath)
|
||||
assert example_config.max_user_send_per_minute == 37
|
||||
assert example_config.mail_domain == "chat.example.org"
|
||||
|
||||
|
||||
def test_read_config_testrun(make_config):
|
||||
config = make_config("something.testrun.org")
|
||||
assert config.mail_domain == "something.testrun.org"
|
||||
assert len(config.privacy_postal.split("\n")) > 1
|
||||
assert len(config.privacy_supervisor.split("\n")) > 1
|
||||
assert len(config.privacy_pdo.split("\n")) > 1
|
||||
assert config.privacy_mail == "privacy@testrun.org"
|
||||
assert config.filtermail_smtp_port == 10080
|
||||
assert config.postfix_reinject_port == 10025
|
||||
assert config.max_user_send_per_minute == 60
|
||||
assert config.passthrough_recipients
|
||||
def test_read_config_testrun(example_config):
|
||||
assert example_config.mail_domain == "something.testrun.org"
|
||||
assert len(example_config.privacy_postal.split("\n")) > 1
|
||||
assert len(example_config.privacy_supervisor.split("\n")) > 1
|
||||
assert len(example_config.privacy_pdo.split("\n")) > 1
|
||||
assert example_config.privacy_mail == "privacy@testrun.org"
|
||||
assert example_config.filtermail_smtp_port == 10080
|
||||
assert example_config.postfix_reinject_port == 10025
|
||||
assert example_config.max_user_send_per_minute == 60
|
||||
assert example_config.max_mailbox_size == "100M"
|
||||
assert example_config.delete_mails_after == "40d"
|
||||
assert example_config.username_min_length == 6
|
||||
assert example_config.username_max_length == 20
|
||||
assert example_config.password_min_length == 9
|
||||
assert example_config.passthrough_senders
|
||||
assert example_config.passthrough_recipients
|
||||
|
@ -9,32 +9,37 @@ from chatmaild.doveauth import get_user_data, lookup_passdb, handle_dovecot_requ
|
||||
from chatmaild.database import DBError
|
||||
|
||||
|
||||
def test_basic(db, make_config):
|
||||
config = make_config("c1.testrun.org")
|
||||
lookup_passdb(db, config, "link2xt@c1.testrun.org", "Pieg9aeToe3eghuthe5u")
|
||||
data = get_user_data(db, "link2xt@c1.testrun.org")
|
||||
def test_basic(db, example_config):
|
||||
lookup_passdb(
|
||||
db, example_config, "link2xt@chat.example.org", "Pieg9aeToe3eghuthe5u"
|
||||
)
|
||||
data = get_user_data(db, "link2xt@chat.example.org")
|
||||
assert data
|
||||
data2 = lookup_passdb(db, config, "link2xt@c1.testrun.org", "Pieg9aeToe3eghuthe5u")
|
||||
data2 = lookup_passdb(
|
||||
db, example_config, "link2xt@chat.example.org", "Pieg9aeToe3eghuthe5u"
|
||||
)
|
||||
assert data == data2
|
||||
|
||||
|
||||
def test_dont_overwrite_password_on_wrong_login(db, make_config):
|
||||
def test_dont_overwrite_password_on_wrong_login(db, example_config):
|
||||
"""Test that logging in with a different password doesn't create a new user"""
|
||||
config = make_config("something.org")
|
||||
res = lookup_passdb(db, config, "newuser1@something.org", "kajdlkajsldk12l3kj1983")
|
||||
res = lookup_passdb(
|
||||
db, example_config, "newuser1@chat.example.org", "kajdlkajsldk12l3kj1983"
|
||||
)
|
||||
assert res["password"]
|
||||
res2 = lookup_passdb(db, config, "newuser1@something.org", "kajdlqweqwe")
|
||||
res2 = lookup_passdb(db, example_config, "newuser1@chat.example.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, monkeypatch, tmpdir, make_config):
|
||||
config = make_config("something.org")
|
||||
def test_nocreate_file(db, monkeypatch, tmpdir, example_config):
|
||||
p = tmpdir.join("nocreate")
|
||||
p.write("")
|
||||
monkeypatch.setattr(chatmaild.doveauth, "NOCREATE_FILE", str(p))
|
||||
lookup_passdb(db, config, "newuser1@something.org", "zequ0Aimuchoodaechik")
|
||||
assert not get_user_data(db, "newuser1@something.org")
|
||||
lookup_passdb(
|
||||
db, example_config, "newuser1@chat.example.org", "zequ0Aimuchoodaechik"
|
||||
)
|
||||
assert not get_user_data(db, "newuser1@chat.example.org")
|
||||
|
||||
|
||||
def test_db_version(db):
|
||||
@ -48,34 +53,32 @@ def test_too_high_db_version(db):
|
||||
db.ensure_tables()
|
||||
|
||||
|
||||
def test_handle_dovecot_request(db, make_config):
|
||||
config = make_config("c3.testrun.org")
|
||||
def test_handle_dovecot_request(db, example_config):
|
||||
msg = (
|
||||
"Lshared/passdb/laksjdlaksjdlaksjdlk12j3l1k2j3123/"
|
||||
"some42@c3.testrun.org\tsome42@c3.testrun.org"
|
||||
"some42@chat.example.org\tsome42@chat.example.org"
|
||||
)
|
||||
res = handle_dovecot_request(msg, db, config)
|
||||
res = handle_dovecot_request(msg, db, example_config)
|
||||
assert res
|
||||
assert res[0] == "O" and res.endswith("\n")
|
||||
userdata = json.loads(res[1:].strip())
|
||||
assert userdata["home"] == "/home/vmail/some42@c3.testrun.org"
|
||||
assert userdata["home"] == "/home/vmail/some42@chat.example.org"
|
||||
assert userdata["uid"] == userdata["gid"] == "vmail"
|
||||
assert userdata["password"].startswith("{SHA512-CRYPT}")
|
||||
|
||||
|
||||
def test_50_concurrent_lookups_different_accounts(
|
||||
db, gencreds, make_config, maildomain
|
||||
db, gencreds, example_config, maildomain
|
||||
):
|
||||
num_threads = 50
|
||||
req_per_thread = 5
|
||||
results = queue.Queue()
|
||||
config = make_config(maildomain)
|
||||
|
||||
def lookup(db):
|
||||
for i in range(req_per_thread):
|
||||
addr, password = gencreds()
|
||||
try:
|
||||
lookup_passdb(db, config, addr, password)
|
||||
lookup_passdb(db, example_config, addr, password)
|
||||
except Exception:
|
||||
results.put(traceback.format_exc())
|
||||
else:
|
||||
|
@ -4,26 +4,24 @@ import chatmaild
|
||||
from chatmaild.newemail import create_newemail_dict, print_new_account
|
||||
|
||||
|
||||
def test_create_newemail_dict(make_config):
|
||||
config = make_config("example.org")
|
||||
ac1 = create_newemail_dict(config)
|
||||
def test_create_newemail_dict(example_config):
|
||||
ac1 = create_newemail_dict(example_config)
|
||||
assert "@" in ac1["email"]
|
||||
assert len(ac1["password"]) >= 10
|
||||
|
||||
ac2 = create_newemail_dict(config)
|
||||
ac2 = create_newemail_dict(example_config)
|
||||
|
||||
assert ac1["email"] != ac2["email"]
|
||||
assert ac1["password"] != ac2["password"]
|
||||
|
||||
|
||||
def test_print_new_account(capsys, monkeypatch, maildomain, tmpdir, make_config):
|
||||
config = make_config(maildomain)
|
||||
monkeypatch.setattr(chatmaild.newemail, "CONFIG_PATH", str(config._inipath))
|
||||
def test_print_new_account(capsys, monkeypatch, maildomain, tmpdir, example_config):
|
||||
monkeypatch.setattr(chatmaild.newemail, "CONFIG_PATH", str(example_config._inipath))
|
||||
print_new_account()
|
||||
out, err = capsys.readouterr()
|
||||
lines = out.split("\n")
|
||||
assert lines[0] == "Content-Type: application/json"
|
||||
assert not lines[1]
|
||||
dic = json.loads(lines[2])
|
||||
assert dic["email"].endswith(f"@{config.mail_domain}")
|
||||
assert dic["email"].endswith(f"@{example_config.mail_domain}")
|
||||
assert len(dic["password"]) >= 10
|
||||
|
Loading…
Reference in New Issue
Block a user