Modify

Opened 10 years ago

Closed 8 years ago

#12192 closed defect (fixed)

[PATCH] test suite failures with trac 1.0.x

Reported by: paul@… Owned by: Ryan J Ollos
Priority: normal Component: AccountManagerPlugin
Severity: normal Keywords:
Cc: Trac Release: 1.0

Description

Didn't see this with older trac versions:

$ python setup.py test
running test
running egg_info
writing requirements to TracAccountManager.egg-info/requires.txt
writing TracAccountManager.egg-info/PKG-INFO
writing top-level names to TracAccountManager.egg-info/top_level.txt
writing dependency_links to TracAccountManager.egg-info/dependency_links.txt
writing entry points to TracAccountManager.egg-info/entry_points.txt
reading manifest file 'TracAccountManager.egg-info/SOURCES.txt'
writing manifest file 'TracAccountManager.egg-info/SOURCES.txt'
running build_ext
test_available_actions (acct_mgr.tests.api.PermissionTestCase) ... ok
test_available_actions_config_admin (acct_mgr.tests.api.PermissionTestCase) ... ok
test_available_actions_full_perms (acct_mgr.tests.api.PermissionTestCase) ... ok
test_available_actions_no_perms (acct_mgr.tests.api.PermissionTestCase) ... ok
test_available_actions_user_admin (acct_mgr.tests.api.PermissionTestCase) ... ok
test_create_user (acct_mgr.tests.db.HtDigestTestCase) ... ok
test_delete_nonexistant_user (acct_mgr.tests.db.HtDigestTestCase) ... ok
test_delete_user (acct_mgr.tests.db.HtDigestTestCase) ... ok
test_get_users (acct_mgr.tests.db.HtDigestTestCase) ... ok
test_has_user (acct_mgr.tests.db.HtDigestTestCase) ... ok
test_unicode_username_and_password (acct_mgr.tests.db.HtDigestTestCase) ... ok
test_update_password (acct_mgr.tests.db.HtDigestTestCase) ... ok
test_create_user (acct_mgr.tests.db.HtPasswdTestCase) ... ok
test_delete_nonexistant_user (acct_mgr.tests.db.HtPasswdTestCase) ... ok
test_delete_user (acct_mgr.tests.db.HtPasswdTestCase) ... ok
test_get_users (acct_mgr.tests.db.HtPasswdTestCase) ... ok
test_has_user (acct_mgr.tests.db.HtPasswdTestCase) ... ok
test_unicode_username_and_password (acct_mgr.tests.db.HtPasswdTestCase) ... ok
test_update_password (acct_mgr.tests.db.HtPasswdTestCase) ... ok
test_file (acct_mgr.tests.htfile.HtDigestTestCase) ... ok
test_unicode (acct_mgr.tests.htfile.HtDigestTestCase) ... ok
test_update_password (acct_mgr.tests.htfile.HtDigestTestCase) ... ok
test_userline (acct_mgr.tests.htfile.HtDigestTestCase) ... ok
test_add_with_no_trailing_newline (acct_mgr.tests.htfile.HtPasswdTestCase) ... ok
test_create_hash (acct_mgr.tests.htfile.HtPasswdTestCase) ... ok
test_crypt (acct_mgr.tests.htfile.HtPasswdTestCase) ... ok
test_md5 (acct_mgr.tests.htfile.HtPasswdTestCase) ... ok
test_no_trailing_newline (acct_mgr.tests.htfile.HtPasswdTestCase) ... ok
test_sha (acct_mgr.tests.htfile.HtPasswdTestCase) ... ok
test_sha256 (acct_mgr.tests.htfile.HtPasswdTestCase) ... ok
test_sha512 (acct_mgr.tests.htfile.HtPasswdTestCase) ... ok
test_unicode (acct_mgr.tests.htfile.HtPasswdTestCase) ... ok
test_update_password (acct_mgr.tests.htfile.HtPasswdTestCase) ... ok
test_bad_check (acct_mgr.tests.register.DummyRegInspectorTestCase) ... ok
test_check_error (acct_mgr.tests.register.DummyRegInspectorTestCase) ... ok
test_dummy_check (acct_mgr.tests.register.DummyRegInspectorTestCase) ... ok
test_check (acct_mgr.tests.register.BasicCheckTestCase) ... ERROR
test_check (acct_mgr.tests.register.BotTrapCheckTestCase) ... ok
test_verify_conf_changes (acct_mgr.tests.register.EmailCheckTestCase)
Registration challenges with EmailVerificationModule enabled. ... ERROR
test_verify_mod_disabled (acct_mgr.tests.register.EmailCheckTestCase)
Registration challenges with EmailVerificationModule disabled. ... ok
test_check (acct_mgr.tests.register.RegExpCheckTestCase) ... ok
test_check (acct_mgr.tests.register.UsernamePermCheckTestCase) ... ok
test_checks (acct_mgr.tests.register.RegistrationModuleTestCase) ... ok
test_mandatory_email_registration (acct_mgr.tests.register.RegistrationModuleTestCase) ... ok
test_optional_email_registration (acct_mgr.tests.register.RegistrationModuleTestCase) ... ok
test_check (acct_mgr.tests.register.EmailVerificationModuleTestCase) ... ok
test_check_email_used (acct_mgr.tests.register.EmailVerificationModuleTestCase) ... ok
test_check_no_email (acct_mgr.tests.register.EmailVerificationModuleTestCase) ... ok

