aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/primitives/test_hmac.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/hazmat/primitives/test_hmac.py')
-rw-r--r--tests/hazmat/primitives/test_hmac.py21
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()