diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2016-06-29 09:27:21 -0500 |
---|---|---|
committer | Donald Stufft <donald@stufft.io> | 2016-06-29 10:27:21 -0400 |
commit | c9a9ec1e7a39949b1d09d72746fad6a1d681a80b (patch) | |
tree | 6726e1973f4c55af714bc9c4c77d76d772d59a7c /tests/test_bcrypt.py | |
parent | 81e8efd0cf48ecf3acfe4c205489c8301ca28045 (diff) | |
download | py-bcrypt-git-c9a9ec1e7a39949b1d09d72746fad6a1d681a80b.tar.gz |
Add checkpw (#76)
Diffstat (limited to 'tests/test_bcrypt.py')
-rw-r--r-- | tests/test_bcrypt.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/test_bcrypt.py b/tests/test_bcrypt.py index b506a7a..ea5cee3 100644 --- a/tests/test_bcrypt.py +++ b/tests/test_bcrypt.py @@ -217,6 +217,11 @@ def test_hashpw_new(password, salt, hashed): @pytest.mark.parametrize(("password", "salt", "hashed"), _test_vectors) +def test_checkpw(password, salt, hashed): + assert bcrypt.checkpw(password, hashed) is True + + +@pytest.mark.parametrize(("password", "salt", "hashed"), _test_vectors) def test_hashpw_existing(password, salt, hashed): assert bcrypt.hashpw(password, hashed) == hashed @@ -226,11 +231,47 @@ def test_hashpw_2y_prefix(password, hashed, expected): assert bcrypt.hashpw(password, hashed) == expected +@pytest.mark.parametrize(("password", "hashed", "expected"), _2y_test_vectors) +def test_checkpw_2y_prefix(password, hashed, expected): + assert bcrypt.checkpw(password, hashed) is True + + def test_hashpw_invalid(): with pytest.raises(ValueError): bcrypt.hashpw(b"password", b"$2z$04$cVWp4XaNU8a4v1uMRum2SO") +def test_checkpw_wrong_password(): + assert bcrypt.checkpw( + b"badpass", + b"$2b$04$2Siw3Nv3Q/gTOIPetAyPr.GNj3aO0lb1E5E9UumYGKjP9BYqlNWJe" + ) is False + + +def test_checkpw_bad_salt(): + with pytest.raises(ValueError): + bcrypt.checkpw( + b"badpass", + b"$2b$04$?Siw3Nv3Q/gTOIPetAyPr.GNj3aO0lb1E5E9UumYGKjP9BYqlNWJe" + ) + + +def test_checkpw_str_password(): + with pytest.raises(TypeError): + bcrypt.checkpw( + six.text_type("password"), + b"$2b$04$cVWp4XaNU8a4v1uMRum2SO", + ) + + +def test_checkpw_str_salt(): + with pytest.raises(TypeError): + bcrypt.checkpw( + b"password", + six.text_type("$2b$04$cVWp4XaNU8a4v1uMRum2SO"), + ) + + def test_hashpw_str_password(): with pytest.raises(TypeError): bcrypt.hashpw( @@ -247,6 +288,20 @@ def test_hashpw_str_salt(): ) +def test_checkpw_nul_byte(): + with pytest.raises(ValueError): + bcrypt.checkpw( + b"abc\0def", + b"$2b$04$2Siw3Nv3Q/gTOIPetAyPr.GNj3aO0lb1E5E9UumYGKjP9BYqlNWJe" + ) + + with pytest.raises(ValueError): + bcrypt.checkpw( + b"abcdef", + b"$2b$04$2S\0w3Nv3Q/gTOIPetAyPr.GNj3aO0lb1E5E9UumYGKjP9BYqlNWJe" + ) + + def test_hashpw_nul_byte(): salt = bcrypt.gensalt(4) with pytest.raises(ValueError): |