diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-03-16 08:04:10 -0430 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-03-16 08:04:10 -0430 |
commit | 77fdd4e4559c30ee0155430f6fe192311b5eae8b (patch) | |
tree | 22351055cf68c4306926d3dfff3430d21f68c376 /tests/hazmat | |
parent | e2083365826c231f0a11efb7555280b4a1579a9e (diff) | |
parent | f575ec18b36fd87ff54d63ed959781070efdf053 (diff) | |
download | cryptography-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/hazmat')
-rw-r--r-- | tests/hazmat/primitives/test_hmac.py | 19 |
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) |