diff options
Diffstat (limited to 'test/test_generator.py')
| -rw-r--r-- | test/test_generator.py | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/test/test_generator.py b/test/test_generator.py index b4bb961..4329ae4 100644 --- a/test/test_generator.py +++ b/test/test_generator.py | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | # SPDX-License-Identifier: BSD-2-Clause-FreeBSD | 1 | # SPDX-License-Identifier: BSD-2-Clause-FreeBSD |
| 3 | # | 2 | # |
| 4 | # Copyright (c) 2020-2023, Simeon Simeonov | 3 | # Copyright (c) 2020-2025, Simeon Simeonov |
| 5 | # All rights reserved. | 4 | # All rights reserved. |
| 6 | # | 5 | # |
| 7 | # Redistribution and use in source and binary forms, with or without | 6 | # Redistribution and use in source and binary forms, with or without |
| @@ -36,25 +35,25 @@ def test_caller_exceptions(): | |||
| 36 | 'TeSt', | 35 | 'TeSt', |
| 37 | otp2289.OTP_ALGO_MD5, | 36 | otp2289.OTP_ALGO_MD5, |
| 38 | ) | 37 | ) |
| 39 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | 38 | with pytest.raises(otp2289.OTPGeneratorError) as exc_info: |
| 40 | gen.generate_otp_words('3') | 39 | gen.generate_otp_words('3') |
| 41 | assert exc_info.type is otp2289.OTPGeneratorException | 40 | assert exc_info.type is otp2289.OTPGeneratorError |
| 42 | assert exc_info.value.args[0] == 'Step value MUST be an int' | 41 | assert exc_info.value.args[0] == 'Step value MUST be an int' |
| 43 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | 42 | with pytest.raises(otp2289.OTPGeneratorError) as exc_info: |
| 44 | gen.generate_otp_hexdigest(-1) | 43 | gen.generate_otp_hexdigest(-1) |
| 45 | assert exc_info.type is otp2289.OTPGeneratorException | 44 | assert exc_info.type is otp2289.OTPGeneratorError |
| 46 | assert exc_info.value.args[0] == 'Step value MUST be >= 0' | 45 | assert exc_info.value.args[0] == 'Step value MUST be >= 0' |
| 47 | with pytest.raises(otp2289.OTPChallengeException) as exc_info: | 46 | with pytest.raises(otp2289.OTPChallengeError) as exc_info: |
| 48 | gen.generate_otp_hexdigest_from_challenge(b'md5 fbd TeSt') | 47 | gen.generate_otp_hexdigest_from_challenge(b'md5 fbd TeSt') |
| 49 | assert exc_info.type is otp2289.OTPChallengeException | 48 | assert exc_info.type is otp2289.OTPChallengeError |
| 50 | assert exc_info.value.args[0] == 'Challenge must be str' | 49 | assert exc_info.value.args[0] == 'Challenge must be str' |
| 51 | with pytest.raises(otp2289.OTPChallengeException) as exc_info: | 50 | with pytest.raises(otp2289.OTPChallengeError) as exc_info: |
| 52 | gen.generate_otp_hexdigest_from_challenge('md5 fbd TeSt') | 51 | gen.generate_otp_hexdigest_from_challenge('md5 fbd TeSt') |
| 53 | assert exc_info.type is otp2289.OTPChallengeException | 52 | assert exc_info.type is otp2289.OTPChallengeError |
| 54 | assert exc_info.value.args[0] == 'Invalid challenge' | 53 | assert exc_info.value.args[0] == 'Invalid challenge' |
| 55 | with pytest.raises(otp2289.generator.OTPChallengeException) as exc_info: | 54 | with pytest.raises(otp2289.generator.OTPChallengeError) as exc_info: |
| 56 | gen.generate_otp_hexdigest_from_challenge('otp-md5 fbd TeSt') | 55 | gen.generate_otp_hexdigest_from_challenge('otp-md5 fbd TeSt') |
| 57 | assert exc_info.type is otp2289.generator.OTPChallengeException | 56 | assert exc_info.type is otp2289.generator.OTPChallengeError |
| 58 | assert exc_info.value.args[0] == 'Invalid challenge' | 57 | assert exc_info.value.args[0] == 'Invalid challenge' |
| 59 | 58 | ||
| 60 | 59 | ||
| @@ -63,74 +62,74 @@ def test_constructor_exceptions(): | |||
| 63 | Tests the exceptions when initializing a new object (in the constructor) | 62 | Tests the exceptions when initializing a new object (in the constructor) |
| 64 | """ | 63 | """ |
| 65 | # test the otp2289.OTPGenerator __init__ and validators | 64 | # test the otp2289.OTPGenerator __init__ and validators |
| 66 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | 65 | with pytest.raises(otp2289.OTPGeneratorError) as exc_info: |
| 67 | otp2289.OTPGenerator( | 66 | otp2289.OTPGenerator( |
| 68 | 'This is a test.'.encode(), | 67 | 'This is a test.'.encode(), |
| 69 | 'TeStø'.encode(), | 68 | 'TeStø'.encode(), |
| 70 | otp2289.OTP_ALGO_MD5, | 69 | otp2289.OTP_ALGO_MD5, |
| 71 | ) | 70 | ) |
| 72 | assert exc_info.type is otp2289.OTPGeneratorException | 71 | assert exc_info.type is otp2289.OTPGeneratorError |
| 73 | assert exc_info.value.args[0] == 'Seed must be a string' | 72 | assert exc_info.value.args[0] == 'Seed must be a string' |
| 74 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | 73 | with pytest.raises(otp2289.OTPGeneratorError) as exc_info: |
| 75 | otp2289.OTPGenerator( | 74 | otp2289.OTPGenerator( |
| 76 | 'This is a test.'.encode(), | 75 | 'This is a test.'.encode(), |
| 77 | 'TeStøtEsTteSTteStTest', | 76 | 'TeStøtEsTteSTteStTest', |
| 78 | otp2289.OTP_ALGO_SHA1, | 77 | otp2289.OTP_ALGO_SHA1, |
| 79 | ) | 78 | ) |
| 80 | assert exc_info.type is otp2289.OTPGeneratorException | 79 | assert exc_info.type is otp2289.OTPGeneratorError |
| 81 | assert exc_info.value.args[0] == ( | 80 | assert exc_info.value.args[0] == ( |
| 82 | 'The seed MUST be of 1 to 16 characters in length' | 81 | 'The seed MUST be of 1 to 16 characters in length' |
| 83 | ) | 82 | ) |
| 84 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | 83 | with pytest.raises(otp2289.OTPGeneratorError) as exc_info: |
| 85 | otp2289.OTPGenerator( | 84 | otp2289.OTPGenerator( |
| 86 | 'This is a test.'.encode(), | 85 | 'This is a test.'.encode(), |
| 87 | 'TeStø', | 86 | 'TeStø', |
| 88 | otp2289.OTP_ALGO_SHA1, | 87 | otp2289.OTP_ALGO_SHA1, |
| 89 | ) | 88 | ) |
| 90 | assert exc_info.type is otp2289.OTPGeneratorException | 89 | assert exc_info.type is otp2289.OTPGeneratorError |
| 91 | assert exc_info.value.args[0] == ( | 90 | assert exc_info.value.args[0] == ( |
| 92 | 'The seed MUST consist of purely alphanumeric characters' | 91 | 'The seed MUST consist of purely alphanumeric characters' |
| 93 | ) | 92 | ) |
| 94 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | 93 | with pytest.raises(otp2289.OTPGeneratorError) as exc_info: |
| 95 | otp2289.OTPGenerator( | 94 | otp2289.OTPGenerator( |
| 96 | 'This is a test.'.encode(), | 95 | 'This is a test.'.encode(), |
| 97 | 'TeSt', | 96 | 'TeSt', |
| 98 | 9, | 97 | 9, |
| 99 | ) | 98 | ) |
| 100 | assert exc_info.type is otp2289.OTPGeneratorException | 99 | assert exc_info.type is otp2289.OTPGeneratorError |
| 101 | assert exc_info.value.args[0] == ( | 100 | assert exc_info.value.args[0] == ( |
| 102 | 'hash_algo is not among the known algorithms' | 101 | 'hash_algo is not among the known algorithms' |
| 103 | ) | 102 | ) |
| 104 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | 103 | with pytest.raises(otp2289.OTPGeneratorError) as exc_info: |
| 105 | otp2289.OTPGenerator( | 104 | otp2289.OTPGenerator( |
| 106 | 'This is a test.'.encode(), | 105 | 'This is a test.'.encode(), |
| 107 | 'TeSt', | 106 | 'TeSt', |
| 108 | b'md5', | 107 | b'md5', |
| 109 | ) | 108 | ) |
| 110 | assert exc_info.type is otp2289.OTPGeneratorException | 109 | assert exc_info.type is otp2289.OTPGeneratorError |
| 111 | assert exc_info.value.args[0] == 'hash_algo must be an int or a str' | 110 | assert exc_info.value.args[0] == 'hash_algo must be an int or a str' |
| 112 | # test the package structure as well | 111 | # test the package structure as well |
| 113 | with pytest.raises(otp2289.generator.OTPGeneratorException) as exc_info: | 112 | with pytest.raises(otp2289.generator.OTPGeneratorError) as exc_info: |
| 114 | otp2289.generator.OTPGenerator( | 113 | otp2289.generator.OTPGenerator( |
| 115 | 'This is a test.'.encode(), | 114 | 'This is a test.'.encode(), |
| 116 | 'TeSt', | 115 | 'TeSt', |
| 117 | 'foo', | 116 | 'foo', |
| 118 | ) | 117 | ) |
| 119 | assert exc_info.type is otp2289.generator.OTPGeneratorException | 118 | assert exc_info.type is otp2289.generator.OTPGeneratorError |
| 120 | assert exc_info.value.args[0] == ( | 119 | assert exc_info.value.args[0] == ( |
| 121 | 'foo is not supported by this version of the hashlib module' | 120 | 'foo is not supported by this version of the hashlib module' |
| 122 | ) | 121 | ) |
| 123 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | 122 | with pytest.raises(otp2289.OTPGeneratorError) as exc_info: |
| 124 | otp2289.OTPGenerator('1234567', 'TeSt', otp2289.OTP_ALGO_MD5) | 123 | otp2289.OTPGenerator('1234567', 'TeSt', otp2289.OTP_ALGO_MD5) |
| 125 | assert exc_info.type is otp2289.OTPGeneratorException | 124 | assert exc_info.type is otp2289.OTPGeneratorError |
| 126 | assert exc_info.value.args[0] == 'Password must be a byte-string' | 125 | assert exc_info.value.args[0] == 'Password must be a byte-string' |
| 127 | with pytest.raises(otp2289.OTPGeneratorException) as exc_info: | 126 | with pytest.raises(otp2289.OTPGeneratorError) as exc_info: |
| 128 | otp2289.OTPGenerator( | 127 | otp2289.OTPGenerator( |
| 129 | '1234567'.encode(), | 128 | '1234567'.encode(), |
| 130 | 'TeSt', | 129 | 'TeSt', |
| 131 | otp2289.OTP_ALGO_MD5, | 130 | otp2289.OTP_ALGO_MD5, |
| 132 | ) | 131 | ) |
| 133 | assert exc_info.type is otp2289.OTPGeneratorException | 132 | assert exc_info.type is otp2289.OTPGeneratorError |
| 134 | assert exc_info.value.args[0] == 'Password must be longer than 10 bytes' | 133 | assert exc_info.value.args[0] == 'Password must be longer than 10 bytes' |
| 135 | 134 | ||
| 136 | 135 | ||
