diff options
| author | Barry Warsaw | 2011-04-10 18:03:37 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2011-04-10 18:03:37 -0400 |
| commit | 37038a683cd909438a6dee43beb9b258ef4e4313 (patch) | |
| tree | df50eabfcc890f01203d90c453dc1b1dbde65d2c /src/mailman/tests | |
| parent | cce9729cac32b6c5fe2acc77b2bfb6b7c545711f (diff) | |
| parent | ef3a4a87e2c0f4b640e31afc4828d2edbd005846 (diff) | |
| download | mailman-37038a683cd909438a6dee43beb9b258ef4e4313.tar.gz mailman-37038a683cd909438a6dee43beb9b258ef4e4313.tar.zst mailman-37038a683cd909438a6dee43beb9b258ef4e4313.zip | |
Trunk merge
Diffstat (limited to 'src/mailman/tests')
| -rw-r--r-- | src/mailman/tests/test_documentation.py | 2 | ||||
| -rw-r--r-- | src/mailman/tests/test_membership.py | 2 | ||||
| -rw-r--r-- | src/mailman/tests/test_passwords.py | 150 | ||||
| -rw-r--r-- | src/mailman/tests/test_security_mgr.py | 241 |
4 files changed, 2 insertions, 393 deletions
diff --git a/src/mailman/tests/test_documentation.py b/src/mailman/tests/test_documentation.py index e65885d79..f723ecf3e 100644 --- a/src/mailman/tests/test_documentation.py +++ b/src/mailman/tests/test_documentation.py @@ -254,7 +254,7 @@ def test_suite(): layer = getattr(sys.modules[package_path], 'layer', SMTPLayer) for filename in os.listdir(docsdir): base, extension = os.path.splitext(filename) - if os.path.splitext(filename)[1] == '.txt': + if os.path.splitext(filename)[1] in ('.txt', '.rst'): module_path = package_path + '.' + base doctest_files[module_path] = ( os.path.join(docsdir, filename), layer) diff --git a/src/mailman/tests/test_membership.py b/src/mailman/tests/test_membership.py index c3e40cfcc..8425cf65f 100644 --- a/src/mailman/tests/test_membership.py +++ b/src/mailman/tests/test_membership.py @@ -28,11 +28,11 @@ __all__ = [ import time import unittest -from mailman import passwords from mailman.app.lifecycle import create_list, remove_list from mailman.config import config from mailman.interfaces.member import NotAMemberError from mailman.testing.layers import ConfigLayer +from mailman.utilities import passwords diff --git a/src/mailman/tests/test_passwords.py b/src/mailman/tests/test_passwords.py deleted file mode 100644 index 49f55e82f..000000000 --- a/src/mailman/tests/test_passwords.py +++ /dev/null @@ -1,150 +0,0 @@ -# Copyright (C) 2007-2011 by the Free Software Foundation, Inc. -# -# This file is part of GNU Mailman. -# -# GNU Mailman is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free -# Software Foundation, either version 3 of the License, or (at your option) -# any later version. -# -# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along with -# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. - -"""Unit tests for the passwords module.""" - -from __future__ import absolute_import, unicode_literals - -__metaclass__ = type -__all__ = [ - 'test_suite', - ] - - -import unittest - -from mailman import passwords -from mailman.core import errors - - - -class TestPasswordsBase(unittest.TestCase): - scheme = None - - def setUp(self): - # passwords; 8-bit or unicode strings; ascii or binary - self.pw8a = b'abc' - self.pw8b = b'abc\xc3\xbf' # 'abc\xff' - self.pwub = b'abc\xff' - # bad password; 8-bit or unicode; ascii or binary - self.bad8a = b'xyz' - self.bad8b = b'xyz\xc3\xbf' # 'xyz\xff' - self.badub = b'xyz\xff' - - def test_passwords(self): - unless = self.failUnless - failif = self.failIf - secret = passwords.make_secret(self.pw8a, self.scheme) - unless(passwords.check_response(secret, self.pw8a)) - failif(passwords.check_response(secret, self.bad8a)) - - def test_passwords_with_funky_chars(self): - unless = self.failUnless - failif = self.failIf - secret = passwords.make_secret(self.pw8b, self.scheme) - unless(passwords.check_response(secret, self.pw8b)) - failif(passwords.check_response(secret, self.bad8b)) - - def test_unicode_passwords_with_funky_chars(self): - unless = self.failUnless - failif = self.failIf - secret = passwords.make_secret(self.pwub, self.scheme) - unless(passwords.check_response(secret, self.pwub)) - failif(passwords.check_response(secret, self.badub)) - - - -class TestBogusPasswords(TestPasswordsBase): - scheme = -1 - - def test_passwords(self): - self.assertRaises(errors.BadPasswordSchemeError, - passwords.make_secret, self.pw8a, self.scheme) - - def test_passwords_with_funky_chars(self): - self.assertRaises(errors.BadPasswordSchemeError, - passwords.make_secret, self.pw8b, self.scheme) - - def test_unicode_passwords_with_funky_chars(self): - self.assertRaises(errors.BadPasswordSchemeError, - passwords.make_secret, self.pwub, self.scheme) - - - -class TestNonePasswords(TestPasswordsBase): - scheme = passwords.Schemes.no_scheme - - def test_passwords(self): - failif = self.failIf - secret = passwords.make_secret(self.pw8a, self.scheme) - failif(passwords.check_response(secret, self.pw8a)) - failif(passwords.check_response(secret, self.bad8a)) - - def test_passwords_with_funky_chars(self): - failif = self.failIf - secret = passwords.make_secret(self.pw8b, self.scheme) - failif(passwords.check_response(secret, self.pw8b)) - failif(passwords.check_response(secret, self.bad8b)) - - def test_unicode_passwords_with_funky_chars(self): - failif = self.failIf - secret = passwords.make_secret(self.pwub, self.scheme) - failif(passwords.check_response(secret, self.pwub)) - failif(passwords.check_response(secret, self.badub)) - - - -class TestCleartextPasswords(TestPasswordsBase): - scheme = passwords.Schemes.cleartext - - -class TestSHAPasswords(TestPasswordsBase): - scheme = passwords.Schemes.sha - - -class TestSSHAPasswords(TestPasswordsBase): - scheme = passwords.Schemes.ssha - - -class TestPBKDF2Passwords(TestPasswordsBase): - scheme = passwords.Schemes.pbkdf2 - - - -class TestSchemeLookup(unittest.TestCase): - def test_scheme_name_lookup(self): - unless = self.failUnless - unless(passwords.lookup_scheme('NONE') is passwords.Schemes.no_scheme) - unless(passwords.lookup_scheme('CLEARTEXT') is - passwords.Schemes.cleartext) - unless(passwords.lookup_scheme('SHA') is passwords.Schemes.sha) - unless(passwords.lookup_scheme('SSHA') is passwords.Schemes.ssha) - unless(passwords.lookup_scheme('PBKDF2') is passwords.Schemes.pbkdf2) - unless(passwords.lookup_scheme(' -bogus- ') is None) - - - -def test_suite(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TestBogusPasswords)) - suite.addTest(unittest.makeSuite(TestNonePasswords)) - suite.addTest(unittest.makeSuite(TestCleartextPasswords)) - suite.addTest(unittest.makeSuite(TestSHAPasswords)) - suite.addTest(unittest.makeSuite(TestSSHAPasswords)) - suite.addTest(unittest.makeSuite(TestPBKDF2Passwords)) - suite.addTest(unittest.makeSuite(TestSchemeLookup)) - return suite diff --git a/src/mailman/tests/test_security_mgr.py b/src/mailman/tests/test_security_mgr.py deleted file mode 100644 index a4f9c1cf4..000000000 --- a/src/mailman/tests/test_security_mgr.py +++ /dev/null @@ -1,241 +0,0 @@ -# Copyright (C) 2001-2011 by the Free Software Foundation, Inc. -# -# This file is part of GNU Mailman. -# -# GNU Mailman is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free -# Software Foundation, either version 3 of the License, or (at your option) -# any later version. -# -# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along with -# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. - -"""Unit tests for the SecurityManager module.""" - -from __future__ import absolute_import, unicode_literals - -__metaclass__ = type -__all__ = [ - 'test_suite', - ] - - -import os -import errno -import unittest - -# Don't use cStringIO because we're going to inherit -from StringIO import StringIO - -from mailman import Utils -from mailman import passwords -from mailman.config import config - - - -def password(cleartext): - return passwords.make_secret(cleartext, passwords.Schemes.ssha) - - - -class TestSecurityManager(unittest.TestCase): - def test_init_vars(self): - eq = self.assertEqual - eq(self._mlist.mod_password, None) - eq(self._mlist.passwords, {}) - - def test_auth_context_info_authuser(self): - mlist = self._mlist - self.assertRaises(TypeError, mlist.AuthContextInfo, config.AuthUser) - # Add a member - mlist.addNewMember('aperson@dom.ain', password='xxXXxx') - self.assertEqual( - mlist.AuthContextInfo(config.AuthUser, 'aperson@dom.ain'), - ('_xtest%40example.com+user+aperson--at--dom.ain', 'xxXXxx')) - - def test_auth_context_moderator(self): - mlist = self._mlist - mlist.mod_password = 'yyYYyy' - self.assertEqual( - mlist.AuthContextInfo(config.AuthListModerator), - ('_xtest%40example.com+moderator', 'yyYYyy')) - - def test_auth_context_admin(self): - mlist = self._mlist - mlist.password = 'zzZZzz' - self.assertEqual( - mlist.AuthContextInfo(config.AuthListAdmin), - ('_xtest%40example.com+admin', 'zzZZzz')) - - def test_auth_context_site(self): - mlist = self._mlist - mlist.password = 'aaAAaa' - self.assertEqual( - mlist.AuthContextInfo(config.AuthSiteAdmin), - ('_xtest%40example.com+admin', 'aaAAaa')) - - def test_auth_context_huh(self): - self.assertEqual( - self._mlist.AuthContextInfo('foo'), - (None, None)) - - - -class TestAuthenticate(unittest.TestCase): - def setUp(self): - Utils.set_global_password('bbBBbb', siteadmin=True) - Utils.set_global_password('ccCCcc', siteadmin=False) - - def tearDown(self): - try: - os.unlink(config.SITE_PW_FILE) - except OSError, e: - if e.errno <> errno.ENOENT: - raise - try: - os.unlink(config.LISTCREATOR_PW_FILE) - except OSError, e: - if e.errno <> errno.ENOENT: - raise - - def test_auth_creator(self): - self.assertEqual(self._mlist.Authenticate( - [config.AuthCreator], 'ccCCcc'), config.AuthCreator) - - def test_auth_creator_unauth(self): - self.assertEqual(self._mlist.Authenticate( - [config.AuthCreator], 'xxxxxx'), config.UnAuthorized) - - def test_auth_site_admin(self): - self.assertEqual(self._mlist.Authenticate( - [config.AuthSiteAdmin], 'bbBBbb'), config.AuthSiteAdmin) - - def test_auth_site_admin_unauth(self): - self.assertEqual(self._mlist.Authenticate( - [config.AuthSiteAdmin], 'xxxxxx'), config.UnAuthorized) - - def test_list_admin(self): - self._mlist.password = password('ttTTtt') - self.assertEqual(self._mlist.Authenticate( - [config.AuthListAdmin], 'ttTTtt'), config.AuthListAdmin) - - def test_list_admin_unauth(self): - self._mlist.password = password('ttTTtt') - self.assertEqual(self._mlist.Authenticate( - [config.AuthListAdmin], 'xxxxxx'), config.UnAuthorized) - - def test_list_moderator(self): - self._mlist.mod_password = password('mmMMmm') - self.assertEqual(self._mlist.Authenticate( - [config.AuthListModerator], 'mmMMmm'), config.AuthListModerator) - - def test_user(self): - mlist = self._mlist - mlist.addNewMember('aperson@dom.ain', password=password('nosrepa')) - self.assertEqual(mlist.Authenticate( - [config.AuthUser], 'nosrepa', 'aperson@dom.ain'), config.AuthUser) - - def test_wrong_user(self): - mlist = self._mlist - mlist.addNewMember('aperson@dom.ain', password='nosrepa') - self.assertEqual( - mlist.Authenticate([config.AuthUser], 'nosrepa', 'bperson@dom.ain'), - config.UnAuthorized) - - def test_no_user(self): - mlist = self._mlist - mlist.addNewMember('aperson@dom.ain', password='nosrepa') - self.assertEqual(mlist.Authenticate([config.AuthUser], 'norespa'), - config.UnAuthorized) - - def test_user_unauth(self): - mlist = self._mlist - mlist.addNewMember('aperson@dom.ain', password='nosrepa') - self.assertEqual(mlist.Authenticate( - [config.AuthUser], 'xxxxxx', 'aperson@dom.ain'), - config.UnAuthorized) - - def test_value_error(self): - self.assertRaises(ValueError, self._mlist.Authenticate, - ['spooge'], 'xxxxxx', 'zperson@dom.ain') - - - -class StripperIO(StringIO): - HEAD = 'Set-Cookie: ' - def write(self, s): - if s.startswith(self.HEAD): - s = s[len(self.HEAD):] - StringIO.write(self, s) - - -class TestWebAuthenticate(unittest.TestCase): - def setUp(self): - Utils.set_global_password('bbBBbb', siteadmin=True) - Utils.set_global_password('ccCCcc', siteadmin=False) - mlist = self._mlist - mlist.mod_password = password('abcdefg') - mlist.addNewMember('aperson@dom.ain', password='qqQQqq') - # Set up the cookie data - sfp = StripperIO() - print >> sfp, mlist.MakeCookie(config.AuthSiteAdmin) - # AuthCreator isn't handled in AuthContextInfo() - print >> sfp, mlist.MakeCookie(config.AuthListAdmin) - print >> sfp, mlist.MakeCookie(config.AuthListModerator) - print >> sfp, mlist.MakeCookie(config.AuthUser, 'aperson@dom.ain') - # Strip off the "Set-Cookie: " prefix - cookie = sfp.getvalue() - os.environ['HTTP_COOKIE'] = cookie - - def tearDown(self): - try: - os.unlink(config.SITE_PW_FILE) - except OSError, e: - if e.errno <> errno.ENOENT: - raise - try: - os.unlink(config.LISTCREATOR_PW_FILE) - except OSError, e: - if e.errno <> errno.ENOENT: - raise - del os.environ['HTTP_COOKIE'] - - def test_auth_site_admin(self): - self.failUnless(self._mlist.WebAuthenticate( - [config.AuthSiteAdmin], 'does not matter')) - - def test_list_admin(self): - self.failUnless(self._mlist.WebAuthenticate( - [config.AuthListAdmin], 'does not matter')) - - def test_list_moderator(self): - self.failUnless(self._mlist.WebAuthenticate( - [config.AuthListModerator], 'does not matter')) - - def test_user(self): - self.failUnless(self._mlist.WebAuthenticate( - [config.AuthUser], 'does not matter')) - - def test_not_a_user(self): - self._mlist.removeMember('aperson@dom.ain') - self.failIf(self._mlist.WebAuthenticate( - [config.AuthUser], 'does not matter', 'aperson@dom.ain')) - - - -# TBD: Tests for MakeCookie(), ZapCookie(), CheckCookie() -- although the -# latter is implicitly tested by testing WebAuthenticate() above. - - - -def test_suite(): - suite = unittest.TestSuite() -## suite.addTest(unittest.makeSuite(TestSecurityManager)) -## suite.addTest(unittest.makeSuite(TestAuthenticate)) -## suite.addTest(unittest.makeSuite(TestWebAuthenticate)) - return suite |
