summaryrefslogtreecommitdiff
path: root/passlib/tests
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2012-04-10 16:10:05 -0400
committerEli Collins <elic@assurancetechnologies.com>2012-04-10 16:10:05 -0400
commit157d4806512b2586c1a0fd5ee57e8c167e506f3e (patch)
treea7491056a7b51d93d17c5d3521383457d5638c07 /passlib/tests
parent75758ab6138a01ef58d75a0b4cb4c172248d9d8e (diff)
downloadpasslib-157d4806512b2586c1a0fd5ee57e8c167e506f3e.tar.gz
replaced some common string ops with util funcs (repeat_string, right_pad_string)
Diffstat (limited to 'passlib/tests')
-rw-r--r--passlib/tests/test_handlers.py9
-rw-r--r--passlib/tests/utils.py6
2 files changed, 7 insertions, 8 deletions
diff --git a/passlib/tests/test_handlers.py b/passlib/tests/test_handlers.py
index 8a119a2..aaa114b 100644
--- a/passlib/tests/test_handlers.py
+++ b/passlib/tests/test_handlers.py
@@ -10,10 +10,10 @@ import warnings
#site
#pkg
from passlib import hash
-from passlib.utils.compat import irange, PY3
+from passlib.utils import repeat_string
+from passlib.utils.compat import irange, PY3, u
from passlib.tests.utils import TestCase, HandlerCase, create_backend_case, \
enable_option, b, catch_warnings, UserHandlerMixin, randintgauss
-from passlib.utils.compat import u
#module
#=========================================================
@@ -238,9 +238,8 @@ class _bcrypt_test(HandlerCase):
# using the $2a$ algorithm, by repeating the password until
# it's 72 chars in length.
hash = "$2a$" + hash[3:]
- ss = len(secret)
- if 0 < ss < 72:
- secret = secret * (1+72//ss)
+ if secret:
+ secret = repeat_string(secret, 72)
return Engine(False).hash_key(secret, hash) == hash
verifiers.append(check_bcryptor)
diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py
index 6dedc3d..b7dce87 100644
--- a/passlib/tests/utils.py
+++ b/passlib/tests/utils.py
@@ -39,7 +39,8 @@ if ut_version < 2:
from passlib.exc import MissingBackendError
import passlib.registry as registry
from passlib.utils import has_rounds_info, has_salt_info, rounds_cost_values, \
- classproperty, rng, getrandstr, is_ascii_safe, to_native_str
+ classproperty, rng, getrandstr, is_ascii_safe, to_native_str, \
+ repeat_string
from passlib.utils.compat import b, bytes, iteritems, irange, callable, \
sb_types, exc_err, u, unicode
import passlib.utils.handlers as uh
@@ -1148,8 +1149,7 @@ class HandlerCase(TestCase):
# hash only counts the first <sc> characters; eg: bcrypt, des-crypt
# create & hash string that's exactly sc+1 chars
- secret = (base * (1+sc//16))[:sc+1]
- assert len(secret) == sc+1
+ secret = repeat_string(base, sc+1)
hash = self.do_encrypt(secret)
# check sc value isn't too large by verifying that sc-1'th char