PasswordType now falls back to default length (1024) if no schemes were found in crypt context

This commit is contained in:
Konsta Vesterinen
2013-08-18 12:04:25 +03:00
parent 1cf6d2216b
commit 7751fb0035
2 changed files with 4 additions and 2 deletions

View File

@@ -88,7 +88,7 @@ class PasswordType(types.TypeDecorator, ScalarCoercible):
if max_length is None: if max_length is None:
# Calculate the largest possible encoded password. # Calculate the largest possible encoded password.
# name + rounds + salt + hash + ($ * 4) of largest hash # name + rounds + salt + hash + ($ * 4) of largest hash
max_lengths = [] max_lengths = [1024]
for name in self.context.schemes(): for name in self.context.schemes():
scheme = getattr(__import__('passlib.hash').hash, name) scheme = getattr(__import__('passlib.hash').hash, name)
length = 4 + len(scheme.name) length = 4 + len(scheme.name)

View File

@@ -8,7 +8,6 @@ from sqlalchemy_utils import Password, PasswordType
@mark.skipif('password.passlib is None') @mark.skipif('password.passlib is None')
class TestPasswordType(TestCase): class TestPasswordType(TestCase):
def create_models(self): def create_models(self):
class User(self.Base): class User(self.Base):
__tablename__ = 'user' __tablename__ = 'user'
@@ -86,3 +85,6 @@ class TestPasswordType(TestCase):
expected_length += 4 expected_length += 4
assert impl.length == expected_length assert impl.length == expected_length
def test_without_schemes(self):
assert PasswordType(schemes=[]).length == 1024