diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_generator.py | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/tests/test_generator.py b/tests/test_generator.py index bd86eb9..14258da 100644 --- a/tests/test_generator.py +++ b/tests/test_generator.py | |||
| @@ -1,9 +1,56 @@ | |||
| 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
| 2 | """Tests for otp2289.OTPGenerator""" | 2 | """Tests for otp2289.OTPGenerator""" |
| 3 | import pytest | ||
| 3 | 4 | ||
| 4 | import otp2289 | 5 | import otp2289 |
| 5 | 6 | ||
| 6 | 7 | ||
| 8 | def test_exceptions_and_constraints(): | ||
| 9 | """Tests general exceptions and constraints""" | ||
| 10 | # test the otp2289.OTPGenerator __init__ | ||
| 11 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | ||
| 12 | otp2289.OTPGenerator('1234567', 'TeStø'.encode(), otp2289.OTP_ALGO_MD5) | ||
| 13 | assert exc_info.type is otp2289.OTPGeneratorException | ||
| 14 | assert exc_info.value.args[0] == 'Password must be a byte-string' | ||
| 15 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | ||
| 16 | otp2289.OTPGenerator('1234567'.encode(), | ||
| 17 | 'TeStø'.encode(), | ||
| 18 | otp2289.OTP_ALGO_MD5) | ||
| 19 | assert exc_info.type is otp2289.OTPGeneratorException | ||
| 20 | assert exc_info.value.args[0] == 'Password must be longer than 10 bytes' | ||
| 21 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | ||
| 22 | otp2289.OTPGenerator('This is a test.'.encode(), | ||
| 23 | 'TeStø'.encode(), | ||
| 24 | otp2289.OTP_ALGO_MD5) | ||
| 25 | assert exc_info.type is otp2289.OTPGeneratorException | ||
| 26 | assert exc_info.value.args[0] == 'Seed must be a string' | ||
| 27 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | ||
| 28 | otp2289.OTPGenerator('This is a test.'.encode(), | ||
| 29 | 'TeStøtEsTteSTteStTest', | ||
| 30 | otp2289.OTP_ALGO_SHA1) | ||
| 31 | assert exc_info.type is otp2289.OTPGeneratorException | ||
| 32 | assert exc_info.value.args[0] == ('The seed MUST be of 1 to 16 ' | ||
| 33 | 'characters in length') | ||
| 34 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | ||
| 35 | otp2289.OTPGenerator('This is a test.'.encode(), | ||
| 36 | 'TeStø', | ||
| 37 | otp2289.OTP_ALGO_SHA1) | ||
| 38 | assert exc_info.type is otp2289.OTPGeneratorException | ||
| 39 | assert exc_info.value.args[0] == ('The seed MUST consist of purely ' | ||
| 40 | 'alphanumeric characters') | ||
| 41 | gen = otp2289.OTPGenerator('This is a test.'.encode(), | ||
| 42 | 'TeSt', | ||
| 43 | otp2289.OTP_ALGO_MD5) | ||
| 44 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | ||
| 45 | gen.generate_otp_words('3') | ||
| 46 | assert exc_info.type is otp2289.OTPGeneratorException | ||
| 47 | assert exc_info.value.args[0] == 'Step value MUST be an int' | ||
| 48 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | ||
| 49 | gen.generate_otp_hexdigest(-1) | ||
| 50 | assert exc_info.type is otp2289.OTPGeneratorException | ||
| 51 | assert exc_info.value.args[0] == 'Step value MUST be >= 0' | ||
| 52 | |||
| 53 | |||
| 7 | def test_md5(): | 54 | def test_md5(): |
| 8 | """ | 55 | """ |
| 9 | Tests the MD5 functionality of the OTPGenerator as described in the RFC | 56 | Tests the MD5 functionality of the OTPGenerator as described in the RFC |
| @@ -11,7 +58,6 @@ def test_md5(): | |||
| 11 | Those are the tests from 'RFC-2289 Appendix C - OTP Verification Examples' | 58 | Those are the tests from 'RFC-2289 Appendix C - OTP Verification Examples' |
| 12 | """ | 59 | """ |
| 13 | # We could run this in a loop, but I guess "Readability counts." | 60 | # We could run this in a loop, but I guess "Readability counts." |
| 14 | |||
| 15 | # pass='This is a test.', seed='TeSt' | 61 | # pass='This is a test.', seed='TeSt' |
| 16 | gen = otp2289.OTPGenerator('This is a test.'.encode(), | 62 | gen = otp2289.OTPGenerator('This is a test.'.encode(), |
| 17 | 'TeSt', | 63 | 'TeSt', |
