diff options
Diffstat (limited to 'test/test_static.py')
| -rw-r--r-- | test/test_static.py | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/test/test_static.py b/test/test_static.py new file mode 100644 index 0000000..7635e5e --- /dev/null +++ b/test/test_static.py | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | # SPDX-License-Identifier: BSD-2-Clause-FreeBSD | ||
| 3 | # | ||
| 4 | # Copyright (c) 2020-2023, Simeon Simeonov | ||
| 5 | # All rights reserved. | ||
| 6 | # | ||
| 7 | # Redistribution and use in source and binary forms, with or without | ||
| 8 | # modification, are permitted provided that the following conditions | ||
| 9 | # are met: | ||
| 10 | # 1. Redistributions of source code must retain the above copyright | ||
| 11 | # notice, this list of conditions and the following disclaimer. | ||
| 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, | ||
| 13 | # this list of conditions and the following disclaimer in the documentation | ||
| 14 | # and/or other materials provided with the distribution. | ||
| 15 | # | ||
| 16 | # THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR | ||
| 17 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 18 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 19 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 20 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 21 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 22 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 23 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 25 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 26 | """Tests for the static methods and basic bit, byte, token functionality""" | ||
| 27 | import binascii | ||
| 28 | import os | ||
| 29 | |||
| 30 | import otp2289 | ||
| 31 | |||
| 32 | |||
| 33 | def test_bytes_and_tokens(): | ||
| 34 | """Tests the official hex and tokens defined in RFC2289""" | ||
| 35 | assert binascii.unhexlify('9e876134d90499dd') == ( | ||
| 36 | otp2289.OTPGenerator.tokens_to_bytes('INCH SEA ANNE LONG AHEM TOUR') | ||
| 37 | ) | ||
| 38 | assert binascii.unhexlify('7965e05436f5029f') == ( | ||
| 39 | otp2289.OTPGenerator.tokens_to_bytes('EASE OIL FUM CURE AWRY AVIS') | ||
| 40 | ) | ||
| 41 | assert binascii.unhexlify('50fe1962c4965880') == ( | ||
| 42 | otp2289.OTPGenerator.tokens_to_bytes('BAIL TUFT BITS GANG CHEF THY') | ||
| 43 | ) | ||
| 44 | assert binascii.unhexlify('87066dd9644bf206') == ( | ||
| 45 | otp2289.OTPGenerator.tokens_to_bytes('FULL PEW DOWN ONCE MORT ARC') | ||
| 46 | ) | ||
| 47 | assert binascii.unhexlify('7cd34c1040add14b') == ( | ||
| 48 | otp2289.OTPGenerator.tokens_to_bytes('FACT HOOF AT FIST SITE KENT') | ||
| 49 | ) | ||
| 50 | assert binascii.unhexlify('5aa37a81f212146c') == ( | ||
| 51 | otp2289.OTPGenerator.tokens_to_bytes('BODE HOP JAKE STOW JUT RAP') | ||
| 52 | ) | ||
| 53 | assert binascii.unhexlify('f205753943de4cf9') == ( | ||
| 54 | otp2289.OTPGenerator.tokens_to_bytes('ULAN NEW ARMY FUSE SUIT EYED') | ||
| 55 | ) | ||
| 56 | assert binascii.unhexlify('ddcdac956f234937') == ( | ||
| 57 | otp2289.OTPGenerator.tokens_to_bytes('SKIM CULT LOB SLAM POE HOWL') | ||
| 58 | ) | ||
| 59 | assert binascii.unhexlify('b203e28fa525be47') == ( | ||
| 60 | otp2289.OTPGenerator.tokens_to_bytes('LONG IVY JULY AJAR BOND LEE') | ||
| 61 | ) | ||
| 62 | assert binascii.unhexlify('bb9e6ae1979d8ff4') == ( | ||
| 63 | otp2289.OTPGenerator.tokens_to_bytes('MILT VARY MAST OK SEES WENT') | ||
| 64 | ) | ||
| 65 | assert binascii.unhexlify('63d936639734385b') == ( | ||
| 66 | otp2289.OTPGenerator.tokens_to_bytes('CART OTTO HIVE ODE VAT NUT') | ||
| 67 | ) | ||
| 68 | assert binascii.unhexlify('87fec7768b73ccf9') == ( | ||
| 69 | otp2289.OTPGenerator.tokens_to_bytes('GAFF WAIT SKID GIG SKY EYED') | ||
| 70 | ) | ||
| 71 | assert binascii.unhexlify('ad85f658ebe383c9') == ( | ||
| 72 | otp2289.OTPGenerator.tokens_to_bytes('LEST OR HEEL SCOT ROB SUIT') | ||
| 73 | ) | ||
| 74 | assert binascii.unhexlify('d07ce229b5cf119b') == ( | ||
| 75 | otp2289.OTPGenerator.tokens_to_bytes('RITE TAKE GELD COST TUNE RECK') | ||
| 76 | ) | ||
| 77 | assert binascii.unhexlify('27bc71035aaf3dc6') == ( | ||
| 78 | otp2289.OTPGenerator.tokens_to_bytes('MAY STAR TIN LYON VEDA STAN') | ||
| 79 | ) | ||
| 80 | assert binascii.unhexlify('d51f3e99bf8e6f0b') == ( | ||
| 81 | otp2289.OTPGenerator.tokens_to_bytes('RUST WELT KICK FELL TAIL FRAU') | ||
| 82 | ) | ||
| 83 | assert binascii.unhexlify('82aeb52d943774e4') == ( | ||
| 84 | otp2289.OTPGenerator.tokens_to_bytes('FLIT DOSE ALSO MEW DRUM DEFY') | ||
| 85 | ) | ||
| 86 | assert binascii.unhexlify('4f296a74fe1567ec') == ( | ||
| 87 | otp2289.OTPGenerator.tokens_to_bytes('AURA ALOE HURL WING BERG WAIT') | ||
| 88 | ) | ||
| 89 | |||
| 90 | |||
| 91 | def test_random_bytes(): | ||
| 92 | """Implement a few tests with random bytes""" | ||
| 93 | for _ in range(10): | ||
| 94 | rnd_bytes = os.urandom(8) # 64 bits | ||
| 95 | tokens = otp2289.OTPGenerator.bytes_to_tokens(rnd_bytes) | ||
| 96 | assert rnd_bytes == otp2289.OTPGenerator.tokens_to_bytes(tokens) | ||
