aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat
diff options
context:
space:
mode:
authorAyrx <terrycwk1994@gmail.com>2014-02-13 12:27:56 +0800
committerAyrx <terrycwk1994@gmail.com>2014-02-21 11:13:35 +0800
commita7769110ef8f575105847f84cadf6bb5b9aa5fba (patch)
tree9dd292842a82903d1d2c42529250de41515a322c /tests/hazmat
parentb2ee044298caf5772fb8774dc691add3afe8cdc1 (diff)
downloadcryptography-a7769110ef8f575105847f84cadf6bb5b9aa5fba.tar.gz
cryptography-a7769110ef8f575105847f84cadf6bb5b9aa5fba.tar.bz2
cryptography-a7769110ef8f575105847f84cadf6bb5b9aa5fba.zip
Updated according to code review feedback.
Diffstat (limited to 'tests/hazmat')
-rw-r--r--tests/hazmat/oath/test_hotp.py36
1 files changed, 34 insertions, 2 deletions
diff --git a/tests/hazmat/oath/test_hotp.py b/tests/hazmat/oath/test_hotp.py
index cd06c79f..8a5aebd3 100644
--- a/tests/hazmat/oath/test_hotp.py
+++ b/tests/hazmat/oath/test_hotp.py
@@ -10,18 +10,41 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+from cryptography.exceptions import InvalidToken
+
+import os
import pytest
+
from cryptography.hazmat.oath.hotp import HOTP
+from cryptography.hazmat.primitives import hashes
from tests.utils import load_vectors_from_file, load_nist_vectors
vectors = load_vectors_from_file(
"oath/rfc-4226.txt", load_nist_vectors)
-@pytest.mark.oath
+@pytest.mark.supported(
+ only_if=lambda backend: backend.hmac_supported(hashes.SHA1()),
+ skip_message="Does not support HMAC-SHA1."
+)
+@pytest.mark.hmac
class TestHOTP(object):
+ def test_invalid_key_length(self, backend):
+ secret = os.urandom(10)
+
+ with pytest.raises(ValueError):
+ hotp = HOTP(secret, 6, backend)
+ hotp.generate(0)
+
+ def test_invalid_hotp_length(self, backend):
+ secret = os.urandom(16)
+
+ with pytest.raises(ValueError):
+ hotp = HOTP(secret, 4, backend)
+ hotp.generate(0)
+
@pytest.mark.parametrize("params", vectors)
def test_truncate(self, backend, params):
secret = params["secret"]
@@ -50,4 +73,13 @@ class TestHOTP(object):
hotp = HOTP(secret, 6, backend)
- assert hotp.verify(hotp_value, counter) is True
+ assert hotp.verify(hotp_value, counter) is None
+
+ def test_invalid_verify(self, backend):
+ secret = b"12345678901234567890"
+ counter = 0
+
+ hotp = HOTP(secret, 6, backend)
+
+ with pytest.raises(InvalidToken):
+ hotp.verify(b"123456", counter)