summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2012-02-08 22:41:37 -0500
committerEli Collins <elic@assurancetechnologies.com>2012-02-08 22:41:37 -0500
commit098f270258d6991ec0c74b63783cc0fcf3eecab9 (patch)
tree7d13fd1fe3a90b511cfd5eea6861f38059b0dfd9
parent86a2dc3ed68fcdf7853f5e219541a19b5fcacfff (diff)
downloadpasslib-098f270258d6991ec0c74b63783cc0fcf3eecab9.tar.gz
minor tweaks & fixes
-rw-r--r--passlib/handlers/sha2_crypt.py8
-rw-r--r--passlib/registry.py2
-rw-r--r--passlib/tests/test_handlers.py6
-rw-r--r--passlib/tests/utils.py8
-rw-r--r--passlib/utils/handlers.py2
5 files changed, 14 insertions, 12 deletions
diff --git a/passlib/handlers/sha2_crypt.py b/passlib/handlers/sha2_crypt.py
index c1d782c..bce7980 100644
--- a/passlib/handlers/sha2_crypt.py
+++ b/passlib/handlers/sha2_crypt.py
@@ -317,10 +317,12 @@ class sha256_crypt(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandl
)
def to_string(self):
- if self.rounds == 5000 and self.implicit_rounds:
- hash = u("$5$%s$%s") % (self.salt, self.checksum or u(''))
+ chk = self.checksum or u('')
+ rounds = self.rounds
+ if rounds == 5000 and self.implicit_rounds:
+ hash = u("$5$%s$%s") % (self.salt, chk)
else:
- hash = u("$5$rounds=%d$%s$%s") % (self.rounds, self.salt, self.checksum or u(''))
+ hash = u("$5$rounds=%d$%s$%s") % (rounds, self.salt, chk)
return uascii_to_str(hash)
#=========================================================
diff --git a/passlib/registry.py b/passlib/registry.py
index 4a61d76..50fb595 100644
--- a/passlib/registry.py
+++ b/passlib/registry.py
@@ -259,7 +259,7 @@ def register_crypt_handler(handler, force=False, name=None):
#register handler in dict
_handlers[name] = handler
- log.info("registered crypt handler %r: %r", name, handler)
+ log.debug("registered crypt handler %r: %r", name, handler)
_NOTSET = object()
diff --git a/passlib/tests/test_handlers.py b/passlib/tests/test_handlers.py
index 98a741f..5c94b73 100644
--- a/passlib/tests/test_handlers.py
+++ b/passlib/tests/test_handlers.py
@@ -1373,8 +1373,7 @@ class _SHA256CryptTest(HandlerCase):
"2bIC" ),
]
- def filter_known_config_warnings(self):
- warnings.filterwarnings("ignore", "sha256_crypt does not allow less than 1000 rounds: 10", UserWarning)
+ filter_config_warnings = True # rounds too low, salt too small
def test_raw(self):
#run some tests on raw backend func to ensure it works right
@@ -1447,8 +1446,7 @@ class _SHA512CryptTest(HandlerCase):
"hLsPuWGsUSklZt58jaTfF4ZEQpyUNGc0dqbpBYYBaHHrsX." ),
]
- def filter_known_config_warnings(self):
- warnings.filterwarnings("ignore", "sha512_crypt does not allow less than 1000 rounds: 10", UserWarning)
+ filter_config_warnings = True # rounds too low, salt too small
OsCrypt_SHA512CryptTest = create_backend_case(_SHA512CryptTest, "os_crypt")
Builtin_SHA512CryptTest = create_backend_case(_SHA512CryptTest, "builtin")
diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py
index a89e707..92e601e 100644
--- a/passlib/tests/utils.py
+++ b/passlib/tests/utils.py
@@ -912,17 +912,17 @@ class HandlerCase(TestCase):
#=========================================================
#genhash()
#=========================================================
- filter_known_config_warnings = None
+ filter_config_warnings = False
def test_40_genhash_config(self):
"test genhash() against known config strings"
if not self.known_correct_configs:
raise self.skipTest("no config strings provided")
- fk = self.filter_known_config_warnings
+ fk = self.filter_config_warnings
if fk:
ctx = catch_warnings()
ctx.__enter__()
- fk()
+ warnings.filterwarnings("ignore", category=PasslibHandlerWarning)
for config, secret, hash in self.known_correct_configs:
result = self.do_genhash(secret, config)
self.assertEqual(result, hash, "config=%r,secret=%r:" % (config,secret))
@@ -1022,6 +1022,8 @@ class HandlerCase(TestCase):
# generate a single hash, and verify it using all helpers.
secret = b('t\xc3\xa1\xd0\x91\xe2\x84\x93\xc9\x99').decode("utf-8")
hash = self.do_encrypt(secret)
+ if PY2 and isinstance(secret, unicode):
+ secret = secret.encode("utf-8")
for helper in helpers:
helper(secret, hash)
diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py
index fcbfdb7..9adc03b 100644
--- a/passlib/utils/handlers.py
+++ b/passlib/utils/handlers.py
@@ -1043,7 +1043,7 @@ class HasRounds(GenericHandler):
def _clear_backend(cls):
"restore HasManyBackend subclass to unloaded state - used by unittests"
- assert isinstance(cls, HasManyBackends)
+ assert issubclass(cls, HasManyBackends) and cls is not HasManyBackends
if cls._backend:
del cls._backend
del cls.calc_checksum