aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-03-16 08:04:10 -0430
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-03-16 08:04:10 -0430
commit77fdd4e4559c30ee0155430f6fe192311b5eae8b (patch)
tree22351055cf68c4306926d3dfff3430d21f68c376 /tests
parente2083365826c231f0a11efb7555280b4a1579a9e (diff)
parentf575ec18b36fd87ff54d63ed959781070efdf053 (diff)
downloadcryptography-77fdd4e4559c30ee0155430f6fe192311b5eae8b.tar.gz
cryptography-77fdd4e4559c30ee0155430f6fe192311b5eae8b.tar.bz2
cryptography-77fdd4e4559c30ee0155430f6fe192311b5eae8b.zip
Merge pull request #805 from Ayrx/add-backend-check-to-hmac
Added backend check to hmac primitives
Diffstat (limited to 'tests')
-rw-r--r--tests/hazmat/primitives/test_hmac.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/tests/hazmat/primitives/test_hmac.py b/tests/hazmat/primitives/test_hmac.py
index 88bed52c..af177d7a 100644
--- a/tests/hazmat/primitives/test_hmac.py
+++ b/tests/hazmat/primitives/test_hmac.py
@@ -21,8 +21,11 @@ import six
from cryptography import utils
from cryptography.exceptions import (
- AlreadyFinalized, UnsupportedHash, InvalidSignature
+ AlreadyFinalized, UnsupportedHash, InvalidSignature,
+ UnsupportedInterface
)
+
+from cryptography.hazmat.backends.interfaces import HMACBackend
from cryptography.hazmat.primitives import hashes, hmac, interfaces
from .utils import generate_base_hmac_test
@@ -52,8 +55,11 @@ class TestHMAC(object):
h.update(six.u("\u00FC"))
def test_copy_backend_object(self):
- pretend_hmac = pretend.stub()
- pretend_backend = pretend.stub(hmacs=pretend_hmac)
+ @utils.register_interface(HMACBackend)
+ class PretendBackend(object):
+ pass
+
+ pretend_backend = PretendBackend()
copied_ctx = pretend.stub()
pretend_ctx = pretend.stub(copy=lambda: copied_ctx)
h = hmac.HMAC(b"key", hashes.SHA1(), backend=pretend_backend,
@@ -104,3 +110,10 @@ class TestHMAC(object):
def test_unsupported_hash(self, backend):
with pytest.raises(UnsupportedHash):
hmac.HMAC(b"key", UnsupportedDummyHash(), backend)
+
+
+def test_invalid_backend():
+ pretend_backend = object()
+
+ with pytest.raises(UnsupportedInterface):
+ hmac.HMAC(b"key", hashes.SHA1(), pretend_backend)