def temporary_config(name, settings): """Temporarily set a configuration (use in a with-statement).""" config.push(name, settings) try: yield finally: config.pop(name)
def setUp(self): self.var_dir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self.var_dir) config.push( 'template config', """\ [paths.testing] var_dir: {} """.format(self.var_dir)) self.addCleanup(config.pop, 'template config') # The following MUST happen AFTER the push() above since pushing a new # config also clears out the language manager. getUtility(ILanguageManager).add('xx', 'utf-8', 'Xlandia') self.mlist = create_list('*****@*****.**') self.mlist.preferred_language = 'xx' self.fp = None # Populate the template directories with a few fake templates. def write(text, path): # noqa: E306 os.makedirs(os.path.dirname(path)) with open(path, 'w') as fp: fp.write(text) self.xxsite = os.path.join(self.var_dir, 'templates', 'site', 'xx', 'site.txt') write('Site template', self.xxsite) self.xxdomain = os.path.join(self.var_dir, 'templates', 'domains', 'example.com', 'xx', 'domain.txt') write('Domain template', self.xxdomain) self.xxlist = os.path.join(self.var_dir, 'templates', 'lists', '*****@*****.**', 'xx', 'list.txt') write('List template', self.xxlist)
def setUp(self): # Create a fake mailing list and message object. self._msg = mfs("""\ To: [email protected] From: [email protected] Subject: Testing the test list Message-ID: <ant> Message-ID-Hash: MS6QLWERIJLGCRF44J7USBFDELMNT2BW Tests are better than no tests but the water deserves to be swum. """) with transaction(): self._mlist = create_list('*****@*****.**') # Set up a temporary directory for the prototype archiver so that it's # easier to clean up. self._tempdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self._tempdir) config.push('prototype', """ [paths.testing] archive_dir: {} """.format(self._tempdir)) self.addCleanup(config.pop, 'prototype') # Capture the structure of a maildir. self._expected_dir_structure = set( (os.path.join(config.ARCHIVE_DIR, path) for path in ( 'prototype', os.path.join('prototype', self._mlist.fqdn_listname), os.path.join('prototype', self._mlist.fqdn_listname, 'cur'), os.path.join('prototype', self._mlist.fqdn_listname, 'new'), os.path.join('prototype', self._mlist.fqdn_listname, 'tmp'), ))) self._expected_dir_structure.add(config.ARCHIVE_DIR)
def setUp(self): config.push('french', """ [mailman] default_language: fr """) self.addCleanup(config.pop, 'french') self._mlist = create_list('*****@*****.**') self._mlist.send_welcome_message = False self._mlist.preferred_language = 'fr' self._mlist.digest_size_threshold = 0 self._process = config.handlers['to-digest'].process self._runner = make_testable_runner(DigestRunner) # Add a French version of the digest masthead. tempdir = TemporaryDirectory() self.addCleanup(tempdir.cleanup) french_path = os.path.join(tempdir.name, 'fr', 'masthead.txt') os.makedirs(os.path.dirname(french_path)) with open(french_path, 'w', encoding='utf-8') as fp: print("""\ Envoyez vos messages pour la liste $display_name à \t$got_list_email Pour vous (dés)abonner par courriel, envoyez un message avec « help » dans le corps ou dans le sujet à \t$got_request_email Vous pouvez contacter l'administrateur de la liste à l'adresse \t$got_owner_email Si vous répondez, n'oubliez pas de changer l'objet du message afin qu'il soit plus spécifique que « Re: Contenu du groupe de $display_name... """, file=fp) getUtility(ITemplateManager).set( 'list:member:digest:masthead', self._mlist.list_id, 'file:///{}/$language/masthead.txt'.format(tempdir.name))
def setUp(cls): assert cls.smtpd is None, 'Layer already set up' # Use a different port than the SMTP and SMTPS layers, since that one # might still be in use. config.push( 'starttls', """ [mta] smtp_port: 9587 smtp_secure_mode: starttls """) test_cert_path = resource_filename('mailman.testing', 'ssl_test_cert.crt') test_key_path = resource_filename('mailman.testing', 'ssl_test_key.key') client_context = ssl.create_default_context() client_context.load_verify_locations(cafile=test_cert_path) server_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) server_context.load_cert_chain(test_cert_path, test_key_path) host = config.mta.smtp_host port = int(config.mta.smtp_port) cls.smtpd = ConnectionCountingSTARTTLSController( host, port, client_context=client_context, server_context=server_context) cls.smtpd.start()
def setUp(self): resources = ExitStack() self.addCleanup(resources.close) self.var_dir = resources.enter_context(TemporaryDirectory()) self._mlist = create_list('*****@*****.**') self._mlist.display_name = 'Test List' getUtility(ITemplateManager).set( 'user:ack:welcome', self._mlist.list_id, 'mailman:///welcome.txt') config.push('template config', """\ [paths.testing] template_dir: {}/templates """.format(self.var_dir)) resources.callback(config.pop, 'template config') # Populate the template directories with a few fake templates. path = os.path.join(self.var_dir, 'templates', 'site', 'en') os.makedirs(path) full_path = os.path.join(path, 'list:user:notice:welcome.txt') with open(full_path, 'w', encoding='utf-8') as fp: print("""\ Welcome to the $list_name mailing list. Posting address: $fqdn_listname Help and other requests: $list_requests Your name: $user_name Your address: $user_address""", file=fp) # Write a list-specific welcome message. path = os.path.join(self.var_dir, 'templates', 'lists', '*****@*****.**', 'xx') os.makedirs(path) full_path = os.path.join(path, 'list:user:notice:welcome.txt') with open(full_path, 'w', encoding='utf-8') as fp: print('You just joined the $list_name mailing list!', file=fp)
def setUp(self): self._mlist = create_list('*****@*****.**') self._now = now() # Enable just the dummy archiver. config.push( 'dummy', """ [archiver.dummy] class: mailman.runners.tests.test_archiver.DummyArchiver enable: no [archiver.prototype] enable: no [archiver.mhonarc] enable: no [archiver.mail_archive] enable: no """) self._archiveq = config.switchboards['archive'] self._msg = mfs("""\ From: [email protected] To: [email protected] Subject: My first post Message-ID: <first> Message-ID-Hash: 4CMWUN6BHVCMHMDAOSJZ2Q72G5M32MWB First post! """) self._runner = make_testable_runner(ArchiveRunner) IListArchiverSet(self._mlist).get('dummy').is_enabled = True
def setUp(self): self._mlist = create_list('*****@*****.**') self._mlist.welcome_message_uri = 'mailman:///welcome.txt' self._mlist.display_name = 'Test List' self.var_dir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self.var_dir) config.push( 'template config', """\ [paths.testing] template_dir: {}/templates """.format(self.var_dir)) self.addCleanup(config.pop, 'template config') # Populate the template directories with a few fake templates. path = os.path.join(self.var_dir, 'templates', 'site', 'en') os.makedirs(path) with open(os.path.join(path, 'welcome.txt'), 'w') as fp: print("""\ Welcome to the $list_name mailing list. Posting address: $fqdn_listname Help and other requests: $list_requests Your name: $user_name Your address: $user_address Your options: $user_options_uri""", file=fp) # Write a list-specific welcome message. path = os.path.join(self.var_dir, 'templates', 'lists', '*****@*****.**', 'xx') os.makedirs(path) with open(os.path.join(path, 'welcome.txt'), 'w') as fp: print('You just joined the $list_name mailing list!', file=fp) # Let assertMultiLineEqual work without bounds. self.maxDiff = None
def test_dispose_preservable(self): # Two actions can happen here, depending on a site-wide setting. If # the site owner has indicated that filtered messages can be # preserved, then this is similar to discarding the message except # that a copy is preserved in the 'bad' queue. self._mlist.filter_action = FilterAction.preserve config.push('preservable', """ [mailman] filtered_messages_are_preservable: yes """) try: mime_delete.dispose(self._mlist, self._msg, {}, 'preserved') except errors.DiscardMessage as error: pass else: raise AssertionError('DiscardMessage exception expected') finally: config.pop('preservable') self.assertEqual(error.message, 'preserved') # There should be no messages in the 'bad' queue. messages = get_queue_messages('bad') self.assertEqual(len(messages), 1) message = messages[0].msg self.assertEqual(message['subject'], 'A disposable message') self.assertEqual(message['message-id'], '<ant>')
def setUp(self): # Create a fake mailing list and message object self._msg = mfs("""\ To: [email protected] From: [email protected] Subject: Testing the test list Message-ID: <ant> X-Message-ID-Hash: MS6QLWERIJLGCRF44J7USBFDELMNT2BW Tests are better than no tests but the water deserves to be swum. """) with transaction(): self._mlist = create_list('*****@*****.**') # Set up a temporary directory for the prototype archiver so that it's # easier to clean up. self._tempdir = tempfile.mkdtemp() config.push('prototype', """ [paths.testing] archive_dir: {0} """.format(self._tempdir)) # Capture the structure of a maildir. self._expected_dir_structure = set( (os.path.join(config.ARCHIVE_DIR, path) for path in ( 'prototype', os.path.join('prototype', self._mlist.fqdn_listname), os.path.join('prototype', self._mlist.fqdn_listname, 'cur'), os.path.join('prototype', self._mlist.fqdn_listname, 'new'), os.path.join('prototype', self._mlist.fqdn_listname, 'tmp'), ))) self._expected_dir_structure.add(config.ARCHIVE_DIR)
def test_arc_sign_raises_exception(self, mocked_sign_message): config.push( 'arc_sign', """ [ARC] enabled: yes authserv_id: test.example.org selector: dummy domain: example.org privkey: %s """ % (self.keyfile.name)) self.addCleanup(config.pop, 'arc_sign') lst = create_list('*****@*****.**') msgdata = {} msg = """\ Message-ID: <*****@*****.**> Date: Thu, 14 Jan 2015 15:00:01 -0800 From: John Q Doe <*****@*****.**> To: [email protected] Subject: Example 1 Hey gang, This is a test message. --J.""" msg = message_from_string(msg) with self.assertRaises(DKIMException): ARCSign().process(lst, msg, msgdata) self.assertTrue(mocked_sign_message.called)
def setUp(self): self._mlist = create_list('*****@*****.**') self._mlist.personalize = Personalization.individual # Make Anne a member of this mailing list. self._anne = subscribe(self._mlist, 'Anne', email='*****@*****.**') # Clear out any results from the previous test. del _deliveries[:] self._msg = mfs("""\ From: [email protected] To: [email protected] Subject: test """) # Set up a personalized footer for decoration. self._template_dir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self._template_dir) path = os.path.join(self._template_dir, 'site', 'en', 'member-footer.txt') os.makedirs(os.path.dirname(path)) with open(path, 'w', encoding='utf-8') as fp: print("""\ address : $user_address delivered: $user_delivered_to language : $user_language name : $user_name """, file=fp) config.push('templates', """ [paths.testing] template_dir: {} """.format(self._template_dir)) self.addCleanup(config.pop, 'templates') getUtility(ITemplateManager).set( 'list:member:regular:footer', self._mlist.list_id, 'mailman:///member-footer.txt')
def setUp(self): self._mlist = create_list('*****@*****.**') self._member = subscribe(self._mlist, 'Anne', email='*****@*****.**') self._msg = mfs("""\ From: [email protected] To: [email protected] Subject: You bounced Message-ID: <first> """) # Set up the translation context. self._var_dir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self._var_dir) xx_template_path = os.path.join( self._var_dir, 'templates', 'site', 'xx', 'probe.txt') os.makedirs(os.path.dirname(xx_template_path)) config.push('xx template dir', """\ [paths.testing] var_dir: {} """.format(self._var_dir)) self.addCleanup(config.pop, 'xx template dir') language_manager = getUtility(ILanguageManager) language_manager.add('xx', 'utf-8', 'Freedonia') self._member.preferences.preferred_language = 'xx' with open(xx_template_path, 'w') as fp: print("""\ blah blah blah $listname $address $optionsurl $owneraddr """, file=fp)
def setUp(self): self._mlist = create_list('*****@*****.**') self._mlist.welcome_message_uri = 'mailman:///welcome.txt' self._mlist.display_name = 'Test List' self.var_dir = tempfile.mkdtemp() config.push('template config', """\ [paths.testing] template_dir: {0}/templates """.format(self.var_dir)) # Populate the template directories with a few fake templates. path = os.path.join(self.var_dir, 'templates', 'site', 'en') os.makedirs(path) with open(os.path.join(path, 'welcome.txt'), 'w') as fp: print("""\ Welcome to the $list_name mailing list. Posting address: $fqdn_listname Help and other requests: $list_requests Your name: $user_name Your address: $user_address Your options: $user_options_uri""", file=fp) # Write a list-specific welcome message. path = os.path.join(self.var_dir, 'templates', 'lists', '*****@*****.**', 'xx') os.makedirs(path) with open(os.path.join(path, 'welcome.txt'), 'w') as fp: print('You just joined the $list_name mailing list!', file=fp) # Let assertMultiLineEqual work without bounds. self.maxDiff = None
def setUp(self): # Set up a temporary directory for the archiver so that it's # easier to clean up. self._tempdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self._tempdir) config.push( 'hyperkitty', """ [paths.testing] archive_dir: {tmpdir}/archive [archiver.hyperkitty] class: mailman_hyperkitty.Archiver enable: yes configuration: {tmpdir}/mailman-hyperkitty.cfg """.format(tmpdir=self._tempdir)) self.addCleanup(config.pop, 'hyperkitty') with open(os.path.join(self._tempdir, "mailman-hyperkitty.cfg"), "w") as conf_h: conf_h.write( dedent(""" [general] base_url: http://localhost api_key: DummyKey """)) # Create the archiver self.archiver = Archiver() self.mlist = FakeList("*****@*****.**") # Patch requests self.requests_patcher = patch("mailman_hyperkitty.requests") self.requests = self.requests_patcher.start() self.fake_response = None self.requests.get.side_effect = \ lambda url, *a, **kw: self.fake_response self.requests.post.side_effect = \ lambda url, *a, **kw: self.fake_response
def setUp(self): self.var_dir = tempfile.mkdtemp() config.push('template config', """\ [paths.testing] var_dir: {0} """.format(self.var_dir)) # The following MUST happen AFTER the push() above since pushing a new # config also clears out the language manager. getUtility(ILanguageManager).add('xx', 'utf-8', 'Xlandia') self.mlist = create_list('*****@*****.**') self.mlist.preferred_language = 'xx' # Populate the template directories with a few fake templates. path = os.path.join(self.var_dir, 'templates', 'site', 'xx') os.makedirs(path) with open(os.path.join(path, 'nosub.txt'), 'w') as fp: print("""\ This is a global template. It has no substitutions. It will be wrapped. """, file=fp) with open(os.path.join(path, 'subs.txt'), 'w') as fp: print("""\ This is a $kind template. It has $howmany substitutions. It will be wrapped. """, file=fp) with open(os.path.join(path, 'nowrap.txt'), 'w') as fp: print("""\ This is a $kind template. It has $howmany substitutions. It will not be wrapped. """, file=fp)
def setUp(self): self._mlist = create_list('*****@*****.**') self._member = add_member(self._mlist, '*****@*****.**', 'Anne Person', 'xxx', DeliveryMode.regular, 'en') self._msg = mfs("""\ From: [email protected] To: [email protected] Subject: You bounced Message-ID: <first> """) # Set up the translation context. self._var_dir = tempfile.mkdtemp() xx_template_path = os.path.join( self._var_dir, 'templates', 'site', 'xx', 'probe.txt') os.makedirs(os.path.dirname(xx_template_path)) config.push('xx template dir', """\ [paths.testing] var_dir: {0} """.format(self._var_dir)) language_manager = getUtility(ILanguageManager) language_manager.add('xx', 'utf-8', 'Freedonia') self._member.preferences.preferred_language = 'xx' with open(xx_template_path, 'w') as fp: print("""\ blah blah blah $listname $address $optionsurl $owneraddr """, file=fp) # Let assertMultiLineEqual work without bounds. self.maxDiff = None
def setUp(self): self._mlist = create_list('*****@*****.**') self._now = now() # Enable just the dummy archiver. config.push('dummy', """ [archiver.dummy] class: mailman.runners.tests.test_archiver.DummyArchiver enable: no [archiver.prototype] enable: no [archiver.mhonarc] enable: no [archiver.mail_archive] enable: no """) self._archiveq = config.switchboards['archive'] self._msg = mfs("""\ From: [email protected] To: [email protected] Subject: My first post Message-ID: <first> X-Message-ID-Hash: 4CMWUN6BHVCMHMDAOSJZ2Q72G5M32MWB First post! """) self._runner = make_testable_runner(ArchiveRunner) IListArchiverSet(self._mlist).get('dummy').is_enabled = True
def setUp(self): self._mlist = create_list('*****@*****.**') self._member = subscribe(self._mlist, 'Anne', email='*****@*****.**') self._msg = mfs("""\ From: [email protected] To: [email protected] Subject: You bounced Message-ID: <first> """) # Set up the translation context. self._var_dir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self._var_dir) xx_template_path = os.path.join(self._var_dir, 'templates', 'site', 'xx', 'list:user:notice:probe.txt') os.makedirs(os.path.dirname(xx_template_path)) config.push( 'xx template dir', """\ [paths.testing] var_dir: {} """.format(self._var_dir)) self.addCleanup(config.pop, 'xx template dir') language_manager = getUtility(ILanguageManager) language_manager.add('xx', 'utf-8', 'Freedonia') self._member.preferences.preferred_language = 'xx' with open(xx_template_path, 'w') as fp: print("""\ blah blah blah $listname $address $owneraddr """, file=fp)
def setUp(self): self._mlist = create_list('*****@*****.**') self._mlist.personalize = Personalization.individual # Make Anne a member of this mailing list. self._anne = add_member(self._mlist, '*****@*****.**', 'Anne Person', 'xyz', DeliveryMode.regular, 'en') # Clear out any results from the previous test. del _deliveries[:] self._msg = mfs("""\ From: [email protected] To: [email protected] Subject: test """) # Set up a personalized footer for decoration. self._template_dir = tempfile.mkdtemp() path = os.path.join(self._template_dir, 'site', 'en', 'member-footer.txt') os.makedirs(os.path.dirname(path)) with open(path, 'w') as fp: print("""\ address : $user_address delivered: $user_delivered_to language : $user_language name : $user_name options : $user_optionsurl """, file=fp) config.push('templates', """ [paths.testing] template_dir: {0} """.format(self._template_dir)) self._mlist.footer_uri = 'mailman:///member-footer.txt' # Let assertMultiLineEqual work without bounds. self.maxDiff = None
def setUp(self): self._mlist = create_list('*****@*****.**') self._mlist.personalize = Personalization.individual # Make Anne a member of this mailing list. self._anne = subscribe(self._mlist, 'Anne', email='*****@*****.**') # Clear out any results from the previous test. del _deliveries[:] self._msg = mfs("""\ From: [email protected] To: [email protected] Subject: test """) # Set up a personalized footer for decoration. self._template_dir = tempfile.mkdtemp() path = os.path.join(self._template_dir, 'site', 'en', 'member-footer.txt') os.makedirs(os.path.dirname(path)) with open(path, 'w') as fp: print("""\ address : $user_address delivered: $user_delivered_to language : $user_language name : $user_name options : $user_optionsurl """, file=fp) config.push( 'templates', """ [paths.testing] template_dir: {0} """.format(self._template_dir)) self._mlist.footer_uri = 'mailman:///member-footer.txt' # Let assertMultiLineEqual work without bounds. self.maxDiff = None
def dummy_script(arg=''): exe = sys.executable extra = '' if arg == 'scripterr': extra = 'error' with ExitStack() as resources: tempdir = tempfile.mkdtemp() resources.callback(shutil.rmtree, tempdir) filter_path = os.path.join(tempdir, 'filter.py') if arg in ('noperm', 'nonexist'): exe = filter_path with open(filter_path, 'w', encoding='utf-8') as fp: print("""\ import sys if len(sys.argv) > 2: sys.exit(1) print('Converted text/html to text/plain') print('Filename:', sys.argv[1]) """, file=fp) config.push('dummy script', """\ [mailman] html_to_plain_text_command = {exe} {script} {extra} $filename """.format(exe=exe, script=filter_path, extra=extra)) resources.callback(config.pop, 'dummy script') if arg == 'nonexist': os.rename(filter_path, filter_path + 'xxx') elif arg == 'noperm': os.chmod(filter_path, 0o644) yield
def setUp(self): self._mlist = create_list("*****@*****.**") self._mlist.send_welcome_message = False self._bounceq = config.switchboards["bounces"] self._runner = make_testable_runner(BounceRunner, "bounces") self._anne = getUtility(IUserManager).create_address("*****@*****.**") self._member = self._mlist.subscribe(self._anne, MemberRole.member) self._msg = message_from_string( """\ From: [email protected] To: [email protected] Message-Id: <first> """ ) self._msgdata = dict(listid="test.example.com") self._processor = getUtility(IBounceProcessor) config.push( "site owner", """ [mailman] site_owner: [email protected] """, ) self.addCleanup(config.pop, "site owner")
def setUp(self): self.var_dir = tempfile.mkdtemp() config.push('template config', """\ [paths.testing] var_dir: {0} """.format(self.var_dir)) # The following MUST happen AFTER the push() above since pushing a new # config also clears out the language manager. getUtility(ILanguageManager).add('xx', 'utf-8', 'Xlandia') self.mlist = create_list('*****@*****.**') self.mlist.preferred_language = 'xx' self.fp = None # Populate the template directories with a few fake templates. def write(text, path): os.makedirs(os.path.dirname(path)) with open(path, 'w') as fp: fp.write(text) self.xxsite = os.path.join( self.var_dir, 'templates', 'site', 'xx', 'site.txt') write('Site template', self.xxsite) self.xxdomain = os.path.join( self.var_dir, 'templates', 'domains', 'example.com', 'xx', 'domain.txt') write('Domain template', self.xxdomain) self.xxlist = os.path.join( self.var_dir, 'templates', 'lists', '*****@*****.**', 'xx', 'list.txt') write('List template', self.xxlist)
def test_chain_validation_fail(self): # Set the log-level for dkimpy to CRITICAL To avoid error output from # logger. logging.getLogger('dkimpy').setLevel(logging.CRITICAL) config.push('dkim_and_cv', """ [ARC] enabled: yes authserv_id: lists.example.org dkim: yes dmarc: no privkey: {} """.format(self.keyfile.name)) self.addCleanup(config.pop, 'dkim_and_cv') lst = create_list('*****@*****.**') msgdata = {} msg = message_from_string("""MIME-Version: 1.0 Return-Path: <*****@*****.**> ARC-Seal: a=rsa-sha256; b=dOdFEyhrk/tw5wl3vMIogoxhaVsKJkrkEhnAcq2XqOLSQhPpGzhGBJzR7k1sWGokon3TmQ 7TX9zQLO6ikRpwd/pUswiRW5DBupy58fefuclXJAhErsrebfvfiueGyhHXV7C1LyJTztywzn QGG4SCciU/FTlsJ0QANrnLRoadfps=; cv=none; d=example.org; i=1; s=dummy; t=12345 ARC-Message-Signature: a=rsa-sha256; b=QsRzR/UqwRfVLBc1TnoQomlVw5qi6jp08q8lHpBSl4RehWyHQtY3uOIAGdghDk/mO+/Xpm 9JA5UVrPyDV0f+2q/YAHuwvP11iCkBQkocmFvgTSxN8H+DwFFPrVVUudQYZV7UDDycXoM6UE cdfzLLzVNPOAHEDIi/uzoV4sUqZ18=; bh=KWSe46TZKCcDbH4klJPo+tjk5LWJnVRlP5pvjXFZYLQ=; c=relaxed/relaxed; d=example.org; h=from:to:date:subject:mime-version:arc-authentication- results; i=1; s=dummy; t=12345 ARC-Authentication-Results: i=1; lists.example.org; spf=pass [email protected]; dkim=pass (1024-bit key) [email protected]; dmarc=pass Received: from segv.d1.example (segv.d1.example [72.52.75.15]) by lists.example.org (8.14.5/8.14.5) with ESMTP id t0EKaNU9010123 for <*****@*****.**>; Thu, 14 Jan 2015 15:01:30 -0800 (PST) (envelope-from [email protected]) Authentication-Results: lists.example.org; spf=pass [email protected]; dkim=pass (1024-bit key) [email protected]; dmarc=pass Received: by 10.157.14.6 with HTTP; Tue, 3 Jan 2017 12:22:54 -0800 (PST) Message-ID: <*****@*****.**> Date: Thu, 14 Jan 2015 15:00:01 -0800 From: John Q Doe <*****@*****.**> To: [email protected] Subject: Example 1 Hey gang(modified), This is a test message. --J. """) ValidateAuthenticity().process(lst, msg, msgdata) res = ["lists.example.org; spf=pass [email protected]" "; dkim=pass [email protected]; dmarc=pass; arc=fail"] self.assertEqual(msg["Authentication-Results"], ''.join(res))
def test_starttls_config(self): config.push('starttls_config', """\ [mta] smtp_secure_mode: starttls """) delivery = BaseDeliveryTester() self.assertIsInstance(delivery.connection, Connection) config.pop('starttls_config')
def test_invalid_config(self): config.push('invalid_config', """\ [mta] smtp_secure_mode: invalid """) with self.assertRaises(InvalidConfigurationError): BaseDeliveryTester() config.pop('invalid_config')
def setUp(self): self._mlist = create_list('*****@*****.**') # The default ssha scheme introduces a random salt, which is # inappropriate for unit tests. config.push('password scheme', """ [passwords] password_scheme: sha """)
def test_pushed_section_is_found(self): config.push('test config', """\ [archiver.other] enable: yes """) result = self._command.invoke(conf, ('-k', 'enable')) self.assertIn('[archiver.other] enable: yes', result.output) config.pop('test config')
def test_prototype_no_url(self): # The prototype archiver is not web-based, it must not return URLs config.push('archiver', """ [archiver.prototype] enable: yes """) self.addCleanup(config.pop, 'archiver') rfc_2369.process(self._mlist, self._msg, {}) self.assertNotIn('Archived-At', self._msg) self.assertNotIn('List-Archive', self._msg)
def setUp(self): self._mlist = create_list('*****@*****.**') self._msg = mfs("""\ To: [email protected] From: [email protected] Message-ID: <alpha> Content-Type: text/plain; This is a test message. """) self._mpm = mfs("""\ To: [email protected] From: [email protected] Message-ID: <alpha> Content-Type: multipart/mixed; boundary="aaaaaa" --aaaaaa Content-Type: text/plain; This is a test message. --aaaaaa Content-Type: text/plain; This is part 2 --aaaaaa-- """) self._mpa = mfs("""\ To: [email protected] From: [email protected] Message-ID: <alpha> Content-Type: multipart/alternative; boundary="aaaaaa" --aaaaaa Content-Type: text/plain; This is a test message. --aaaaaa Content-Type: text/html; This is a test message. --aaaaaa-- """) temporary_dir = TemporaryDirectory() self.addCleanup(temporary_dir.cleanup) template_dir = temporary_dir.name config.push( 'archiver', """\ [paths.testing] template_dir: {} [archiver.testarchiver] class: mailman.handlers.tests.test_decorate.TestArchiver enable: yes """.format(template_dir)) self.addCleanup(config.pop, 'archiver')
def setUp(self): config.push('french', """ [mailman] default_language: fr """) self.addCleanup(config.pop, 'french') self._mlist = create_list('*****@*****.**') self._mlist.preferred_language = 'fr' self._mlist.digest_size_threshold = 0 self._process = config.handlers['to-digest'].process self._runner = make_testable_runner(DigestRunner)
def setUp(self): self.var_dir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self.var_dir) config.push('no template dir', """\ [mailman] default_language: fr [paths.testing] var_dir: {} """.format(self.var_dir)) self.addCleanup(config.pop, 'no template dir') self.mlist = create_list('*****@*****.**') self.mlist.preferred_language = 'de'
def test_not_archived(self): # Messages sent to non-archived lists must not get the added headers. self._mlist.archive_policy = ArchivePolicy.never config.push('archiver', """ [archiver.dummy] class: {}.DummyArchiver enable: yes """.format(DummyArchiver.__module__)) self.addCleanup(config.pop, 'archiver') rfc_2369.process(self._mlist, self._msg, {}) self.assertNotIn('List-Archive', self._msg) self.assertNotIn('Archived-At', self._msg)
def setUp(self): self.var_dir = tempfile.mkdtemp() config.push('template config', """\ [paths.testing] var_dir: {0} """.format(self.var_dir)) # Put a demo template in the site directory. path = os.path.join(self.var_dir, 'templates', 'site', 'en') os.makedirs(path) with open(os.path.join(path, 'demo.txt'), 'w') as fp: print('Test content', end='', file=fp) self._loader = getUtility(ITemplateLoader) self._mlist = create_list('*****@*****.**')
def setUp(self): self.var_dir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self.var_dir) config.push( 'no template dir', """\ [mailman] default_language: fr [paths.testing] var_dir: {} """.format(self.var_dir)) self.addCleanup(config.pop, 'no template dir') self.mlist = create_list('*****@*****.**') self.mlist.preferred_language = 'de'
def setUp(self): resources = ExitStack() self.addCleanup(resources.close) var_dir = resources.enter_context(TemporaryDirectory()) config.push( 'template config', """\ [paths.testing] var_dir: {} """.format(var_dir)) resources.callback(config.pop, 'template config') self._mlist = create_list('*****@*****.**') self._loader = getUtility(ITemplateLoader) self._manager = getUtility(ITemplateManager)
def setUp(self): self.var_dir = tempfile.mkdtemp() config.push('no template dir', """\ [mailman] default_language: fr [paths.testing] var_dir: {0} """.format(self.var_dir)) language_manager = getUtility(ILanguageManager) language_manager.add('de', 'utf-8', 'German') language_manager.add('it', 'utf-8', 'Italian') self.mlist = create_list('*****@*****.**') self.mlist.preferred_language = 'de'
def setUp(self): config.push('test config', """ [mailman] site_owner: [email protected] """) self._mlist = create_list('*****@*****.**') self._msg = mfs("""\ From: [email protected] To: [email protected] Subject: You bounced Message-ID: <first> """)
def setUp(self): self._command = CliRunner() config.push( 'gatenews tests', """\ [nntp] host: news.example.com """) self.addCleanup(config.pop, 'gatenews tests') self.mlist = create_list('*****@*****.**') self.mlist.linked_newsgroup = 'my.group' self.mlist.usenet_watermark = 0 self.mlist.gateway_to_mail = True # Create a second list without gateway for test coverage purposes. create_list('*****@*****.**')
def setUp(self): self.var_dir = tempfile.mkdtemp() config.push( 'no template dir', """\ [mailman] default_language: fr [paths.testing] var_dir: {0} """.format(self.var_dir)) language_manager = getUtility(ILanguageManager) language_manager.add('de', 'utf-8', 'German') language_manager.add('it', 'utf-8', 'Italian') self.mlist = create_list('*****@*****.**') self.mlist.preferred_language = 'de'
def setUp(self): self.var_dir = tempfile.mkdtemp() config.push( 'template config', """\ [paths.testing] var_dir: {0} """.format(self.var_dir)) # Put a demo template in the site directory. path = os.path.join(self.var_dir, 'templates', 'site', 'en') os.makedirs(path) with open(os.path.join(path, 'demo.txt'), 'w') as fp: print('Test content', end='', file=fp) self._loader = getUtility(ITemplateLoader) self._mlist = create_list('*****@*****.**')
def setUp(self): self._mlist = create_list('*****@*****.**') self._msg = mfs("""\ From: [email protected] To: [email protected] Subject: A disposable message Message-ID: <ant> """) config.push('dispose', """ [mailman] site_owner: [email protected] """) self.addCleanup(config.pop, 'dispose')
def test_add_headers(self): # Test the addition of the Archived-At and List-Archive headers. config.push('archiver', """ [archiver.dummy] class: {}.DummyArchiver enable: yes """.format(DummyArchiver.__module__)) self.addCleanup(config.pop, 'archiver') rfc_2369.process(self._mlist, self._msg, {}) self.assertEqual( self._msg.get_all('List-Archive'), ['<http://example.com>']) self.assertEqual( self._msg.get_all('Archived-At'), ['<http://example.com/4CMWUN6BHVCMHMDAOSJZ2Q72G5M32MWB>'])
def test_site_disabled(self): # Here the system configuration enables all the archivers in time for # the archive set to be created with all list archivers enabled. But # then the site-wide archiver gets disabled, so the list specific # archiver will also be disabled. archiver_set = IListArchiverSet(self._mlist) archiver = archiver_set.get('prototype') self.assertTrue(archiver.is_enabled) # Disable the site-wide archiver. config.push('enable prototype', """\ [archiver.prototype] enable: no """) self.assertFalse(archiver.is_enabled) config.pop('enable prototype')
def test_add_headers(self): # Test the addition of the Archived-At and List-Archive headers. config.push('archiver', """ [archiver.dummy] class: {}.DummyArchiver enable: yes """.format(DummyArchiver.__module__)) self.addCleanup(config.pop, 'archiver') rfc_2369.process(self._mlist, self._msg, {}) self.assertEqual( self._msg.get_all('List-Archive'), ['<http://lists.example.com>']) self.assertEqual( self._msg.get_all('Archived-At'), ['<http://lists.example.com/4CMWUN6BHVCMHMDAOSJZ2Q72G5M32MWB>'])
def setUp(self): self._mlist = create_list('*****@*****.**') self._msg = mfs("""\ From: [email protected] To: [email protected] Subject: A disposable message Message-ID: <ant> """) config.push('dispose', """ [mailman] site_owner: [email protected] """) # Let assertMultiLineEqual work without bounds. self.maxDiff = None
def dummy_script(): with ExitStack() as resources: tempdir = tempfile.mkdtemp() resources.callback(shutil.rmtree, tempdir) filter_path = os.path.join(tempdir, 'filter.py') with open(filter_path, 'w', encoding='utf-8') as fp: print("""\ import sys print('Converted text/html to text/plain') print('Filename:', sys.argv[1]) """, file=fp) config.push('dummy script', """\ [mailman] html_to_plain_text_command = {exe} {script} $filename """.format(exe=sys.executable, script=filter_path)) resources.callback(config.pop, 'dummy script') yield
def setUp(self): # Push a config where actual delivery is handled by a dummy function. # We generally don't care what this does, since we're just testing the # setting of the 'verp' key in the metadata. config.push('fake outgoing', """ [mta] outgoing: mailman.runners.tests.test_outgoing.raise_socket_error """) self._mlist = create_list('*****@*****.**') self._outq = config.switchboards['out'] self._runner = make_testable_runner(OutgoingRunner, 'out', run_once) self._msg = message_from_string("""\ From: [email protected] To: [email protected] Message-Id: <first> """)
def test_max_autoresponses_per_day(self): # The last one we sent was the last one we should send today. Instead # of sending an automatic response, send them the "no more today" # message. config.push('max-1', """ [mta] max_autoresponses_per_day: 1 """) # Simulate a response having been sent to an address already. anne = getUtility(IUserManager).create_address('*****@*****.**') response_set = IAutoResponseSet(self._mlist) response_set.response_sent(anne, Response.hold) # Trigger the sending of a "last response for today" using the default # language (i.e. the mailing list's preferred language). autorespond_to_sender(self._mlist, '*****@*****.**') # So first, there should be one more hold response sent to the user. self.assertEqual(response_set.todays_count(anne, Response.hold), 2) # And the virgin queue should have the message in it. messages = get_queue_messages('virgin') self.assertEqual(len(messages), 1) # Remove the variable headers. message = messages[0].msg self.assertTrue('message-id' in message) del message['message-id'] self.assertTrue('date' in message) del message['date'] self.eq(messages[0].msg.as_string(), """\ MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Subject: Last autoresponse notification for today From: [email protected] To: [email protected] Precedence: bulk We have received a message from your address <*****@*****.**> requesting an automated response from the [email protected] mailing list. The number we have seen today: 1. In order to avoid problems such as mail loops between email robots, we will not be sending you any further responses today. Please try again tomorrow. If you believe this message is in error, or if you have any questions, please contact the list owner at [email protected].""")
def test_enable_list_archiver(self): # When the system configuration file disables an archiver site-wide, # the list-specific mailing list will get initialized as not enabled. # Create the archiver set on the fly so that it doesn't get # initialized with a configuration that enables the prototype archiver. archiver_set = IListArchiverSet(self._mlist) archiver = archiver_set.get('prototype') self.assertFalse(archiver.is_enabled) # Enable both the list archiver and the system archiver. archiver.is_enabled = True config.push('enable prototype', """\ [archiver.prototype] enable: yes """) # Get the IListArchiver again. archiver = archiver_set.get('prototype') self.assertTrue(archiver.is_enabled) config.pop('enable prototype')
def setUp(self): self.var_dir = tempfile.mkdtemp() config.push( "template config", """\ [paths.testing] var_dir: {0} """.format( self.var_dir ), ) # Put a demo template in the site directory. path = os.path.join(self.var_dir, "templates", "site", "en") os.makedirs(path) with open(os.path.join(path, "demo.txt"), "w") as fp: print("Test content", end="", file=fp) self._loader = getUtility(ITemplateLoader) getUtility(ILanguageManager).add("it", "utf-8", "Italian") self._mlist = create_list("*****@*****.**")
def setUp(self): self._mlist = create_list('*****@*****.**') self._bounceq = config.switchboards['bounces'] self._runner = make_testable_runner(BounceRunner, 'bounces') self._anne = getUtility(IUserManager).create_address( '*****@*****.**') self._member = self._mlist.subscribe(self._anne, MemberRole.member) self._msg = message_from_string("""\ From: [email protected] To: [email protected] Message-Id: <first> """) self._msgdata = dict(listname='*****@*****.**') self._processor = getUtility(IBounceProcessor) config.push('site owner', """ [mailman] site_owner: [email protected] """)
def test_site_admin_unicode(self): # Since the config file is read as bytes, the site_owner is also a # bytes and must be converted to unicode when used as a fallback. self._cris.unsubscribe() self._dave.unsubscribe() self.assertEqual(self._mlist.administrators.member_count, 0) msgdata = {} # In order to properly mimic the testing environment, use # config.push()/config.pop() directly instead of using the # configuration() context manager. config.push('test_site_admin_unicode', b"""\ [mailman] site_owner: [email protected] """) try: self._process(self._mlist, self._msg, msgdata) finally: config.pop('test_site_admin_unicode') self.assertEqual(len(msgdata['recipients']), 1) self.assertIsInstance(list(msgdata['recipients'])[0], unicode)