From b482ca185fc1fa0a6cce614c442c35c2fbfac906 Mon Sep 17 00:00:00 2001 From: Ayrx Date: Sun, 16 Mar 2014 13:06:25 +0800 Subject: Added backend check to hash primitives --- tests/hazmat/primitives/test_hashes.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/hazmat/primitives/test_hashes.py b/tests/hazmat/primitives/test_hashes.py index fc53d635..a7af8a8d 100644 --- a/tests/hazmat/primitives/test_hashes.py +++ b/tests/hazmat/primitives/test_hashes.py @@ -20,7 +20,10 @@ import pytest import six from cryptography import utils -from cryptography.exceptions import AlreadyFinalized, UnsupportedHash +from cryptography.exceptions import ( + AlreadyFinalized, UnsupportedHash, UnsupportedInterface) + +from cryptography.hazmat.backends.interfaces import HashBackend from cryptography.hazmat.primitives import hashes, interfaces from .utils import generate_base_hash_test @@ -39,7 +42,11 @@ class TestHashContext(object): m.update(six.u("\u00FC")) def test_copy_backend_object(self): - pretend_backend = pretend.stub() + @utils.register_interface(HashBackend) + class PretendBackend(object): + pass + + pretend_backend = PretendBackend() copied_ctx = pretend.stub() pretend_ctx = pretend.stub(copy=lambda: copied_ctx) h = hashes.Hash(hashes.SHA1(), backend=pretend_backend, @@ -171,3 +178,10 @@ class TestMD5(object): digest_size=16, block_size=64, ) + + +def test_invalid_backend(): + pretend_backend = object() + + with pytest.raises(UnsupportedInterface): + hashes.Hash(hashes.SHA1(), pretend_backend) -- cgit v1.2.3 From b018dbc6a3a5cb0c4697f8623ddb021cebc27330 Mon Sep 17 00:00:00 2001 From: Ayrx Date: Sun, 16 Mar 2014 19:51:44 +0800 Subject: Style nitpick --- tests/hazmat/primitives/test_hashes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/hazmat/primitives/test_hashes.py b/tests/hazmat/primitives/test_hashes.py index a7af8a8d..d74d1d82 100644 --- a/tests/hazmat/primitives/test_hashes.py +++ b/tests/hazmat/primitives/test_hashes.py @@ -21,7 +21,8 @@ import six from cryptography import utils from cryptography.exceptions import ( - AlreadyFinalized, UnsupportedHash, UnsupportedInterface) + AlreadyFinalized, UnsupportedHash, UnsupportedInterface +) from cryptography.hazmat.backends.interfaces import HashBackend from cryptography.hazmat.primitives import hashes, interfaces -- cgit v1.2.3