mirror of
https://github.com/simple-login/app.git
synced 2024-11-16 17:08:30 +01:00
35f6e67053
* feat: set up UserAuditLog * refactor: extract payment callbacks into their own files + handle subscription user_audit_log * feat: handle account linking for user audit log * chore: user_audit_log for mailboxes * chore: user_audit_log for custom domains * chore: user_audit_log for contacts * chore: user_audit_log for directories * fix: do not enforce cronjob being defined in choices + enable user deletion * chore: user_audit_log for user deletion * refactor: change emit_user_audit_log function to receive the full user object * feat: add user_audit_log migration * test: fix tests * test: add some tests for user_audit_log * fix: spf record verification user_audit_log * chore: add missing index to user_audit_log.created_at * chore: add missing index to alias_audit_log.created_at
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
from typing import List
|
|
|
|
from app import config, mailbox_utils
|
|
from app.user_audit_log_utils import emit_user_audit_log, UserAuditLogAction
|
|
from app.models import UserAuditLog
|
|
from app.utils import random_string
|
|
from tests.utils import create_new_user, random_email
|
|
|
|
|
|
def setup_module():
|
|
config.SKIP_MX_LOOKUP_ON_CHECK = True
|
|
|
|
|
|
def teardown_module():
|
|
config.SKIP_MX_LOOKUP_ON_CHECK = False
|
|
|
|
|
|
def test_emit_alias_audit_log_for_random_data():
|
|
user = create_new_user()
|
|
|
|
message = random_string()
|
|
action = UserAuditLogAction.CreateMailbox
|
|
emit_user_audit_log(
|
|
user=user,
|
|
action=action,
|
|
message=message,
|
|
commit=True,
|
|
)
|
|
|
|
logs_for_user: List[UserAuditLog] = UserAuditLog.filter_by(user_id=user.id).all()
|
|
assert len(logs_for_user) == 1
|
|
assert logs_for_user[0].user_id == user.id
|
|
assert logs_for_user[0].user_email == user.email
|
|
assert logs_for_user[0].action == action.value
|
|
assert logs_for_user[0].message == message
|
|
|
|
|
|
def test_emit_audit_log_on_mailbox_creation():
|
|
user = create_new_user()
|
|
output = mailbox_utils.create_mailbox(
|
|
user=user, email=random_email(), verified=True
|
|
)
|
|
|
|
logs_for_user: List[UserAuditLog] = UserAuditLog.filter_by(user_id=user.id).all()
|
|
assert len(logs_for_user) == 1
|
|
assert logs_for_user[0].user_id == user.id
|
|
assert logs_for_user[0].user_email == user.email
|
|
assert logs_for_user[0].action == UserAuditLogAction.CreateMailbox.value
|
|
assert (
|
|
logs_for_user[0].message
|
|
== f"Create mailbox {output.mailbox.id} ({output.mailbox.email}). Verified=True"
|
|
)
|