示例#1
0
 def setUp(self):
     self.tempdir = tempfile.mkdtemp()
     self.utility = getUtility(IMailTransportAgentAliases)
     self.mlist = create_list('*****@*****.**')
     self.postfix = LMTP()
     # Let assertMultiLineEqual work without bounds.
     self.maxDiff = None
示例#2
0
 def setUp(self):
     self.tempdir = tempfile.mkdtemp()
     self.utility = getUtility(IMailTransportAgentAliases)
     self.mlist = create_list('*****@*****.**')
     self.postfix = LMTP()
     # Let assertMultiLineEqual work without bounds.
     self.maxDiff = None
示例#3
0
 def setUp(self):
     self.utility = getUtility(IMailTransportAgentAliases)
     self.mlist = create_list("*****@*****.**")
     self.output = StringIO()
     self.postfix = LMTP()
     # Python 2.7 has assertMultiLineEqual.  Let this work without bounds.
     self.maxDiff = None
     self.eq = getattr(self, "assertMultiLineEqual", self.assertEqual)
示例#4
0
class TestPostfix(unittest.TestCase):
    """Test the Postfix LMTP alias generator."""

    layer = ConfigLayer

    def setUp(self):
        self.tempdir = tempfile.mkdtemp()
        self.utility = getUtility(IMailTransportAgentAliases)
        self.mlist = create_list('*****@*****.**')
        self.postfix = LMTP()
        # Let assertMultiLineEqual work without bounds.
        self.maxDiff = None

    def tearDown(self):
        shutil.rmtree(self.tempdir)

    def test_aliases(self):
        # Test the format of the Postfix alias generator.
        self.postfix.regenerate(self.tempdir)
        # There are two files in this directory.
        self.assertEqual(sorted(os.listdir(self.tempdir)),
                         ['postfix_domains', 'postfix_lmtp'])
        # The domains file, just contains the example.com domain.  We have to
        # ignore the file header.
        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 mappings 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.
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]          lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]     lmtp:[127.0.0.1]:9024
[email protected]   lmtp:[127.0.0.1]:9024
""")

    def test_two_lists(self):
        # Both lists need to show up in the aliases file.  LP: #874929.
        # Create a second list.
        create_list('*****@*****.**')
        self.postfix.regenerate(self.tempdir)
        # There are two files in this directory.
        self.assertEqual(sorted(os.listdir(self.tempdir)),
                         ['postfix_domains', 'postfix_lmtp'])
        # Because both lists are in the same domain, there should be only one
        # entry in the relays file.
        with open(os.path.join(self.tempdir, 'postfix_domains')) as fp:
            contents = _strip_header(fp.read())
        self.assertMultiLineEqual(contents, """\
example.com example.com
""")
        # The transport file contains entries for both lists.
        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.
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]          lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]     lmtp:[127.0.0.1]:9024
[email protected]   lmtp:[127.0.0.1]:9024

[email protected]               lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]          lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]     lmtp:[127.0.0.1]:9024
[email protected]   lmtp:[127.0.0.1]:9024
""")

    def test_two_lists_two_domains(self):
        # Now we have two lists in two different domains.  Both lists will
        # show up in the postfix_lmtp file, and both domains will show up in
        # the postfix_domains file.
        getUtility(IDomainManager).add('example.net')
        create_list('*****@*****.**')
        self.postfix.regenerate(self.tempdir)
        # There are two files in this directory.
        self.assertEqual(sorted(os.listdir(self.tempdir)),
                         ['postfix_domains', 'postfix_lmtp'])
        # Because both lists are in the same domain, there should be only one
        # entry in the relays file.
        with open(os.path.join(self.tempdir, 'postfix_domains')) as fp:
            contents = _strip_header(fp.read())
        self.assertMultiLineEqual(contents, """\
example.com example.com
example.net example.net
""")
        # The transport file contains entries for both lists.
        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.
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]          lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]     lmtp:[127.0.0.1]:9024
[email protected]   lmtp:[127.0.0.1]:9024

