-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(email): add tests for email character escaping
- Loading branch information
Taylor Osler
authored and
Taylor Osler
committed
Aug 21, 2024
1 parent
9edbb44
commit c057bf4
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import functools | ||
import os | ||
from copy import deepcopy | ||
from unittest.mock import patch | ||
|
||
from django.conf import settings | ||
from django.core import mail | ||
from django.core.mail.message import EmailMultiAlternatives | ||
from django.test import override_settings | ||
|
||
from sentry import options | ||
from sentry.models.groupemailthread import GroupEmailThread | ||
|
@@ -18,6 +22,14 @@ | |
|
||
|
||
class MessageBuilderTest(TestCase): | ||
def _override_templates(self): | ||
templates = deepcopy(settings.TEMPLATES) | ||
for template in templates: | ||
template["DIRS"] = [os.path.abspath(os.path.dirname(__file__)) + "/testdata/templates"] | ||
template["APP_DIRS"] = False | ||
|
||
return override_settings(TEMPLATES=templates) | ||
|
||
def test_raw_content(self): | ||
msg = MessageBuilder( | ||
subject="Test", | ||
|
@@ -333,3 +345,16 @@ def test_adds_type_to_headers(self): | |
|
||
json_xsmtpapi_data = json.loads(out.extra_headers["X-SMTPAPI"]) | ||
assert json_xsmtpapi_data["category"] == "test_email.type" | ||
|
||
def test_doesnt_escape_plaintext(self): | ||
context = {"name": "Bob's Hardware & Paint <LTD>"} | ||
with self._override_templates(): | ||
msg = MessageBuilder( | ||
subject="Congratulations! You won!", | ||
template="escaping_plaintext_test.txt", | ||
context=context, | ||
) | ||
msg.send(["[email protected]"]) | ||
|
||
assert len(mail.outbox) == 1 | ||
assert context["name"] in mail.outbox[0].body |
1 change: 1 addition & 0 deletions
1
tests/sentry/utils/email/testdata/templates/escaping_plaintext_test.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
You're our winner, {{ name }}! Congratulations! |