diff options
author | Ayrx <terrycwk1994@gmail.com> | 2014-03-16 14:14:17 +0800 |
---|---|---|
committer | Ayrx <terrycwk1994@gmail.com> | 2014-03-16 14:14:17 +0800 |
commit | ecac0290b7fedc71e72b1fb0a7bfc02433a11f7f (patch) | |
tree | cae9a09b6ab5349ce6dfdf43180054d5a9e10d7a /tests/hazmat | |
parent | 3fb221f1fb02ffed7a558bd06ba41bb75c329fc5 (diff) | |
download | cryptography-ecac0290b7fedc71e72b1fb0a7bfc02433a11f7f.tar.gz cryptography-ecac0290b7fedc71e72b1fb0a7bfc02433a11f7f.tar.bz2 cryptography-ecac0290b7fedc71e72b1fb0a7bfc02433a11f7f.zip |
Added backend check to hmac primitives
Diffstat (limited to 'tests/hazmat')
-rw-r--r-- | tests/hazmat/primitives/test_hmac.py | 20 |
1 files changed, 16 insertions, 4 deletions
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) |