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