mirror of
https://github.com/chatmail/relay.git
synced 2026-05-17 01:48:58 +00:00
refactor password/login-timestamp handling into a User object
This commit is contained in:
@@ -2,28 +2,17 @@ import time
|
||||
|
||||
from chatmaild.delete_inactive_users import delete_inactive_users
|
||||
from chatmaild.doveauth import AuthDictProxy
|
||||
from chatmaild.lastlogin import get_last_login_from_userdir, write_last_login_to_userdir
|
||||
|
||||
|
||||
def test_login_timestamps(tmp_path):
|
||||
userdir = tmp_path.joinpath("someuser@chat.example.org")
|
||||
userdir.mkdir()
|
||||
userdir.joinpath("password").touch()
|
||||
write_last_login_to_userdir(userdir, timestamp=100000)
|
||||
assert get_last_login_from_userdir(userdir) == 86400
|
||||
def test_login_timestamps(example_config):
|
||||
testaddr = "someuser@chat.example.org"
|
||||
user = example_config.get_user(testaddr)
|
||||
|
||||
write_last_login_to_userdir(userdir, timestamp=200000)
|
||||
assert get_last_login_from_userdir(userdir) == 86400 * 2
|
||||
|
||||
write_last_login_to_userdir(userdir, timestamp=200000)
|
||||
assert get_last_login_from_userdir(userdir) == 86400 * 2
|
||||
|
||||
|
||||
def test_delete_skips_non_email_dir(example_config):
|
||||
userdir = example_config.get_user_maildir("something")
|
||||
userdir.mkdir()
|
||||
get_last_login_from_userdir(userdir)
|
||||
assert not list(userdir.iterdir())
|
||||
# password file needs to be set because it's mtime tracks last-login time
|
||||
user.set_password("1l2k3j1l2k3j123")
|
||||
for i in range(10):
|
||||
user.set_last_login_timestamp(86400 * 4 + i)
|
||||
assert user.get_last_login_timestamp() == 86400 * 4
|
||||
|
||||
|
||||
def test_delete_inactive_users(example_config):
|
||||
@@ -33,10 +22,10 @@ def test_delete_inactive_users(example_config):
|
||||
|
||||
def create_user(addr, last_login):
|
||||
dictproxy.lookup_passdb(addr, "q9mr3faue")
|
||||
md = example_config.get_user_maildir(addr)
|
||||
md.joinpath("cur").mkdir()
|
||||
md.joinpath("cur", "something").mkdir()
|
||||
write_last_login_to_userdir(md, timestamp=last_login)
|
||||
user = example_config.get_user(addr)
|
||||
user.maildir.joinpath("cur").mkdir()
|
||||
user.maildir.joinpath("cur", "something").mkdir()
|
||||
user.set_last_login_timestamp(timestamp=last_login)
|
||||
|
||||
# create some stale and some new accounts
|
||||
to_remove = []
|
||||
@@ -54,7 +43,7 @@ def test_delete_inactive_users(example_config):
|
||||
# check pre and post-conditions for delete_inactive_users()
|
||||
|
||||
for addr in to_remove:
|
||||
assert example_config.get_user_maildir(addr).exists()
|
||||
assert example_config.get_user(addr).maildir.exists()
|
||||
|
||||
delete_inactive_users(example_config)
|
||||
|
||||
@@ -62,9 +51,9 @@ def test_delete_inactive_users(example_config):
|
||||
assert not p.name.startswith("old")
|
||||
|
||||
for addr in to_remove:
|
||||
assert not example_config.get_user_maildir(addr).exists()
|
||||
assert not example_config.get_user(addr).maildir.exists()
|
||||
|
||||
for addr in remain:
|
||||
userdir = example_config.get_user_maildir(addr)
|
||||
userdir = example_config.get_user(addr).maildir
|
||||
assert userdir.exists()
|
||||
assert userdir.joinpath("password").read_text()
|
||||
|
||||
Reference in New Issue
Block a user