From ecac0290b7fedc71e72b1fb0a7bfc02433a11f7f Mon Sep 17 00:00:00 2001 From: Ayrx Date: Sun, 16 Mar 2014 14:14:17 +0800 Subject: Added backend check to hmac primitives --- tests/hazmat/primitives/test_hmac.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'tests/hazmat') diff --git a/tests/hazmat/primitives/test_hmac.py b/tests/hazmat/primitives/test_hmac.py index 88bed52c..24988e76 100644 --- a/tests/hazmat/primitives/test_hmac.py +++ b/tests/hazmat/primitives/test_hmac.py @@ -21,8 +21,10 @@ 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 +54,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 +109,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) -- cgit v1.2.3