summaryrefslogtreecommitdiff
path: root/src/mailman/mta/tests
diff options
context:
space:
mode:
authorAbhilash Raj2017-05-23 18:23:32 +0000
committerBarry Warsaw2017-05-23 18:23:32 +0000
commit30a21e0aacd4fcf755816e31b031aec81f83c98e (patch)
treed650c8dc5c24e8a2b13754d196beac891d543fd4 /src/mailman/mta/tests
parenta7c563e9048d302c52558e6e2202fdfb49961843 (diff)
downloadmailman-30a21e0aacd4fcf755816e31b031aec81f83c98e.tar.gz
mailman-30a21e0aacd4fcf755816e31b031aec81f83c98e.tar.zst
mailman-30a21e0aacd4fcf755816e31b031aec81f83c98e.zip
Add support for regex based postfix transport maps and relay_domains.
Diffstat (limited to 'src/mailman/mta/tests')
-rw-r--r--src/mailman/mta/tests/test_aliases.py168
1 files changed, 123 insertions, 45 deletions
diff --git a/src/mailman/mta/tests/test_aliases.py b/src/mailman/mta/tests/test_aliases.py
index d5cea3ecb..b8090c86d 100644
--- a/src/mailman/mta/tests/test_aliases.py
+++ b/src/mailman/mta/tests/test_aliases.py
@@ -154,15 +154,15 @@ example.com example.com
contents = _strip_header(fp.read())
self.assertMultiLineEqual(contents, """\
# Aliases which are visible only in the @example.com domain.
-test@example.com lmtp:[127.0.0.1]:9024
-test-bounces@example.com lmtp:[127.0.0.1]:9024
-test-confirm@example.com lmtp:[127.0.0.1]:9024
-test-join@example.com lmtp:[127.0.0.1]:9024
-test-leave@example.com lmtp:[127.0.0.1]:9024
-test-owner@example.com lmtp:[127.0.0.1]:9024
-test-request@example.com lmtp:[127.0.0.1]:9024
-test-subscribe@example.com lmtp:[127.0.0.1]:9024
-test-unsubscribe@example.com lmtp:[127.0.0.1]:9024
+test@example.com lmtp:[127.0.0.1]:9024
+test-bounces@example.com lmtp:[127.0.0.1]:9024
+test-confirm@example.com lmtp:[127.0.0.1]:9024
+test-join@example.com lmtp:[127.0.0.1]:9024
+test-leave@example.com lmtp:[127.0.0.1]:9024
+test-owner@example.com lmtp:[127.0.0.1]:9024
+test-request@example.com lmtp:[127.0.0.1]:9024
+test-subscribe@example.com lmtp:[127.0.0.1]:9024
+test-unsubscribe@example.com lmtp:[127.0.0.1]:9024
""")
def test_two_lists(self):
@@ -185,25 +185,25 @@ example.com example.com
contents = _strip_header(fp.read())
self.assertMultiLineEqual(contents, """\
# Aliases which are visible only in the @example.com domain.
-other@example.com lmtp:[127.0.0.1]:9024
-other-bounces@example.com lmtp:[127.0.0.1]:9024
-other-confirm@example.com lmtp:[127.0.0.1]:9024
-other-join@example.com lmtp:[127.0.0.1]:9024
-other-leave@example.com lmtp:[127.0.0.1]:9024
-other-owner@example.com lmtp:[127.0.0.1]:9024
-other-request@example.com lmtp:[127.0.0.1]:9024
-other-subscribe@example.com lmtp:[127.0.0.1]:9024
-other-unsubscribe@example.com lmtp:[127.0.0.1]:9024
+other@example.com lmtp:[127.0.0.1]:9024
+other-bounces@example.com lmtp:[127.0.0.1]:9024
+other-confirm@example.com lmtp:[127.0.0.1]:9024
+other-join@example.com lmtp:[127.0.0.1]:9024
+other-leave@example.com lmtp:[127.0.0.1]:9024
+other-owner@example.com lmtp:[127.0.0.1]:9024
+other-request@example.com lmtp:[127.0.0.1]:9024
+other-subscribe@example.com lmtp:[127.0.0.1]:9024
+other-unsubscribe@example.com lmtp:[127.0.0.1]:9024
-test@example.com lmtp:[127.0.0.1]:9024
-test-bounces@example.com lmtp:[127.0.0.1]:9024
-test-confirm@example.com lmtp:[127.0.0.1]:9024
-test-join@example.com lmtp:[127.0.0.1]:9024
-test-leave@example.com lmtp:[127.0.0.1]:9024
-test-owner@example.com lmtp:[127.0.0.1]:9024
-test-request@example.com lmtp:[127.0.0.1]:9024
-test-subscribe@example.com lmtp:[127.0.0.1]:9024
-test-unsubscribe@example.com lmtp:[127.0.0.1]:9024
+test@example.com lmtp:[127.0.0.1]:9024
+test-bounces@example.com lmtp:[127.0.0.1]:9024
+test-confirm@example.com lmtp:[127.0.0.1]:9024
+test-join@example.com lmtp:[127.0.0.1]:9024
+test-leave@example.com lmtp:[127.0.0.1]:9024
+test-owner@example.com lmtp:[127.0.0.1]:9024
+test-request@example.com lmtp:[127.0.0.1]:9024
+test-subscribe@example.com lmtp:[127.0.0.1]:9024
+test-unsubscribe@example.com lmtp:[127.0.0.1]:9024
""")
def test_two_lists_two_domains(self):
@@ -229,24 +229,102 @@ example.net example.net
contents = _strip_header(fp.read())
self.assertMultiLineEqual(contents, """\
# Aliases which are visible only in the @example.com domain.
-test@example.com lmtp:[127.0.0.1]:9024
-test-bounces@example.com lmtp:[127.0.0.1]:9024
-test-confirm@example.com lmtp:[127.0.0.1]:9024
-test-join@example.com lmtp:[127.0.0.1]:9024
-test-leave@example.com lmtp:[127.0.0.1]:9024
-test-owner@example.com lmtp:[127.0.0.1]:9024
-test-request@example.com lmtp:[127.0.0.1]:9024
-test-subscribe@example.com lmtp:[127.0.0.1]:9024
-test-unsubscribe@example.com lmtp:[127.0.0.1]:9024
+test@example.com lmtp:[127.0.0.1]:9024
+test-bounces@example.com lmtp:[127.0.0.1]:9024
+test-confirm@example.com lmtp:[127.0.0.1]:9024
+test-join@example.com lmtp:[127.0.0.1]:9024
+test-leave@example.com lmtp:[127.0.0.1]:9024
+test-owner@example.com lmtp:[127.0.0.1]:9024
+test-request@example.com lmtp:[127.0.0.1]:9024
+test-subscribe@example.com lmtp:[127.0.0.1]:9024
+test-unsubscribe@example.com lmtp:[127.0.0.1]:9024
# Aliases which are visible only in the @example.net domain.
-other@example.net lmtp:[127.0.0.1]:9024
-other-bounces@example.net lmtp:[127.0.0.1]:9024
-other-confirm@example.net lmtp:[127.0.0.1]:9024
-other-join@example.net lmtp:[127.0.0.1]:9024
-other-leave@example.net lmtp:[127.0.0.1]:9024
-other-owner@example.net lmtp:[127.0.0.1]:9024
-other-request@example.net lmtp:[127.0.0.1]:9024
-other-subscribe@example.net lmtp:[127.0.0.1]:9024
-other-unsubscribe@example.net lmtp:[127.0.0.1]:9024
+other@example.net lmtp:[127.0.0.1]:9024
+other-bounces@example.net lmtp:[127.0.0.1]:9024
+other-confirm@example.net lmtp:[127.0.0.1]:9024
+other-join@example.net lmtp:[127.0.0.1]:9024
+other-leave@example.net lmtp:[127.0.0.1]:9024
+other-owner@example.net lmtp:[127.0.0.1]:9024
+other-request@example.net lmtp:[127.0.0.1]:9024
+other-subscribe@example.net lmtp:[127.0.0.1]:9024
+other-unsubscribe@example.net lmtp:[127.0.0.1]:9024
+""")
+
+ def test_missing_postmap_command_raises_runtime_errorr(self):
+ # Changing the postmap command to false will always
+ # return a non-zero exit code.
+ self.postfix.postmap_command = 'false'
+ # Generating postmap hash files will raise a runtimerror.
+ with self.assertRaises(RuntimeError):
+ self.postfix.regenerate(self.tempdir)
+ # Now change the command back to true will make the
+ # command run normally.
+ self.postfix.postmap_command = 'true'
+ self.postfix.regenerate(self.tempdir)
+ # There should be two files in the tempdir.
+ self.assertEqual(sorted(os.listdir(self.tempdir)),
+ ['postfix_domains', 'postfix_lmtp'])
+
+ def test_aliases_regex(self):
+ # Test aliases generation for regex maps for postfix.
+ # Set the transport map type to regex.
+ self.postfix.transport_file_type = 'regex'
+ self.postfix.regenerate(self.tempdir)
+ # The domains file just contains the example.com domain.
+ with open(os.path.join(self.tempdir, 'postfix_domains')) as fp:
+ contents = _strip_header(fp.read())
+ self.assertMultiLineEqual(contents, """\
+/^example\.com$/ example.com
+""")
+
+ # the lmtp file contains transport mapping to the lmtp server.
+ with open(os.path.join(self.tempdir, 'postfix_lmtp')) as fp:
+ contents = _strip_header(fp.read())
+ self.assertMultiLineEqual(contents, """\
+# Aliases which are visible only in the @example.com domain.
+/^test@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-bounces@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-confirm@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-join@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-leave@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-owner@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-request@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-subscribe@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-unsubscribe@example\.com$/ lmtp:[127.0.0.1]:9024
+""")
+
+ def test_aliases_regex_with_dots(self):
+ # Test regex is generated for listnames with multiple dots.
+ self.postfix.transport_file_type = 'regex'
+ create_list('test.list.name.dots@example.com')
+ self.postfix.regenerate(self.tempdir)
+ with open(os.path.join(self.tempdir, 'postfix_domains')) as fp:
+ contents = _strip_header(fp.read())
+ self.assertMultiLineEqual(contents, """\
+/^example\.com$/ example.com
+""")
+ with open(os.path.join(self.tempdir, 'postfix_lmtp')) as fp:
+ contents = _strip_header(fp.read())
+ self.assertMultiLineEqual(contents, """\
+# Aliases which are visible only in the @example.com domain.
+/^test@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-bounces@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-confirm@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-join@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-leave@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-owner@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-request@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-subscribe@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test-unsubscribe@example\.com$/ lmtp:[127.0.0.1]:9024
+
+/^test\.list\.name\.dots@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test\.list\.name\.dots-bounces@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test\.list\.name\.dots-confirm@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test\.list\.name\.dots-join@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test\.list\.name\.dots-leave@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test\.list\.name\.dots-owner@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test\.list\.name\.dots-request@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test\.list\.name\.dots-subscribe@example\.com$/ lmtp:[127.0.0.1]:9024
+/^test\.list\.name\.dots-unsubscribe@example\.com$/ lmtp:[127.0.0.1]:9024
""")