cubicweb/test/unittest_crypto.py
author Jérémy Bobbio <jeremy.bobbio@irq7.fr>
Wed, 19 Jun 2019 18:43:38 +0200
changeset 12682 da36da3f89f1
parent 12615 7abe23cbfda1
permissions -rw-r--r--
[tests] Use 16 bytes key when testing Blowfish The version of Cryptodome currently in Debian only accepts Blowfish keys with at least 5 bytes. This is a bug (it should accept 4 as it did before) that has since been fixed upstream: https://github.com/Legrandin/pycryptodome/commit/93912230f3c39e09f4038cb17e301468687c6538 So we work around this issue by using a 16 bytes key instead (which happens to be the minimum recommended length).

from unittest import TestCase

from cubicweb import crypto


class CryptoTC(TestCase):

    def test_encrypt_decrypt_roundtrip(self):
        data = {'a': u'ah', 'b': [1, 2]}
        seed = 's' * 16
        crypted = crypto.encrypt(data, seed)
        decrypted = crypto.decrypt(crypted, seed)
        self.assertEqual(decrypted, data)


if __name__ == '__main__':
    import unittest
    unittest.main()