# Aliases which are visible only in the @example.net domain.
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]          lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]     lmtp:[127.0.0.1]:9024
[email protected]   lmtp:[127.0.0.1]:9024
""")
示例#5
0
class TestPostfix(unittest.TestCase):
    """Test the Postfix LMTP alias generator."""

    layer = ConfigLayer

    def setUp(self):
        self.tempdir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, self.tempdir)
        self.utility = getUtility(IMailTransportAgentAliases)
        self.mlist = create_list('*****@*****.**')
        self.postfix = LMTP()
        # Let assertMultiLineEqual work without bounds.
        self.maxDiff = None

    def test_aliases(self):
        # Test the format of the Postfix alias generator.
        self.postfix.regenerate(self.tempdir)
        # There are two files in this directory.
        self.assertEqual(sorted(os.listdir(self.tempdir)),
                         ['postfix_domains', 'postfix_lmtp'])
        # The domains file, just contains the example.com domain.  We have to
        # ignore the file header.
        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 mappings 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.
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]          lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]     lmtp:[127.0.0.1]:9024
[email protected]   lmtp:[127.0.0.1]:9024
""")

    def test_two_lists(self):
        # Both lists need to show up in the aliases file.  LP: #874929.
        # Create a second list.
        create_list('*****@*****.**')
        self.postfix.regenerate(self.tempdir)
        # There are two files in this directory.
        self.assertEqual(sorted(os.listdir(self.tempdir)),
                         ['postfix_domains', 'postfix_lmtp'])
        # Because both lists are in the same domain, there should be only one
        # entry in the relays file.
        with open(os.path.join(self.tempdir, 'postfix_domains')) as fp:
            contents = _strip_header(fp.read())
        self.assertMultiLineEqual(contents, """\
example.com example.com
""")
        # The transport file contains entries for both lists.
        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.
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]          lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]     lmtp:[127.0.0.1]:9024
[email protected]   lmtp:[127.0.0.1]:9024

[email protected]               lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]          lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]     lmtp:[127.0.0.1]:9024
[email protected]   lmtp:[127.0.0.1]:9024
""")

    def test_two_lists_two_domains(self):
        # Now we have two lists in two different domains.  Both lists will
        # show up in the postfix_lmtp file, and both domains will show up in
        # the postfix_domains file.
        getUtility(IDomainManager).add('example.net')
        create_list('*****@*****.**')
        self.postfix.regenerate(self.tempdir)
        # There are two files in this directory.
        self.assertEqual(sorted(os.listdir(self.tempdir)),
                         ['postfix_domains', 'postfix_lmtp'])
        # Because both lists are in the same domain, there should be only one
        # entry in the relays file.
        with open(os.path.join(self.tempdir, 'postfix_domains')) as fp:
            contents = _strip_header(fp.read())
        self.assertMultiLineEqual(
            contents, """\
example.com example.com
example.net example.net
""")
        # The transport file contains entries for both lists.
        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.
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]          lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]     lmtp:[127.0.0.1]:9024
[email protected]   lmtp:[127.0.0.1]:9024

# Aliases which are visible only in the @example.net domain.
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]          lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]     lmtp:[127.0.0.1]:9024
[email protected]   lmtp:[127.0.0.1]:9024
""")
示例#6
0
class TestPostfix(unittest.TestCase):
    """Test the Postfix LMTP alias generator."""

    layer = ConfigLayer

    def setUp(self):
        self.tempdir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, self.tempdir)
        self.utility = getUtility(IMailTransportAgentAliases)
        self.mlist = create_list('*****@*****.**')
        self.postfix = LMTP()
        # Let assertMultiLineEqual work without bounds.
        self.maxDiff = None

    def test_aliases(self):
        # Test the format of the Postfix alias generator.
        self.postfix.regenerate(self.tempdir)
        # There are two files in this directory.
        self.assertEqual(sorted(os.listdir(self.tempdir)),
                         ['postfix_domains', 'postfix_lmtp'])
        # The domains file, just contains the example.com domain.  We have to
        # ignore the file header.
        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 mappings 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.
[email protected]                       lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]                  lmtp:[127.0.0.1]:9024
[email protected]                 lmtp:[127.0.0.1]:9024
[email protected]                 lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]             lmtp:[127.0.0.1]:9024
[email protected]           lmtp:[127.0.0.1]:9024
""")

    def test_two_lists(self):
        # Both lists need to show up in the aliases file.  LP: #874929.
        # Create a second list.
        create_list('*****@*****.**')
        self.postfix.regenerate(self.tempdir)
        # There are two files in this directory.
        self.assertEqual(sorted(os.listdir(self.tempdir)),
                         ['postfix_domains', 'postfix_lmtp'])
        # Because both lists are in the same domain, there should be only one
        # entry in the relays file.
        with open(os.path.join(self.tempdir, 'postfix_domains')) as fp:
            contents = _strip_header(fp.read())
        self.assertMultiLineEqual(contents, """\
