diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-11-19 07:38:19 -0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-11-19 07:38:19 -0800 |
commit | b29a6b2e4623fa87fecaccc05551b996f684cd53 (patch) | |
tree | f3579a5536862a304eaba25612f07f0c2515c8bd /tests/hazmat/primitives/test_hmac.py | |
parent | 867acfa0300ca75f2c11c15490e04b556d8bfe99 (diff) | |
parent | 62e96cbb0698d8f7d65d8dd2d301ef975a829d9e (diff) | |
download | cryptography-b29a6b2e4623fa87fecaccc05551b996f684cd53.tar.gz cryptography-b29a6b2e4623fa87fecaccc05551b996f684cd53.tar.bz2 cryptography-b29a6b2e4623fa87fecaccc05551b996f684cd53.zip |
Merge branch 'master' into fernet
Diffstat (limited to 'tests/hazmat/primitives/test_hmac.py')
-rw-r--r-- | tests/hazmat/primitives/test_hmac.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/tests/hazmat/primitives/test_hmac.py b/tests/hazmat/primitives/test_hmac.py index a44838cf..d17049e3 100644 --- a/tests/hazmat/primitives/test_hmac.py +++ b/tests/hazmat/primitives/test_hmac.py @@ -19,6 +19,7 @@ import pytest import six +from cryptography.exceptions import AlreadyFinalized from cryptography.hazmat.primitives import hashes, hmac from .utils import generate_base_hmac_test @@ -27,7 +28,7 @@ from .utils import generate_base_hmac_test class TestHMAC(object): test_copy = generate_base_hmac_test( hashes.MD5(), - only_if=lambda backend: backend.hashes.supported(hashes.MD5), + only_if=lambda backend: backend.hash_supported(hashes.MD5), skip_message="Does not support MD5", ) @@ -37,9 +38,10 @@ class TestHMAC(object): h.update(six.u("\u00FC")) def test_copy_backend_object(self): - pretend_hmac = pretend.stub(copy_ctx=lambda a: True) + pretend_hmac = pretend.stub() pretend_backend = pretend.stub(hmacs=pretend_hmac) - pretend_ctx = pretend.stub() + copied_ctx = pretend.stub() + pretend_ctx = pretend.stub(copy=lambda: copied_ctx) h = hmac.HMAC(b"key", hashes.SHA1(), backend=pretend_backend, ctx=pretend_ctx) assert h._backend is pretend_backend @@ -48,3 +50,16 @@ class TestHMAC(object): def test_hmac_algorithm_instance(self): with pytest.raises(TypeError): hmac.HMAC(b"key", hashes.SHA1) + + def test_raises_after_finalize(self): + h = hmac.HMAC(b"key", hashes.SHA1()) + h.finalize() + + with pytest.raises(AlreadyFinalized): + h.update(b"foo") + + with pytest.raises(AlreadyFinalized): + h.copy() + + with pytest.raises(AlreadyFinalized): + h.finalize() |