def test_arc_sign_non_ascii_privkey(self): # Private Key contains non-ascii characters. config = Configuration() uni_keyfile = tempfile.NamedTemporaryFile(delete=True) uni_keyfile.write("¢¢¢¢¢¢¢".encode('utf-8')) uni_keyfile.flush() with ExitStack() as resources: fp = resources.enter_context( NamedTemporaryFile('w', encoding='utf-8')) print("""\ [ARC] enabled: yes authserv_id: lists.example.org selector: dummy domain: example.org sig_headers: mime-version, date, from, to, subject privkey: {} """.format(uni_keyfile.name), file=fp) fp.flush() # Suppress warning messages in the test output. Also, make sure # that the config.load() call doesn't break global state. resources.enter_context(mock.patch('sys.stderr')) resources.enter_context(mock.patch.object(config, '_clear')) resources.enter_context(self.assertRaises(SystemExit)) config.load(fp.name)
def test_path_expansion_infloop(self): # A path expansion never completes because it references a # non-existent substitution variable. fd, filename = tempfile.mkstemp() self.addCleanup(os.remove, filename) os.close(fd) with open(filename, 'w') as fp: print("""\ [paths.dev] log_dir: $nopath/log_dir """, file=fp) config = Configuration() # Suppress warning messages in the test output. with self.assertRaises(SystemExit) as cm, mock.patch('sys.stderr'): config.load(filename) self.assertEqual(cm.exception.args, (1,))
def test_bad_path_layout_specifier(self): # Using a [mailman]layout name that doesn't exist is a fatal error. fd, filename = tempfile.mkstemp() self.addCleanup(os.remove, filename) os.close(fd) with open(filename, 'w') as fp: print("""\ [mailman] layout: nonesuch """, file=fp) # Use a fake sys.exit() function that records that it was called, and # that prevents further processing. config = Configuration() # Suppress warning messages in the test output. with self.assertRaises(SystemExit) as cm, mock.patch('sys.stderr'): config.load(filename) self.assertEqual(cm.exception.args, (1,))
def test_bad_path_layout_specifier(self): # Using a [mailman]layout name that doesn't exist is a fatal error. config = Configuration() with ExitStack() as resources: fp = resources.enter_context( NamedTemporaryFile('w', encoding='utf-8')) print("""\ [mailman] layout: nonesuch """, file=fp) fp.flush() # Suppress warning messages in the test output. Also, make sure # that the config.load() call doesn't break global state. resources.enter_context(mock.patch('sys.stderr')) resources.enter_context(mock.patch.object(config, '_clear')) cm = resources.enter_context(self.assertRaises(SystemExit)) config.load(fp.name) self.assertEqual(cm.exception.args, (1,))
def test_path_expansion_infloop(self): # A path expansion never completes because it references a non-existent # substitution variable. config = Configuration() with ExitStack() as resources: fp = resources.enter_context( NamedTemporaryFile('w', encoding='utf-8')) print("""\ [paths.here] log_dir: $nopath/log_dir """, file=fp) fp.flush() # Suppress warning messages in the test output. Also, make sure # that the config.load() call doesn't break global state. resources.enter_context(mock.patch('sys.stderr')) resources.enter_context(mock.patch.object(config, '_clear')) cm = resources.enter_context(self.assertRaises(SystemExit)) config.load(fp.name) self.assertEqual(cm.exception.args, (1,))
def test_config_template_dir_is_source(self): # This test will leave a 'var' directory in the top-level source # directory. Be sure to clean it up. config = Configuration() with ExitStack() as resources: fp = resources.enter_context( NamedTemporaryFile('w', encoding='utf-8')) var_dir = resources.enter_context(TemporaryDirectory()) # Don't let the post-processing after the config.load() to put a # 'var' directory in the source tree's top level directory. print("""\ [paths.here] template_dir: :source: var_dir: {} """.format(var_dir), file=fp) fp.flush() config.load(fp.name) import mailman.templates self.assertEqual(config.TEMPLATE_DIR, os.path.dirname(mailman.templates.__file__))
def test_path_expansion_infloop(self): # A path expansion never completes because it references a non-existent # substitution variable. fd, filename = tempfile.mkstemp() self.addCleanup(os.remove, filename) os.close(fd) with open(filename, 'w') as fp: print("""\ [paths.here] log_dir: $nopath/log_dir """, file=fp) config = Configuration() # Suppress warning messages in the test output. Also, make sure that # the config.load() call doesn't break global state. with ExitStack() as resources: resources.enter_context(mock.patch('sys.stderr')) resources.enter_context(mock.patch.object(config, '_clear')) cm = resources.enter_context(self.assertRaises(SystemExit)) config.load(filename) self.assertEqual(cm.exception.args, (1,))
def test_path_expansion_infloop(self): # A path expansion never completes because it references a non-existent # substitution variable. fd, filename = tempfile.mkstemp() self.addCleanup(os.remove, filename) os.close(fd) with open(filename, 'w') as fp: print("""\ [paths.here] log_dir: $nopath/log_dir """, file=fp) config = Configuration() # Suppress warning messages in the test output. Also, make sure that # the config.load() call doesn't break global state. with ExitStack() as resources: resources.enter_context(mock.patch('sys.stderr')) resources.enter_context(mock.patch.object(config, '_clear')) cm = resources.enter_context(self.assertRaises(SystemExit)) config.load(filename) self.assertEqual(cm.exception.args, (1, ))
def test_bad_path_layout_specifier(self): # Using a [mailman]layout name that doesn't exist is a fatal error. fd, filename = tempfile.mkstemp() self.addCleanup(os.remove, filename) os.close(fd) with open(filename, 'w') as fp: print("""\ [mailman] layout: nonesuch """, file=fp) # Use a fake sys.exit() function that records that it was called, and # that prevents further processing. config = Configuration() # Suppress warning messages in the test output. Also, make sure that # the config.load() call doesn't break global state. with ExitStack() as resources: resources.enter_context(mock.patch('sys.stderr')) resources.enter_context(mock.patch.object(config, '_clear')) cm = resources.enter_context(self.assertRaises(SystemExit)) config.load(filename) self.assertEqual(cm.exception.args, (1,))
def test_bad_path_layout_specifier(self): # Using a [mailman]layout name that doesn't exist is a fatal error. fd, filename = tempfile.mkstemp() self.addCleanup(os.remove, filename) os.close(fd) with open(filename, 'w') as fp: print("""\ [mailman] layout: nonesuch """, file=fp) # Use a fake sys.exit() function that records that it was called, and # that prevents further processing. config = Configuration() # Suppress warning messages in the test output. Also, make sure that # the config.load() call doesn't break global state. with ExitStack() as resources: resources.enter_context(mock.patch('sys.stderr')) resources.enter_context(mock.patch.object(config, '_clear')) cm = resources.enter_context(self.assertRaises(SystemExit)) config.load(filename) self.assertEqual(cm.exception.args, (1, ))
def test_arc_enabled_but_wrong_file(self): # Unreadable private key when ARC is enabled. config = Configuration() with ExitStack() as resources: fp = resources.enter_context( NamedTemporaryFile('w', encoding='utf-8')) print("""\ [ARC] enabled: yes authserv_id: lists.example.org selector: dummy domain: example.org sig_headers: mime-version, date, from, to, subject privkey: /missing/location.pem """, file=fp) fp.flush() # Suppress warning messages in the test output. Also, make sure # that the config.load() call doesn't break global state. resources.enter_context(mock.patch('sys.stderr')) resources.enter_context(mock.patch.object(config, '_clear')) resources.enter_context(self.assertRaises(SystemExit)) config.load(fp.name)
def test_arc_missing_from_in_headers(self): # List of sig_headers should always include "From" header, otherwise, # exception is raised when signing a message. config = Configuration() with ExitStack() as resources: fp = resources.enter_context( NamedTemporaryFile('w', encoding='utf-8')) print("""\ [ARC] enabled: yes authserv_id: lists.example.org selector: dummy domain: example.org sig_headers: to, subject, date privkey: {} """.format(self.keyfile.name), file=fp) fp.flush() # Suppress warning messages in the test output. Also, make sure # that the config.load() call doesn't break global state. resources.enter_context(mock.patch('sys.stderr')) resources.enter_context(mock.patch.object(config, '_clear')) resources.enter_context(self.assertRaises(SystemExit)) config.load(fp.name)