def test_custom_password_class(self):
from boto.utils import Password
from boto.sdb.db.model import Model
from boto.sdb.db.property import PasswordProperty
import hmac, hashlib
myhashfunc = hashlib.md5
## Define a new Password class
class MyPassword(Password):
hashfunc = myhashfunc #hashlib.md5 #lambda cls,msg: hmac.new('mysecret',msg)
## Define a custom password property using the new Password class
class MyPasswordProperty(PasswordProperty):
data_type=MyPassword
type_name=MyPassword.__name__
## Define a model using the new password property
class MyModel(Model):
password=MyPasswordProperty()#hashfunc=hashlib.md5)
obj = MyModel()
obj.password = 'bar'
expected = myhashfunc('bar').hexdigest() #hmac.new('mysecret','bar').hexdigest()
log.debug("\npassword=%s\nexpected=%s" % (obj.password, expected))
self.assertTrue(obj.password == 'bar' )
obj.save()
id= obj.id
time.sleep(5)
obj = MyModel.get_by_id(id)
self.assertEquals(obj.password, 'bar')
self.assertEquals(str(obj.password), expected)
#hmac.new('mysecret','bar').hexdigest())
评论列表
文章目录