mirror of
https://github.com/simple-login/app.git
synced 2025-02-23 07:13:18 +08:00
add more test. Make sure to delete To header before changing.
This commit is contained in:
parent
becde6458b
commit
01fd880902
2 changed files with 33 additions and 4 deletions
|
@ -406,9 +406,9 @@ def add_alias_to_header_if_needed(msg, alias):
|
||||||
LOG.d(f"add {alias} to To: header {to_header}")
|
LOG.d(f"add {alias} to To: header {to_header}")
|
||||||
|
|
||||||
if to_header:
|
if to_header:
|
||||||
msg[headers.TO] = f"{to_header},{alias.email}"
|
add_or_replace_header(msg, headers.TO, f"{to_header},{alias.email}")
|
||||||
else:
|
else:
|
||||||
msg[headers.TO] = alias.email
|
add_or_replace_header(msg, headers.TO, alias.email)
|
||||||
|
|
||||||
|
|
||||||
def replace_header_when_reply(msg: Message, alias: Alias, header: str):
|
def replace_header_when_reply(msg: Message, alias: Alias, header: str):
|
||||||
|
|
|
@ -191,11 +191,40 @@ def test_dmarc_reply_quarantine(flask_client, dmarc_result):
|
||||||
|
|
||||||
def test_add_alias_to_header_if_needed():
|
def test_add_alias_to_header_if_needed():
|
||||||
msg = EmailMessage()
|
msg = EmailMessage()
|
||||||
create_new_user()
|
user = create_new_user()
|
||||||
alias = Alias.first()
|
alias = Alias.filter_by(user_id=user.id).first()
|
||||||
|
|
||||||
assert msg[headers.TO] is None
|
assert msg[headers.TO] is None
|
||||||
|
|
||||||
email_handler.add_alias_to_header_if_needed(msg, alias)
|
email_handler.add_alias_to_header_if_needed(msg, alias)
|
||||||
|
|
||||||
assert msg[headers.TO] == alias.email
|
assert msg[headers.TO] == alias.email
|
||||||
|
|
||||||
|
|
||||||
|
def test_append_alias_to_header_if_needed_existing_to():
|
||||||
|
msg = EmailMessage()
|
||||||
|
original_to = "noone@nowhere.no"
|
||||||
|
msg[headers.TO] = original_to
|
||||||
|
user = create_new_user()
|
||||||
|
alias = Alias.filter_by(user_id=user.id).first()
|
||||||
|
email_handler.add_alias_to_header_if_needed(msg, alias)
|
||||||
|
assert msg[headers.TO] == f"{original_to}, {alias.email}"
|
||||||
|
|
||||||
|
|
||||||
|
def test_avoid_add_to_header_already_present():
|
||||||
|
msg = EmailMessage()
|
||||||
|
user = create_new_user()
|
||||||
|
alias = Alias.filter_by(user_id=user.id).first()
|
||||||
|
msg[headers.TO] = alias.email
|
||||||
|
email_handler.add_alias_to_header_if_needed(msg, alias)
|
||||||
|
assert msg[headers.TO] == alias.email
|
||||||
|
|
||||||
|
|
||||||
|
def test_avoid_add_to_header_already_present_in_cc():
|
||||||
|
msg = EmailMessage()
|
||||||
|
create_new_user()
|
||||||
|
alias = Alias.first()
|
||||||
|
msg[headers.CC] = alias.email
|
||||||
|
email_handler.add_alias_to_header_if_needed(msg, alias)
|
||||||
|
assert msg[headers.TO] is None
|
||||||
|
assert msg[headers.CC] == alias.email
|
||||||
|
|
Loading…
Reference in a new issue