test_security.py 834 B

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