Fix comparison of password types.
session.flush() on models with password type with the coercion listener active raised a TypeError before.
This commit is contained in:
@@ -23,6 +23,11 @@ class Password(object):
|
||||
self.context = weakref.proxy(context)
|
||||
|
||||
def __eq__(self, value):
|
||||
if isinstance(value, Password):
|
||||
# Comparing 2 hashes isn't very useful; but this equality
|
||||
# method breaks otherwise.
|
||||
return value.hash == self.hash
|
||||
|
||||
valid, new = self.context.verify_and_update(value, self.hash)
|
||||
if valid and new:
|
||||
# New hash was calculated due to various reasons; stored one
|
||||
|
@@ -88,3 +88,15 @@ class TestPasswordType(TestCase):
|
||||
|
||||
def test_without_schemes(self):
|
||||
assert PasswordType(schemes=[]).length == 1024
|
||||
|
||||
def test_compare(self):
|
||||
from passlib.hash import md5_crypt
|
||||
|
||||
obj = self.User()
|
||||
obj.password = Password(md5_crypt.encrypt('b'))
|
||||
|
||||
other = self.User()
|
||||
other.password = Password(md5_crypt.encrypt('b'))
|
||||
|
||||
# Not sure what to assert here; the test raised an error before.
|
||||
assert obj.password != other.password
|
||||
|
Reference in New Issue
Block a user