======================================================================
ERROR: test_check (acct_mgr.tests.register.BasicCheckTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/TracAccountManager-0.4.4/acct_mgr/tests/register.py", line 131, in test_check
    self.assertRaises(RegistrationError, check.validate_registration, req)
  File "/usr/lib64/python2.7/unittest/case.py", line 511, in assertRaises
    callableObj(*args, **kwargs)
  File "/builddir/build/BUILD/TracAccountManager-0.4.4/acct_mgr/register.py", line 136, in validate_registration
    for store_user in acctmgr.get_users():
  File "/builddir/build/BUILD/TracAccountManager-0.4.4/acct_mgr/api.py", line 220, in get_users
    for store in self._password_store:
  File "/usr/lib/python2.7/site-packages/trac/config.py", line 779, in __get__
    option=tag.tt("[%s] %s" % (self.section, self.name))))
ConfigurationError: Cannot find implementation(s) of the <tt>IPasswordStore</tt> interface named <tt>SessionStore</tt>. Please check that the Component is enabled or update the option <tt>[account-manager] password_store</tt> in trac.ini.

======================================================================
ERROR: test_verify_conf_changes (acct_mgr.tests.register.EmailCheckTestCase)
Registration challenges with EmailVerificationModule enabled.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/TracAccountManager-0.4.4/acct_mgr/tests/register.py", line 214, in test_verify_conf_changes
    field_res = check.render_registration_fields(req, acct)
  File "/builddir/build/BUILD/TracAccountManager-0.4.4/acct_mgr/register.py", line 233, in render_registration_fields
    reset_password = AccountModule(self.env).reset_password_enabled
  File "/builddir/build/BUILD/TracAccountManager-0.4.4/acct_mgr/web_ui.py", line 144, in _reset_password_enabled
    self.store.hash_method
  File "/usr/lib/python2.7/site-packages/trac/config.py", line 741, in __get__
    option=tag.tt("[%s] %s" % (self.section, self.name))))
ConfigurationError: Cannot find an implementation of the <tt>IPasswordHashMethod</tt> interface named <tt>HtDigestHashMethod</tt>. Please check that the Component is enabled or update the option <tt>[account-manager] hash_method</tt> in trac.ini.

----------------------------------------------------------------------
Ran 48 tests in 0.717s

FAILED (errors=2)

I'll attach a patch I've used that resolves this problem for me.

Attachments (1)

TracAccountManager-0.4.4-tests.patch (1.0 KB) - added by paul@… 10 years ago.
Patch that fixes test failures

Download all attachments as: .zip

Change History (10)

Changed 10 years ago by paul@…

Patch that fixes test failures

comment:1 in reply to:  description Changed 10 years ago by Ryan J Ollos

Replying to paul@…:

Didn't see this with older trac versions:

The failures likely started with trac:milestone:1.0.2, due to implementation of trac:#10285.

Thanks for the patch.

comment:2 Changed 9 years ago by Ryan J Ollos

In 14909:

0.5dev: Make test pass with Trac 1.0.9.

Refs #12192.

comment:3 Changed 9 years ago by Ryan J Ollos

I still see a few test failures on OSX:

test_obfuscate_shared_secret (acct_mgr.opt.tests.radius.RadiusAuthTestCase) ... ok
test_update_password (acct_mgr.opt.tests.radius.RadiusAuthTestCase) ... ok