example.com example.com
""")
        # The transport file contains entries for both lists.
        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.
[email protected]                       lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]                  lmtp:[127.0.0.1]:9024
[email protected]                 lmtp:[127.0.0.1]:9024
[email protected]                 lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]             lmtp:[127.0.0.1]:9024
[email protected]           lmtp:[127.0.0.1]:9024

[email protected]                       lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]                  lmtp:[127.0.0.1]:9024
[email protected]                 lmtp:[127.0.0.1]:9024
[email protected]                 lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]             lmtp:[127.0.0.1]:9024
[email protected]           lmtp:[127.0.0.1]:9024
""")

    def test_two_lists_two_domains(self):
        # Now we have two lists in two different domains.  Both lists will
        # show up in the postfix_lmtp file, and both domains will show up in
        # the postfix_domains file.
        getUtility(IDomainManager).add('example.net')
        create_list('*****@*****.**')
        self.postfix.regenerate(self.tempdir)
        # There are two files in this directory.
        self.assertEqual(sorted(os.listdir(self.tempdir)),
                         ['postfix_domains', 'postfix_lmtp'])
        # Because the lists are in different domains, there should be two
        # entries in the relays file.
        with open(os.path.join(self.tempdir, 'postfix_domains')) as fp:
            contents = _strip_header(fp.read())
        self.assertMultiLineEqual(
            contents, """\
example.com example.com
example.net example.net
""")
        # The transport file contains entries for both lists.
        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.
[email protected]                       lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]                  lmtp:[127.0.0.1]:9024
[email protected]                 lmtp:[127.0.0.1]:9024
[email protected]                 lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]             lmtp:[127.0.0.1]:9024
[email protected]           lmtp:[127.0.0.1]:9024

# Aliases which are visible only in the @example.net domain.
[email protected]                       lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]                  lmtp:[127.0.0.1]:9024
[email protected]                 lmtp:[127.0.0.1]:9024
[email protected]                 lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]             lmtp:[127.0.0.1]:9024
[email protected]           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('*****@*****.**')
        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
""")

    def test_three_lists_three_domains_with_one_alias_domain(self):
        # Now we have three lists in three different domains.  All lists will
        # show up in the postfix_lmtp file, and both domains will show up in
        # the postfix_domains file.  One domain has an alias_domain so there
        # will also be a postfix_vmap file with mappings from the email_domain
        # to the alias_domain for the list in that domain and entries for the
        # alias_domain in the other files.
        getUtility(IDomainManager).add('example.net')
        create_list('*****@*****.**')
        getUtility(IDomainManager).add('example.org',
                                       alias_domain='x.example.org')
        create_list('*****@*****.**')
        self.postfix.regenerate(self.tempdir)
        # There are three files in this directory.
        self.assertEqual(sorted(os.listdir(self.tempdir)),
                         ['postfix_domains', 'postfix_lmtp', 'postfix_vmap'])
        # Because the lists are in different domains, there should be three
        # entries in the relays file.
        with open(os.path.join(self.tempdir, 'postfix_domains')) as fp:
            contents = _strip_header(fp.read())
        self.assertMultiLineEqual(
            contents, """\
example.com example.com
example.net example.net
x.example.org example.org
""")
        # The transport file contains entries for all three lists.
        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.
[email protected]                       lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]                  lmtp:[127.0.0.1]:9024
[email protected]                 lmtp:[127.0.0.1]:9024
[email protected]                 lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]             lmtp:[127.0.0.1]:9024
[email protected]           lmtp:[127.0.0.1]:9024

# Aliases which are visible only in the @example.net domain.
[email protected]                       lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]                  lmtp:[127.0.0.1]:9024
[email protected]                 lmtp:[127.0.0.1]:9024
[email protected]                 lmtp:[127.0.0.1]:9024
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]             lmtp:[127.0.0.1]:9024
[email protected]           lmtp:[127.0.0.1]:9024

# Aliases which are visible only in the @x.example.org domain.
[email protected]                        lmtp:[127.0.0.1]:9024
[email protected]                lmtp:[127.0.0.1]:9024
[email protected]                lmtp:[127.0.0.1]:9024
[email protected]                   lmtp:[127.0.0.1]:9024
[email protected]                  lmtp:[127.0.0.1]:9024
[email protected]                  lmtp:[127.0.0.1]:9024
[email protected]                lmtp:[127.0.0.1]:9024
[email protected]              lmtp:[127.0.0.1]:9024
[email protected]            lmtp:[127.0.0.1]:9024
""")
        # The virtual mapping contains only entries for the list with an
        # alias_domain.
        with open(os.path.join(self.tempdir, 'postfix_vmap')) as fp:
            contents = _strip_header(fp.read())
        self.assertMultiLineEqual(
            contents, """\
# Virtual mappings for the @example.org domain.
[email protected]                      [email protected]
[email protected]              [email protected]
[email protected]              [email protected]
[email protected]                 [email protected]
[email protected]                [email protected]
[email protected]                [email protected]
[email protected]              [email protected]
[email protected]            [email protected]
[email protected]          [email protected]
""")

    def test_vmap_regex(self):
        # Test alias domain virtual mapping with regex.
        self.postfix.transport_file_type = 'regex'
        getUtility(IDomainManager).add('example.org',
                                       alias_domain='x.example.org')
        create_list('*****@*****.**')
        self.postfix.regenerate(self.tempdir)
        # There are three files in this directory.
        self.assertEqual(sorted(os.listdir(self.tempdir)),
                         ['postfix_domains', 'postfix_lmtp', 'postfix_vmap'])
        # Because the lists are in different domains, there should be two
        # entries in the relays file.
        with open(os.path.join(self.tempdir, 'postfix_domains')) as fp:
            contents = _strip_header(fp.read())
        self.assertMultiLineEqual(
            contents, """\
/^example\\.com$/ example.com
/^x\\.example\\.org$/ example.org
""")
        # The transport file contains entries for both lists.
        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

