summaryrefslogtreecommitdiff
path: root/passlib
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2011-07-09 12:28:59 -0400
committerEli Collins <elic@assurancetechnologies.com>2011-07-09 12:28:59 -0400
commit5c1bbb6f4fe1902a554f24e665b6e23ba63ba9de (patch)
treeb5256bb46aaf386019ba6eb9456584acd4608938 /passlib
parent1ad4449dd053d5c19a7a9d432f556c34cd062971 (diff)
downloadpasslib-5c1bbb6f4fe1902a554f24e665b6e23ba63ba9de.tar.gz
bugfixes from running UTs
* typo in safe_os_crypt UT * typo in has_backend UT * typo in HasManyBackends HandlerCase UT * fixed inverted has_backend() test in HasManyBackends.set_backend() * ensure all safe_os_crypt backend checks return boolean * BSDiCrypt - fixed os_crypt backend, was passing incomplete string to os_crypt * workaround for Jython object.__new__() behavior in test 'UnsaltedHash' UT * added passlib.utils.jython_vm flag for detecting jython
Diffstat (limited to 'passlib')
-rw-r--r--passlib/handlers/bcrypt.py13
-rw-r--r--passlib/handlers/des_crypt.py9
-rw-r--r--passlib/handlers/md5_crypt.py4
-rw-r--r--passlib/handlers/sha1_crypt.py2
-rw-r--r--passlib/handlers/sha2_crypt.py14
-rw-r--r--passlib/tests/test_utils.py2
-rw-r--r--passlib/tests/test_utils_handlers.py16
-rw-r--r--passlib/tests/utils.py2
-rw-r--r--passlib/utils/__init__.py1
-rw-r--r--passlib/utils/handlers.py2
10 files changed, 31 insertions, 34 deletions
diff --git a/passlib/handlers/bcrypt.py b/passlib/handlers/bcrypt.py
index a363ab6..44192f6 100644
--- a/passlib/handlers/bcrypt.py
+++ b/passlib/handlers/bcrypt.py
@@ -138,15 +138,10 @@ class bcrypt(uh.HasManyIdents, uh.HasRounds, uh.HasSalt, uh.HasManyBackends, uh.
@classproperty
def _has_backend_os_crypt(cls):
- return (
- safe_os_crypt is not None
- and
- safe_os_crypt(u"test", u"$2a$04$......................")[1] ==
- u'$2a$04$......................qiOQjkB8hxU8OzRhS.GhRMa4VUnkPty'
- and
- safe_os_crypt(u"test", u"$2$04$......................")[1] ==
- u'$2$04$......................1O4gOrCYaqBG3o/4LnT2ykQUt1wbyju'
- )
+ h1 = u'$2$04$......................1O4gOrCYaqBG3o/4LnT2ykQUt1wbyju'
+ h2 = u'$2a$04$......................qiOQjkB8hxU8OzRhS.GhRMa4VUnkPty'
+ return bool(safe_os_crypt and safe_os_crypt(u"test",h1)[1]==h1 and
+ safe_os_crypt(u"test", h2)[1]==h2)
@classmethod
def _no_backends_msg(cls):
diff --git a/passlib/handlers/des_crypt.py b/passlib/handlers/des_crypt.py
index 0cbe7a8..ca095c3 100644
--- a/passlib/handlers/des_crypt.py
+++ b/passlib/handlers/des_crypt.py
@@ -205,7 +205,8 @@ class des_crypt(uh.HasManyBackends, uh.HasSalt, uh.GenericHandler):
@classproperty
def _has_backend_os_crypt(cls):
- return safe_os_crypt and safe_os_crypt(u"test", u"ab")[1] == u'abgOeLfPimXQo'
+ h = u'abgOeLfPimXQo'
+ return bool(safe_os_crypt and safe_os_crypt(u"test",h)[1]==h)
def _calc_checksum_builtin(self, secret):
#gotta do something - no official policy since des-crypt predates unicode
@@ -334,15 +335,15 @@ class bsdi_crypt(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandler
@classproperty
def _has_backend_os_crypt(cls):
h = u'_/...lLDAxARksGCHin.'
- return safe_os_crypt and safe_os_crypt(u"test", h)[1] == h
-
+ return bool(safe_os_crypt and safe_os_crypt(u"test",h)[1]==h)
+
def _calc_checksum_builtin(self, secret):
if isinstance(secret, unicode):
secret = secret.encode("utf-8")
return raw_ext_crypt(secret, self.rounds, self.salt.encode("ascii")).decode("ascii")
def _calc_checksum_os_crypt(self, secret):
- ok, hash = safe_os_crypt(secret, self.salt)
+ ok, hash = safe_os_crypt(secret, self.to_string(native=False))
if ok:
return hash[9:]
else:
diff --git a/passlib/handlers/md5_crypt.py b/passlib/handlers/md5_crypt.py
index 585d478..e5d025a 100644
--- a/passlib/handlers/md5_crypt.py
+++ b/passlib/handlers/md5_crypt.py
@@ -229,8 +229,8 @@ class md5_crypt(uh.HasManyBackends, _Md5Common):
@classproperty
def _has_backend_os_crypt(cls):
- return safe_os_crypt and safe_os_crypt(u"test", u"$1$test")[1] == \
- u'$1$test$pi/xDtU5WFVRqYS6BMU8X/'
+ h = u'$1$test$pi/xDtU5WFVRqYS6BMU8X/'
+ return bool(safe_os_crypt and safe_os_crypt(u"test",h)[1]==h)
def _calc_checksum_builtin(self, secret):
return raw_md5_crypt(secret, self.salt)
diff --git a/passlib/handlers/sha1_crypt.py b/passlib/handlers/sha1_crypt.py
index c99ca69..934f1f8 100644
--- a/passlib/handlers/sha1_crypt.py
+++ b/passlib/handlers/sha1_crypt.py
@@ -105,7 +105,7 @@ class sha1_crypt(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandler
@classproperty
def _has_backend_os_crypt(cls):
h = u'$sha1$1$Wq3GL2Vp$C8U25GvfHS8qGHimExLaiSFlGkAe'
- return safe_os_crypt and safe_os_crypt(u"test", h)[1] == h
+ return bool(safe_os_crypt and safe_os_crypt(u"test",h)[1]==h)
def _calc_checksum_builtin(self, secret):
if isinstance(secret, unicode):
diff --git a/passlib/handlers/sha2_crypt.py b/passlib/handlers/sha2_crypt.py
index 80308a4..2e56419 100644
--- a/passlib/handlers/sha2_crypt.py
+++ b/passlib/handlers/sha2_crypt.py
@@ -327,11 +327,8 @@ class sha256_crypt(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandl
@classproperty
def _has_backend_os_crypt(cls):
- return bool(
- safe_os_crypt and
- safe_os_crypt(u"test", u"$5$rounds=1000$test")[1] ==
- u"$5$rounds=1000$test$QmQADEXMG8POI5WDsaeho0P36yK3Tcrgboabng6bkb/"
- )
+ h = u"$5$rounds=1000$test$QmQADEXMG8POI5WDsaeho0P36yK3Tcrgboabng6bkb/"
+ return bool(safe_os_crypt and safe_os_crypt(u"test",h)[1]==h)
def _calc_checksum_builtin(self, secret):
if isinstance(secret, unicode):
@@ -482,11 +479,8 @@ class sha512_crypt(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandl
@classproperty
def _has_backend_os_crypt(cls):
- return bool(
- safe_os_crypt and
- safe_os_crypt(u"test", u"$6$rounds=1000$test")[1] ==
- u"$6$rounds=1000$test$2M/Lx6MtobqjLjobw0Wmo4Q5OFx5nVLJvmgseatA6oMnyWeBdRDx4DU.1H3eGmse6pgsOgDisWBGI5c7TZauS0"
- )
+ h = u"$6$rounds=1000$test$2M/Lx6MtobqjLjobw0Wmo4Q5OFx5nVLJvmgseatA6oMnyWeBdRDx4DU.1H3eGmse6pgsOgDisWBGI5c7TZauS0"
+ return bool(safe_os_crypt and safe_os_crypt(u"test",h)[1]==h)
#NOTE: testing w/ HashTimer shows 64-bit linux's crypt to be ~2.6x faster than builtin (627253 vs 238152 rounds/sec)
diff --git a/passlib/tests/test_utils.py b/passlib/tests/test_utils.py
index e432ee1..9cb52ef 100644
--- a/passlib/tests/test_utils.py
+++ b/passlib/tests/test_utils.py
@@ -109,7 +109,7 @@ class MiscTest(TestCase):
def test_safe_os_crypt(self):
"test safe_os_crypt() wrapper"
if not safe_os_crypt:
- raise self.SkipTest("stdlib crypt module not available")
+ raise self.skipTest("stdlib crypt module not available")
#NOTE: this is assuming EVERY crypt will support des_crypt.
# if this fails on some platform, this test will need modifying.
diff --git a/passlib/tests/test_utils_handlers.py b/passlib/tests/test_utils_handlers.py
index 30017a9..bc9e10f 100644
--- a/passlib/tests/test_utils_handlers.py
+++ b/passlib/tests/test_utils_handlers.py
@@ -14,7 +14,7 @@ from passlib.hash import ldap_md5
from passlib.registry import _unload_handler_name as unload_handler_name, \
register_crypt_handler, get_crypt_handler
from passlib.utils import rng, getrandstr, handlers as uh, bytes, b, \
- to_hash_str, to_unicode, MissingBackendError
+ to_hash_str, to_unicode, MissingBackendError, jython_vm
from passlib.tests.utils import HandlerCase, TestCase, catch_warnings, \
dummy_handler_in_registry
#module
@@ -224,8 +224,8 @@ class SkeletonTest(TestCase):
#test unavailable
self.assertRaises(MissingBackendError, d1.set_backend, 'a')
- self.assertTrue(d1.has_backend, 'b')
- self.assertFalse(d1.has_backend, 'a')
+ self.assertTrue(d1.has_backend('b'))
+ self.assertFalse(d1.has_backend('a'))
#enable 'a' backend also
d1._has_backend_a = True
@@ -424,11 +424,17 @@ class UnsaltedHashTest(HandlerCase):
known_correct_hashes = [
("password", "61cfd32684c47de231f1f982c214e884133762c0"),
-
]
def test_bad_kwds(self):
- self.assertRaises(TypeError, UnsaltedHash, salt='x')
+ if not jython_vm:
+ #FIXME: annoyingly, the object() constructor of Jython (as of 2.5.2)
+ # silently drops any extra kwds (old 2.4 behavior)
+ # instead of raising TypeError (new 2.5 behavior).
+ # we *could* use a custom base object to restore correct
+ # behavior, but that's a lot of effort for a non-critical
+ # border case. so just skipping this test instead...
+ self.assertRaises(TypeError, UnsaltedHash, salt='x')
self.assertRaises(ValueError, SaltedHash, checksum=SaltedHash._stub_checksum, salt=None, strict=True)
self.assertRaises(ValueError, SaltedHash, checksum=SaltedHash._stub_checksum, salt='xxx', strict=True)
diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py
index 611f17d..908efe0 100644
--- a/passlib/tests/utils.py
+++ b/passlib/tests/utils.py
@@ -555,7 +555,7 @@ class HandlerCase(TestCase):
try:
#run through all backends handler supports
for backend in h.backends:
- self.assertFalse(backend in RESERVED_BACKEND_NAMES,
+ self.assertFalse(backend in self.RESERVED_BACKEND_NAMES,
"invalid backend name: %r" % (backend,))
#check has_backend() returns bool value
r = h.has_backend(backend)
diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py
index acfdf1b..3b085a7 100644
--- a/passlib/utils/__init__.py
+++ b/passlib/utils/__init__.py
@@ -60,6 +60,7 @@ __all__ = [
#: detect what we're running on
pypy_vm = hasattr(sys, "pypy_version_info")
+jython_vm = sys.platform.startswith('java')
#: number of bits in system architecture
sys_bits = int(logb(sys.maxint,2)+1.5)
diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py
index 92e8339..22a229d 100644
--- a/passlib/utils/handlers.py
+++ b/passlib/utils/handlers.py
@@ -1114,7 +1114,7 @@ class HasManyBackends(GenericHandler):
break
else:
raise MissingBackendError(cls._no_backends_msg())
- elif cls.has_backend(name):
+ elif not cls.has_backend(name):
raise MissingBackendError("%s backend not available: %r" % (cls.name, name))
cls.calc_checksum = getattr(cls, "_calc_checksum_" + name)
cls._backend = name