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