summaryrefslogtreecommitdiff
path: root/tests/test_server.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_server.py')
-rw-r--r--tests/test_server.py77
1 files changed, 47 insertions, 30 deletions
diff --git a/tests/test_server.py b/tests/test_server.py
index 8d24cb8..3d3b77d 100644
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -1,7 +1,7 @@
1# -*- coding: utf-8 -*- 1# -*- coding: utf-8 -*-
2# SPDX-License-Identifier: BSD-2-Clause-FreeBSD 2# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3# 3#
4# Copyright (c) 2020, Simeon Simeonov 4# Copyright (c) 2020-2022, Simeon Simeonov
5# All rights reserved. 5# All rights reserved.
6# 6#
7# Redistribution and use in source and binary forms, with or without 7# Redistribution and use in source and binary forms, with or without
@@ -33,41 +33,50 @@ import otp2289
33 33
34def test_state_caller_exceptions(): 34def test_state_caller_exceptions():
35 """Tests the exceptions when calling the OTPState objects""" 35 """Tests the exceptions when calling the OTPState objects"""
36 state = otp2289.OTPState('0x7965e05436f5029f', 36 state = otp2289.OTPState(
37 1, 37 '0x7965e05436f5029f',
38 'TeSt', 38 1,
39 otp2289.OTP_ALGO_MD5) 39 'TeSt',
40 otp2289.OTP_ALGO_MD5,
41 )
40 with pytest.raises(otp2289.OTPInvalidResponse) as exc_info: 42 with pytest.raises(otp2289.OTPInvalidResponse) as exc_info:
41 state.response_validates('bla') 43 state.response_validates('bla')
42 assert exc_info.type is otp2289.OTPInvalidResponse 44 assert exc_info.type is otp2289.OTPInvalidResponse
43 assert exc_info.value.args[0] == ( 45 assert exc_info.value.args[0] == (
44 'The response is neither a valid token or hex') 46 'The response is neither a valid token or hex'
47 )
45 48
46 49
47def test_state_constructor_exceptions(): 50def test_state_constructor_exceptions():
48 """Tests the exceptions when initializing new OTPState objects""" 51 """Tests the exceptions when initializing new OTPState objects"""
49 with pytest.raises(otp2289.OTPStateException) as exc_info: 52 with pytest.raises(otp2289.OTPStateException) as exc_info:
50 otp2289.OTPState('0x7965e05436f5029t', 53 otp2289.OTPState(
51 1, 54 '0x7965e05436f5029t',
52 'TeStø'.encode(), 55 1,
53 otp2289.OTP_ALGO_MD5) 56 'TeStø'.encode(),
57 otp2289.OTP_ALGO_MD5,
58 )
54 assert exc_info.type is otp2289.OTPStateException 59 assert exc_info.type is otp2289.OTPStateException
55 assert exc_info.value.args[0] == 'Seed must be a string' 60 assert exc_info.value.args[0] == 'Seed must be a string'
56 with pytest.raises(otp2289.OTPStateException) as exc_info: 61 with pytest.raises(otp2289.OTPStateException) as exc_info:
57 otp2289.OTPState('0x7965e05436f5029t', 62 otp2289.OTPState(
58 '1', 63 '0x7965e05436f5029t',
59 'TeSt', 64 '1',
60 otp2289.OTP_ALGO_MD5) 65 'TeSt',
66 otp2289.OTP_ALGO_MD5,
67 )
61 assert exc_info.type is otp2289.OTPStateException 68 assert exc_info.type is otp2289.OTPStateException
62 assert exc_info.value.args[0] == 'Step value MUST be an int' 69 assert exc_info.value.args[0] == 'Step value MUST be an int'
63 70
64 71
65def test_state_validation_md5(): 72def test_state_validation_md5():
66 """Tests the OTPState validation functionality for MD5""" 73 """Tests the OTPState validation functionality for MD5"""
67 state = otp2289.OTPState('0x7965e05436f5029f', 74 state = otp2289.OTPState(
68 1, 75 '0x7965e05436f5029f',
69 'TeSt', 76 1,
70 otp2289.OTP_ALGO_MD5) 77 'TeSt',
78 otp2289.OTP_ALGO_MD5,
79 )
71 assert state.validated is False 80 assert state.validated is False
72 assert state.response_validates('0x9e876134d90499dd') is True 81 assert state.response_validates('0x9e876134d90499dd') is True
73 assert state.response_validates('INCH SEA ANNE LONG AHEM TOUR') is True 82 assert state.response_validates('INCH SEA ANNE LONG AHEM TOUR') is True
@@ -76,10 +85,12 @@ def test_state_validation_md5():
76 85
77def test_state_validation_sha1(): 86def test_state_validation_sha1():
78 """Tests the OTPState validation functionality for SHA1""" 87 """Tests the OTPState validation functionality for SHA1"""
79 state = otp2289.OTPState('0x63d936639734385b', 88 state = otp2289.OTPState(
80 1, 89 '0x63d936639734385b',
81 'TeSt', 90 1,
82 otp2289.OTP_ALGO_SHA1) 91 'TeSt',
92 otp2289.OTP_ALGO_SHA1,
93 )
83 assert state.validated is False 94 assert state.validated is False
84 assert state.response_validates('0xbb9e6ae1979d8ff4') is True 95 assert state.response_validates('0xbb9e6ae1979d8ff4') is True
85 assert state.response_validates('MILT VARY MAST OK SEES WENT') is True 96 assert state.response_validates('MILT VARY MAST OK SEES WENT') is True
@@ -88,14 +99,20 @@ def test_state_validation_sha1():
88 99
89def test_store(): 100def test_store():
90 """Tests the OTPStore functionality""" 101 """Tests the OTPStore functionality"""
91 store_data = {'sgs': {'ot_hex': '0x7965e05436f5029f', 102 store_data = {
92 'current_step': 1, 103 'sgs': {
93 'seed': 'TeSt', 104 'ot_hex': '0x7965e05436f5029f',
94 'hash_algo': 'md5'}, 105 'current_step': 1,
95 'blackmore': {'ot_hex': '0x63d936639734385b', 106 'seed': 'TeSt',
96 'current_step': 1, 107 'hash_algo': 'md5',
97 'seed': 'TeSt', 108 },
98 'hash_algo': 'sha1'}} 109 'blackmore': {
110 'ot_hex': '0x63d936639734385b',
111 'current_step': 1,
112 'seed': 'TeSt',
113 'hash_algo': 'sha1',
114 },
115 }
99 store = otp2289.OTPStore(store_data) 116 store = otp2289.OTPStore(store_data)
100 assert len(store) == 2 117 assert len(store) == 2
101 assert isinstance(json.dumps(store.to_dict()), str) # serializable? 118 assert isinstance(json.dumps(store.to_dict()), str) # serializable?