Mercurial > libervia-backend
comparison sat/test/test_memory_crypto.py @ 4037:524856bd7b19
massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.
However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.
To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.
This is a massive change, and may result in some bugs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | 559a625a236b |
children |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
26 import random | 26 import random |
27 import string | 27 import string |
28 from twisted.internet import defer | 28 from twisted.internet import defer |
29 | 29 |
30 | 30 |
31 def getRandomUnicode(len): | 31 def get_random_unicode(len): |
32 """Return a random unicode string""" | 32 """Return a random unicode string""" |
33 return "".join(random.choice(string.letters + "éáúóâêûôßüöä") for i in range(len)) | 33 return "".join(random.choice(string.letters + "éáúóâêûôßüöä") for i in range(len)) |
34 | 34 |
35 | 35 |
36 class CryptoTest(helpers.SatTestCase): | 36 class CryptoTest(helpers.SatTestCase): |
45 d.addCallback(lambda ciphertext: BlockCipher.decrypt(key, ciphertext)) | 45 d.addCallback(lambda ciphertext: BlockCipher.decrypt(key, ciphertext)) |
46 d.addCallback(lambda decrypted: self.assertEqual(message, decrypted)) | 46 d.addCallback(lambda decrypted: self.assertEqual(message, decrypted)) |
47 d_list.append(d) | 47 d_list.append(d) |
48 | 48 |
49 for key_len in (0, 2, 8, 10, 16, 24, 30, 32, 40): | 49 for key_len in (0, 2, 8, 10, 16, 24, 30, 32, 40): |
50 key = getRandomUnicode(key_len) | 50 key = get_random_unicode(key_len) |
51 for message_len in (0, 2, 16, 24, 32, 100): | 51 for message_len in (0, 2, 16, 24, 32, 100): |
52 message = getRandomUnicode(message_len) | 52 message = get_random_unicode(message_len) |
53 test(key, message) | 53 test(key, message) |
54 return defer.DeferredList(d_list) | 54 return defer.DeferredList(d_list) |
55 | 55 |
56 def test_hash_verify(self): | 56 def test_hash_verify(self): |
57 d_list = [] | 57 d_list = [] |
60 | 60 |
61 def cb(hashed): | 61 def cb(hashed): |
62 d1 = PasswordHasher.verify(password, hashed) | 62 d1 = PasswordHasher.verify(password, hashed) |
63 d1.addCallback(lambda result: self.assertTrue(result)) | 63 d1.addCallback(lambda result: self.assertTrue(result)) |
64 d_list.append(d1) | 64 d_list.append(d1) |
65 attempt = getRandomUnicode(10) | 65 attempt = get_random_unicode(10) |
66 d2 = PasswordHasher.verify(attempt, hashed) | 66 d2 = PasswordHasher.verify(attempt, hashed) |
67 d2.addCallback(lambda result: self.assertFalse(result)) | 67 d2.addCallback(lambda result: self.assertFalse(result)) |
68 d_list.append(d2) | 68 d_list.append(d2) |
69 | 69 |
70 d.addCallback(cb) | 70 d.addCallback(cb) |