author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 16 Jun 2016 14:19:20 +0200 | |
changeset 11278 | 19fcce6dc6d1 |
parent 10775 | 4b3c1069bd4e |
permissions | -rw-r--r-- |
8414
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
1 |
# copyright 2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
3 |
# |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
4 |
# This file is part of CubicWeb. |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
5 |
# |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
9 |
# any later version. |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
10 |
# |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
14 |
# details. |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
15 |
# |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
18 |
""" |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
19 |
|
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
20 |
""" |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
21 |
from logilab.common.testlib import TestCase, unittest_main |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
22 |
|
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
23 |
from cubicweb.server import utils |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
24 |
|
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
25 |
class UtilsTC(TestCase): |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
26 |
def test_crypt(self): |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
27 |
for hash in ( |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
28 |
utils.crypt_password('xxx'), # default sha512 |
10775
4b3c1069bd4e
Fix md5crypt and crypt_password test for python3
Julien Cristau <julien.cristau@logilab.fr>
parents:
8414
diff
changeset
|
29 |
b'ab$5UsKFxRKKN.d8iBIFBnQ80', # custom md5 |
4b3c1069bd4e
Fix md5crypt and crypt_password test for python3
Julien Cristau <julien.cristau@logilab.fr>
parents:
8414
diff
changeset
|
30 |
b'ab4Vlm81ZUHlg', # DES |
8414
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
31 |
): |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
32 |
self.assertEqual(utils.crypt_password('xxx', hash), hash) |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
33 |
self.assertEqual(utils.crypt_password(u'xxx', hash), hash) |
10775
4b3c1069bd4e
Fix md5crypt and crypt_password test for python3
Julien Cristau <julien.cristau@logilab.fr>
parents:
8414
diff
changeset
|
34 |
self.assertEqual(utils.crypt_password(u'xxx', hash.decode('ascii')), hash.decode('ascii')) |
4b3c1069bd4e
Fix md5crypt and crypt_password test for python3
Julien Cristau <julien.cristau@logilab.fr>
parents:
8414
diff
changeset
|
35 |
self.assertEqual(utils.crypt_password('yyy', hash), b'') |
8414
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
36 |
|
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
37 |
# accept any password for empty hashes (is it a good idea?) |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
38 |
self.assertEqual(utils.crypt_password('xxx', ''), '') |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
39 |
self.assertEqual(utils.crypt_password('yyy', ''), '') |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
40 |
|
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
41 |
|
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
42 |
if __name__ == '__main__': |
e7243ed7bb0a
Fixes for compatibility with passlib 1.6 (closes #2356393)
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
43 |
unittest_main() |