Mercurial > libervia-backend
diff src/test/test_memory_crypto.py @ 1098:77cd312d32c4
memory: fixes encoding issues during encryption
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 06 Jul 2014 21:13:47 +0200 |
parents | cbf917a90784 |
children | 069ad98b360d |
line wrap: on
line diff
--- a/src/test/test_memory_crypto.py Fri Jun 27 20:05:31 2014 +0200 +++ b/src/test/test_memory_crypto.py Sun Jul 06 21:13:47 2014 +0200 @@ -23,10 +23,16 @@ from sat.test import helpers from sat.memory.crypto import BlockCipher, PasswordHasher -from os import urandom +import random +import string from twisted.internet import defer +def getRandomUnicode(len): + """Return a random unicode string""" + return u''.join(random.choice(string.letters + u"éáúóâêûôßüöä") for i in xrange(len)) + + class CryptoTest(helpers.SatTestCase): def setUp(self): @@ -42,9 +48,9 @@ d_list.append(d) for key_len in (0, 2, 8, 10, 16, 24, 30, 32, 40): - key = urandom(key_len) + key = getRandomUnicode(key_len) for message_len in (0, 2, 16, 24, 32, 100): - message = urandom(message_len) + message = getRandomUnicode(message_len) test(key, message) return defer.DeferredList(d_list) @@ -57,7 +63,7 @@ d1 = PasswordHasher.verify(password, hashed) d1.addCallback(lambda result: self.assertTrue(result)) d_list.append(d1) - attempt = urandom(10) + attempt = getRandomUnicode(10) d2 = PasswordHasher.verify(attempt, hashed) d2.addCallback(lambda result: self.assertFalse(result)) d_list.append(d2)