test_security.py 801 B

12345678910111213141516171819202122232425
  1. # coding: utf-8
  2. from ..security import passwd, passwd_check, salt_len
  3. import nose.tools as nt
  4. def test_passwd_structure():
  5. p = passwd('passphrase')
  6. algorithm, salt, hashed = p.split(':')
  7. nt.assert_equal(algorithm, 'sha1')
  8. nt.assert_equal(len(salt), salt_len)
  9. nt.assert_equal(len(hashed), 40)
  10. def test_roundtrip():
  11. p = passwd('passphrase')
  12. nt.assert_equal(passwd_check(p, 'passphrase'), True)
  13. def test_bad():
  14. p = passwd('passphrase')
  15. nt.assert_equal(passwd_check(p, p), False)
  16. nt.assert_equal(passwd_check(p, 'a:b:c:d'), False)
  17. nt.assert_equal(passwd_check(p, 'a:b'), False)
  18. def test_passwd_check_unicode():
  19. # GH issue #4524
  20. phash = u'sha1:23862bc21dd3:7a415a95ae4580582e314072143d9c382c491e4f'
  21. assert passwd_check(phash, u"łe¶ŧ←↓→")