# Aliases which are visible only in the @x.example.org domain.
/^other@x\\.example\\.org$/                  lmtp:[127.0.0.1]:9024
/^other-bounces(\\+.*)?@x\\.example\\.org$/   lmtp:[127.0.0.1]:9024
/^other-confirm(\\+.*)?@x\\.example\\.org$/   lmtp:[127.0.0.1]:9024
/^other-join@x\\.example\\.org$/             lmtp:[127.0.0.1]:9024
/^other-leave@x\\.example\\.org$/            lmtp:[127.0.0.1]:9024
/^other-owner@x\\.example\\.org$/            lmtp:[127.0.0.1]:9024
/^other-request@x\\.example\\.org$/          lmtp:[127.0.0.1]:9024
/^other-subscribe@x\\.example\\.org$/        lmtp:[127.0.0.1]:9024
/^other-unsubscribe@x\\.example\\.org$/      lmtp:[127.0.0.1]:9024
""")
        # The virtual mapping contains only entries for the list with an
        # alias_domain.
        with open(os.path.join(self.tempdir, 'postfix_vmap')) as fp:
            contents = _strip_header(fp.read())
        self.assertMultiLineEqual(
            contents, """\
# Virtual mappings for the @example.org domain.
/^other@example\\.org$/                 [email protected]
/^other-bounces(\\+.*)?@example\\.org$/  [email protected]
/^other-confirm(\\+.*)?@example\\.org$/  [email protected]
/^other-join@example\\.org$/            [email protected]
/^other-leave@example\\.org$/           [email protected]
/^other-owner@example\\.org$/           [email protected]
/^other-request@example\\.org$/         [email protected]
/^other-subscribe@example\\.org$/       [email protected]
/^other-unsubscribe@example\\.org$/     [email protected]
""")
示例#7
0
class TestPostfix(unittest.TestCase):
    """Test the Postfix LMTP alias generator."""

    layer = ConfigLayer

    def setUp(self):
        self.utility = getUtility(IMailTransportAgentAliases)
        self.mlist = create_list("*****@*****.**")
        self.output = StringIO()
        self.postfix = LMTP()
        # Python 2.7 has assertMultiLineEqual.  Let this work without bounds.
        self.maxDiff = None
        self.eq = getattr(self, "assertMultiLineEqual", self.assertEqual)

    def test_aliases(self):
        # Test the format of the Postfix alias generator.
        self.postfix.regenerate(self.output)
        # Strip out the variable and unimportant bits of the output.
        lines = self.output.getvalue().splitlines()
        output = NL.join(lines[7:])
        self.eq(
            output,
            """\
# Aliases which are visible only in the @example.com domain.
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]          lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]     lmtp:[127.0.0.1]:9024
[email protected]   lmtp:[127.0.0.1]:9024
""",
        )

    def test_two_lists(self):
        # Both lists need to show up in the aliases file.  LP: #874929.
        # Create a second list.
        create_list("*****@*****.**")
        self.postfix.regenerate(self.output)
        # Strip out the variable and unimportant bits of the output.
        lines = self.output.getvalue().splitlines()
        output = NL.join(lines[7:])
        self.eq(
            output,
            """\
# Aliases which are visible only in the @example.com domain.
[email protected]               lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]          lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]     lmtp:[127.0.0.1]:9024
[email protected]   lmtp:[127.0.0.1]:9024

[email protected]               lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]          lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]         lmtp:[127.0.0.1]:9024
[email protected]       lmtp:[127.0.0.1]:9024
[email protected]     lmtp:[127.0.0.1]:9024
[email protected]   lmtp:[127.0.0.1]:9024
""",
        )