Commit aeb030f8 authored by Lars Kruse's avatar Lars Kruse
Browse files

feat(settings): use configured site domain for undefined email addresses

Previously "localhost" was used as the default email domain.
Now the configured site domain is used instead.
parent af0b7100
Pipeline #3163 failed with stages
in 3 minutes and 56 seconds
......@@ -3,6 +3,7 @@ import functools
import os
from django.conf import settings
from django.contrib.sites.models import Site
from django.templatetags.static import static
......@@ -72,6 +73,10 @@ class LazySettingsResolver:
setattr(self, key, value)
def _get_domain():
return Site.objects.get_current().domain
CORE_SETTINGS = LazySettingsResolver(
# branding
CLAIMS=_GR.get("CLAIMS", []),
......@@ -85,13 +90,13 @@ CORE_SETTINGS = LazySettingsResolver(
# mail handling
COLLECTOR_MAILBOX_ADDRESS=_GR.get("COLLECTOR_MAILBOX_ADDRESS", None),
DEFAULT_DISTINCT_FROM_EMAIL=_GR.get(
"DEFAULT_DISTINCT_FROM_EMAIL", "noreply+{slug}@localhost"
"DEFAULT_DISTINCT_FROM_EMAIL", lambda: "noreply+{slug}@" + _get_domain()
),
DEFAULT_REPLY_TO_EMAIL=_GR.get(
"DEFAULT_REPLY_TO_EMAIL", "reply+{reply_key}@localhost"
"DEFAULT_REPLY_TO_EMAIL", lambda: "reply+{reply_key}@" + _get_domain()
),
MAILINGLIST_ENABLED=_GR.get("MAILINGLIST_ENABLED", False),
POSTMASTER_EMAIL=_GR.get("POSTMASTER_EMAIL", "postmaster@localhost"),
POSTMASTER_EMAIL=_GR.get("POSTMASTER_EMAIL", lambda: "postmaster@" + _get_domain()),
# content import
FEED_IMPORTER_GESTALT_ID=_GR.get("FEED_IMPORTER_GESTALT_ID", None),
OPERATOR_GROUP_ID=_GR.get("OPERATOR_GROUP_ID", 1),
......
......@@ -7,6 +7,7 @@ import os
import re
from aiosmtplib.errors import SMTPDataError
from django.contrib.sites.models import Site
from django.core import mail
from django.urls import reverse
......@@ -21,6 +22,10 @@ from grouprise.features.gestalten import tests as gestalten
from grouprise.features.memberships import test_mixins as memberships
def get_full_address(local):
return local + "@" + Site.objects.get_current()
class MailInjectLMTPMixin:
def assertIsProcessingFailureReply(self, message):
......@@ -104,13 +109,15 @@ class ContentViaLMTP(MailInjectLMTPMixin, tests.Test):
# Mails with a wrong target domain should never reach us. They are probably caused by a
# configuration error of the local mail server.
with self.fresh_outbox_mails_retriever() as get_new_mails:
rejections = self.inject_mail('foo@localhost', ['foo@example.org'], data=b'foo')
rejections = self.inject_mail(
get_full_address('foo'), ['foo@example.org'], data=b'foo')
self.assertEqual(1, len(rejections))
self.assertEqual(0, len(get_new_mails()))
def test_reject_non_existing_target_group(self):
with self.fresh_outbox_mails_retriever() as get_new_mails:
rejections = self.inject_mail('foo@localhost', ['foo@localhost'], data=b'foo')
rejections = self.inject_mail(
get_full_address('foo'), [get_full_address('foo')], data=b'foo')
self.assertEqual(1, len(rejections))
self.assertEqual(0, len(get_new_mails()))
......@@ -119,7 +126,7 @@ class GroupMailMixin(memberships.MemberMixin):
@property
def group_address(self):
return '{}@localhost'.format(self.group.slug)
return get_full_address(self.group.slug)
class GroupContentViaLMTP(GroupMailMixin, MailInjectLMTPMixin, tests.Test):
......@@ -179,7 +186,7 @@ class GroupContentViaLMTP(GroupMailMixin, MailInjectLMTPMixin, tests.Test):
('precedence', '', False),
('X-AUTORESPONDER', 'foo', True)):
with self.fresh_outbox_mails_retriever() as get_new_mails:
self.inject_mail('foo@localhost', [self.group_address],
self.inject_mail(get_full_address('foo'), [self.group_address],
data=self.assemble_mail_data({header_key: header_value}))
self.assertEqual(is_ignored, len(get_new_mails()) == 0,
(header_key, header_value))
......@@ -316,7 +323,7 @@ class ConversationInitiateByEmailViaLMTP(GroupMailMixin, MailInjectLMTPMixin, te
def test_conversation_initiate_by_email_failing(self):
with self.fresh_outbox_mails_retriever() as get_new_mails:
rejections = self.inject_mail(
self.gestalt.user.email, ['not-existing@localhost'],
self.gestalt.user.email, [get_full_address('not-existing')],
data=self.assemble_mail_data({}, body='Text C'))
self.assertEqual(1, len(rejections))
self.assertEqual(0, len(get_new_mails()))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment