diff options
author | Ayrx <terrycwk1994@gmail.com> | 2014-03-15 21:51:04 +0800 |
---|---|---|
committer | Ayrx <terrycwk1994@gmail.com> | 2014-03-15 21:51:04 +0800 |
commit | 30e574e8f0759a747f77e0e45fa5dbefeb44f3f0 (patch) | |
tree | a32b6765ba4ff5862c35b2b181443b2b181c6617 /tests/hazmat/primitives/twofactor | |
parent | b8a9c9e6243716b353b0786dae1e6e7d94f474a8 (diff) | |
download | cryptography-30e574e8f0759a747f77e0e45fa5dbefeb44f3f0.tar.gz cryptography-30e574e8f0759a747f77e0e45fa5dbefeb44f3f0.tar.bz2 cryptography-30e574e8f0759a747f77e0e45fa5dbefeb44f3f0.zip |
Added backend check to twofactor primitives
Diffstat (limited to 'tests/hazmat/primitives/twofactor')
-rw-r--r-- | tests/hazmat/primitives/twofactor/test_hotp.py | 13 | ||||
-rw-r--r-- | tests/hazmat/primitives/twofactor/test_totp.py | 13 |
2 files changed, 24 insertions, 2 deletions
diff --git a/tests/hazmat/primitives/twofactor/test_hotp.py b/tests/hazmat/primitives/twofactor/test_hotp.py index bc907c9f..0ef18979 100644 --- a/tests/hazmat/primitives/twofactor/test_hotp.py +++ b/tests/hazmat/primitives/twofactor/test_hotp.py @@ -15,9 +15,11 @@ from __future__ import absolute_import, division, print_function import os +import pretend + import pytest -from cryptography.exceptions import InvalidToken +from cryptography.exceptions import InvalidToken, UnsupportedInterface from cryptography.hazmat.primitives.twofactor.hotp import HOTP from cryptography.hazmat.primitives import hashes from tests.utils import load_vectors_from_file, load_nist_vectors @@ -95,3 +97,12 @@ class TestHOTP(object): with pytest.raises(TypeError): HOTP(secret, b"foo", SHA1(), backend) + + +def test_invalid_backend(): + secret = b"12345678901234567890" + + pretend_backend = pretend.stub() + + with pytest.raises(UnsupportedInterface): + HOTP(secret, 8, hashes.SHA1(), pretend_backend) diff --git a/tests/hazmat/primitives/twofactor/test_totp.py b/tests/hazmat/primitives/twofactor/test_totp.py index f3bddb88..776a9f2a 100644 --- a/tests/hazmat/primitives/twofactor/test_totp.py +++ b/tests/hazmat/primitives/twofactor/test_totp.py @@ -13,9 +13,11 @@ from __future__ import absolute_import, division, print_function +import pretend + import pytest -from cryptography.exceptions import InvalidToken +from cryptography.exceptions import InvalidToken, UnsupportedInterface from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.twofactor.totp import TOTP from tests.utils import load_vectors_from_file, load_nist_vectors @@ -129,3 +131,12 @@ class TestTOTP(object): totp = TOTP(secret, 8, hashes.SHA1(), 30, backend) assert totp.generate(time) == b"94287082" + + +def test_invalid_backend(): + secret = b"12345678901234567890" + + pretend_backend = pretend.stub() + + with pytest.raises(UnsupportedInterface): + TOTP(secret, 8, hashes.SHA1(), 30, pretend_backend) |