======================================================================
ERROR: test_create_hash (acct_mgr.tests.htfile.HtPasswdTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/rjollos/acct-mgr-eval/accountmanagerplugin-trunk2/acct_mgr/tests/htfile.py", line 184, in test_create_hash
    self.assertTrue(self.store.userline('user', 'password'
  File "/Users/rjollos/acct-mgr-eval/accountmanagerplugin-trunk2/acct_mgr/htfile.py", line 211, in userline
    return self.prefix(user) + mkhtpasswd(password, self.hash_type)
  File "/Users/rjollos/acct-mgr-eval/accountmanagerplugin-trunk2/acct_mgr/pwhash.py", line 141, in mkhtpasswd
    return htpasswd(password, salt_)
  File "/Users/rjollos/acct-mgr-eval/accountmanagerplugin-trunk2/acct_mgr/pwhash.py", line 126, in htpasswd
    available."""))
NotImplementedError: Neither are "sha2" hash algorithms supported by the
                    "crypt" module on this platform nor is "passlib"
                    available.

======================================================================
FAIL: test_sha256 (acct_mgr.tests.htfile.HtPasswdTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/rjollos/acct-mgr-eval/accountmanagerplugin-trunk2/acct_mgr/tests/htfile.py", line 130, in test_sha256
    'user:$5$saltsaltsaltsalt$'
  File "/Users/rjollos/acct-mgr-eval/accountmanagerplugin-trunk2/acct_mgr/tests/htfile.py", line 52, in _do_password_test
    self.assertTrue(self.store.check_password('user', 'password'))
AssertionError: None is not true

======================================================================
FAIL: test_sha512 (acct_mgr.tests.htfile.HtPasswdTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/rjollos/acct-mgr-eval/accountmanagerplugin-trunk2/acct_mgr/tests/htfile.py", line 135, in test_sha512
    'user:$6$saltsaltsaltsalt$'
  File "/Users/rjollos/acct-mgr-eval/accountmanagerplugin-trunk2/acct_mgr/tests/htfile.py", line 52, in _do_password_test
    self.assertTrue(self.store.check_password('user', 'password'))
AssertionError: None is not true

----------------------------------------------------------------------
Ran 78 tests in 2.437s

FAILED (failures=2, errors=1)

comment:4 Changed 9 years ago by Ryan J Ollos

After installing passlib the following errors are seen:

test_update_password (acct_mgr.opt.tests.radius.RadiusAuthTestCase) ... ok

======================================================================
ERROR: test_create_hash (acct_mgr.tests.htfile.HtPasswdTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/rjollos/temp/trunk2/acct_mgr/tests/htfile.py", line 184, in test_create_hash
    self.assertTrue(self.store.userline('user', 'password'
  File "/Users/rjollos/temp/trunk2/acct_mgr/htfile.py", line 211, in userline
    return self.prefix(user) + mkhtpasswd(password, self.hash_type)
  File "/Users/rjollos/temp/trunk2/acct_mgr/pwhash.py", line 146, in mkhtpasswd
    return htpasswd(password, salt_)
  File "/Users/rjollos/temp/trunk2/acct_mgr/pwhash.py", line 130, in htpasswd
    available."""))
NotImplementedError: Neither are "sha2" hash algorithms supported by the
                    "crypt" module on this platform nor is "passlib"
                    available.

======================================================================
FAIL: test_sha256 (acct_mgr.tests.htfile.HtPasswdTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/rjollos/temp/trunk2/acct_mgr/tests/htfile.py", line 130, in test_sha256
    'user:$5$saltsaltsaltsalt$'
  File "/Users/rjollos/temp/trunk2/acct_mgr/tests/htfile.py", line 52, in _do_password_test
    self.assertTrue(self.store.check_password('user', 'password'))
AssertionError: None is not true

======================================================================
FAIL: test_sha512 (acct_mgr.tests.htfile.HtPasswdTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/rjollos/temp/trunk2/acct_mgr/tests/htfile.py", line 135, in test_sha512
    'user:$6$saltsaltsaltsalt$'
  File "/Users/rjollos/temp/trunk2/acct_mgr/tests/htfile.py", line 52, in _do_password_test
    self.assertTrue(self.store.check_password('user', 'password'))
AssertionError: None is not true

----------------------------------------------------------------------
Ran 78 tests in 2.513s

FAILED (failures=2, errors=1)

comment:5 Changed 9 years ago by Ryan J Ollos

For the case that passlib is installed, I think the following patch would be backwards-compatible, but I need to do more testing before committing.

  • acct_mgr/pwhash.py

     
    99#
    1010# Author: Matthew Good <trac@matt-good.net>
    1111
     12import re
     13
    1214from binascii import hexlify
    1315from os import urandom
    1416
     
    103105
    104106
    105107def htpasswd(password, hash):
     108    def from_hash(hash):
     109        match = re.match(r'\$[5,6]\$(?:rounds=(\d+)\$)?(\w+)', hash)
     110        groups = match.groups()
     111        rounds = int(groups[0]) if groups[0] is not None else 5000
     112        salt = groups[1]
     113        return rounds, salt
    106114    if hash.startswith('$apr1$'):
    107115        return md5crypt(password, hash[6:].split('$')[0], '$apr1$')
    108116    elif hash.startswith('{SHA}'):
    109117        return '{SHA}' + sha1(password).digest().encode('base64')[:-1]
    110118    elif passlib_ctxt is not None and hash.startswith('$5$') and \
    111119            'sha256_crypt' in passlib_ctxt.policy.schemes():
    112         return passlib_ctxt.encrypt(password, scheme="sha256_crypt",
    113                                     rounds=5000, salt=hash[3:].split('$')[0])
     120        rounds, salt = from_hash(hash)
     121        return passlib_ctxt.encrypt(password, scheme='sha256_crypt',
     122                                    rounds=rounds, salt=salt)
    114123    elif passlib_ctxt is not None and hash.startswith('$6$') and \
    115124            'sha512_crypt' in passlib_ctxt.policy.schemes():
    116         return passlib_ctxt.encrypt(password, scheme="sha512_crypt",
    117                                     rounds=5000, salt=hash[3:].split('$')[0])
     125        rounds, salt = from_hash(hash)
     126        return passlib_ctxt.encrypt(password, scheme='sha512_crypt',
     127                                    rounds=rounds, salt=salt)
    118128    elif crypt is None:
    119129        # crypt passwords are only supported on Unix-like systems
    120130        raise NotImplementedError(_("The \"crypt\" module is unavailable "
  • acct_mgr/tests/htfile.py

     
    127127
    128128    def test_sha256(self):
    129129        self._do_password_test(self.flavor, 'test_sha256',
    130                                'user:$5$saltsaltsaltsalt$'
    131                                'WsFBeg1qQ90JL3VkUTuM7xVV/5njhLngIVm6ftSnBR2\n')
     130                               'user:$5$rounds=535000$saltsaltsaltsalt$wfx'
     131                               '3LZ09XA7qrZB.ttuCbBidMXt51Kgu5YQ.YFqzxA7\n')
    132132
    133133    def test_sha512(self):
    134134        self._do_password_test(self.flavor, 'test_sha512',
    135                                'user:$6$saltsaltsaltsalt$'
    136                                'bcXJ8qxwY5sQ4v8MTl.0B1jeZ0z0JlA9jjmbUoCJZ.1'
    137                                'wYXiLTU.q2ILyrDJLm890lyfuF7sWAeli0yjOyFPkf0\n')
     135                               'user:$6$rounds=535000$saltsaltsaltsalt$'
     136                               '9ExQK2S3YXW7/FlfUcw2vy7WF.NH5ZF6SIT14DjngOGkc'
     137                               'x.5mINko67cLRrqFFh1AltOT4uPnET7BsJXuI56H/\n')
    138138
    139139    def test_no_trailing_newline(self):
    140140        self._do_password_test(self.flavor, 'test_no_trailing_newline',

comment:6 Changed 9 years ago by Ryan J Ollos

In 15611:

0.5dev: Skip tests when sha256 and sha512 not available

Refs #12192.

comment:7 Changed 9 years ago by Ryan J Ollos

Owner: changed from Steffen Hoffmann to Ryan J Ollos
Status: newaccepted

comment:8 Changed 8 years ago by Ryan J Ollos

In 15612:

0.5dev: Parse rounds from the hash

This fixes unit test failures on OSX, for which rounds defaults
to 535000 if not specified.

Refs #12192.

comment:9 Changed 8 years ago by Ryan J Ollos

Resolution: fixed
Status: acceptedclosed

All unit tests are passing for me on OSX. Please reply or open a new ticket if test failures are seen on other platforms.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.