check if hash is a base-16 string

This commit is contained in:
Martin Zimmermann 2013-12-19 08:55:06 +01:00
parent e244227f41
commit 82da63a81b
2 changed files with 3 additions and 2 deletions

View File

@ -170,7 +170,7 @@ class API(object):
max_age=self.conf.getint('max-age')) max_age=self.conf.getint('max-age'))
rv["text"] = markdown(rv["text"]) rv["text"] = markdown(rv["text"])
rv["hash"] = str(pbkdf2(rv['email'] or rv['remote_addr'], self.isso.salt, 1000, 6)) rv["hash"] = pbkdf2(rv['email'] or rv['remote_addr'], self.isso.salt, 1000, 6).decode("utf-8")
self.cache.set('hash', (rv['email'] or rv['remote_addr']).encode('utf-8'), rv['hash']) self.cache.set('hash', (rv['email'] or rv['remote_addr']).encode('utf-8'), rv['hash'])
@ -332,7 +332,7 @@ class API(object):
val = self.cache.get('hash', key.encode('utf-8')) val = self.cache.get('hash', key.encode('utf-8'))
if val is None: if val is None:
val = str(pbkdf2(key, self.isso.salt, 1000, 6)) val = pbkdf2(key, self.isso.salt, 1000, 6).decode("utf-8")
self.cache.set('hash', key.encode('utf-8'), val) self.cache.set('hash', key.encode('utf-8'), val)
item['hash'] = val item['hash'] = val

View File

@ -219,6 +219,7 @@ class TestComments(unittest.TestCase):
b = loads(b.data) b = loads(b.data)
c = loads(c.data) c = loads(c.data)
assert isinstance(int(a['hash'], 16), int)
assert a['hash'] != '192.168.1.1' assert a['hash'] != '192.168.1.1'
assert a['hash'] == b['hash'] assert a['hash'] == b['hash']
assert a['hash'] != c['hash'] assert a['hash'] != c['hash']