Mercurial > libervia-backend
comparison sat/test/test_memory_crypto.py @ 2562:26edcf3a30eb
core, setup: huge cleaning:
- moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention
- move twisted directory to root
- removed all hacks from setup.py, and added missing dependencies, it is now clean
- use https URL for website in setup.py
- removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed
- renamed sat.sh to sat and fixed its installation
- added python_requires to specify Python version needed
- replaced glib2reactor which use deprecated code by gtk3reactor
sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Apr 2018 19:44:50 +0200 |
parents | src/test/test_memory_crypto.py@2daf7b4c6756 |
children | 56f94936df1e |
comparison
equal
deleted
inserted
replaced
2561:bd30dc3ffe5a | 2562:26edcf3a30eb |
---|---|
1 #!/usr/bin/env python2 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # SAT: a jabber client | |
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) | |
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org) | |
7 | |
8 # This program is free software: you can redistribute it and/or modify | |
9 # it under the terms of the GNU Affero General Public License as published by | |
10 # the Free Software Foundation, either version 3 of the License, or | |
11 # (at your option) any later version. | |
12 | |
13 # This program is distributed in the hope that it will be useful, | |
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 # GNU Affero General Public License for more details. | |
17 | |
18 # You should have received a copy of the GNU Affero General Public License | |
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 | |
21 | |
22 """ Tests for the plugin radiocol """ | |
23 | |
24 from sat.test import helpers | |
25 from sat.memory.crypto import BlockCipher, PasswordHasher | |
26 import random | |
27 import string | |
28 from twisted.internet import defer | |
29 | |
30 | |
31 def getRandomUnicode(len): | |
32 """Return a random unicode string""" | |
33 return u''.join(random.choice(string.letters + u"éáúóâêûôßüöä") for i in xrange(len)) | |
34 | |
35 | |
36 class CryptoTest(helpers.SatTestCase): | |
37 | |
38 def setUp(self): | |
39 self.host = helpers.FakeSAT() | |
40 | |
41 def test_encrypt_decrypt(self): | |
42 d_list = [] | |
43 | |
44 def test(key, message): | |
45 d = BlockCipher.encrypt(key, message) | |
46 d.addCallback(lambda ciphertext: BlockCipher.decrypt(key, ciphertext)) | |
47 d.addCallback(lambda decrypted: self.assertEqual(message, decrypted)) | |
48 d_list.append(d) | |
49 | |
50 for key_len in (0, 2, 8, 10, 16, 24, 30, 32, 40): | |
51 key = getRandomUnicode(key_len) | |
52 for message_len in (0, 2, 16, 24, 32, 100): | |
53 message = getRandomUnicode(message_len) | |
54 test(key, message) | |
55 return defer.DeferredList(d_list) | |
56 | |
57 def test_hash_verify(self): | |
58 d_list = [] | |
59 for password in (0, 2, 8, 10, 16, 24, 30, 32, 40): | |
60 d = PasswordHasher.hash(password) | |
61 | |
62 def cb(hashed): | |
63 d1 = PasswordHasher.verify(password, hashed) | |
64 d1.addCallback(lambda result: self.assertTrue(result)) | |
65 d_list.append(d1) | |
66 attempt = getRandomUnicode(10) | |
67 d2 = PasswordHasher.verify(attempt, hashed) | |
68 d2.addCallback(lambda result: self.assertFalse(result)) | |
69 d_list.append(d2) | |
70 | |
71 d.addCallback(cb) | |
72 return defer.DeferredList(d_list) |