From f19fde48c6b3f65c164c931286e72a0d254c1fb3 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Tue, 29 Mar 2022 20:44:03 +0200 Subject: Add the -P param and improve tests --- tests/test_server.py | 77 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 30 deletions(-) (limited to 'tests/test_server.py') 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 @@ # -*- coding: utf-8 -*- # SPDX-License-Identifier: BSD-2-Clause-FreeBSD # -# Copyright (c) 2020, Simeon Simeonov +# Copyright (c) 2020-2022, Simeon Simeonov # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -33,41 +33,50 @@ import otp2289 def test_state_caller_exceptions(): """Tests the exceptions when calling the OTPState objects""" - state = otp2289.OTPState('0x7965e05436f5029f', - 1, - 'TeSt', - otp2289.OTP_ALGO_MD5) + state = otp2289.OTPState( + '0x7965e05436f5029f', + 1, + 'TeSt', + otp2289.OTP_ALGO_MD5, + ) with pytest.raises(otp2289.OTPInvalidResponse) as exc_info: state.response_validates('bla') assert exc_info.type is otp2289.OTPInvalidResponse assert exc_info.value.args[0] == ( - 'The response is neither a valid token or hex') + 'The response is neither a valid token or hex' + ) def test_state_constructor_exceptions(): """Tests the exceptions when initializing new OTPState objects""" with pytest.raises(otp2289.OTPStateException) as exc_info: - otp2289.OTPState('0x7965e05436f5029t', - 1, - 'TeStø'.encode(), - otp2289.OTP_ALGO_MD5) + otp2289.OTPState( + '0x7965e05436f5029t', + 1, + 'TeStø'.encode(), + otp2289.OTP_ALGO_MD5, + ) assert exc_info.type is otp2289.OTPStateException assert exc_info.value.args[0] == 'Seed must be a string' with pytest.raises(otp2289.OTPStateException) as exc_info: - otp2289.OTPState('0x7965e05436f5029t', - '1', - 'TeSt', - otp2289.OTP_ALGO_MD5) + otp2289.OTPState( + '0x7965e05436f5029t', + '1', + 'TeSt', + otp2289.OTP_ALGO_MD5, + ) assert exc_info.type is otp2289.OTPStateException assert exc_info.value.args[0] == 'Step value MUST be an int' def test_state_validation_md5(): """Tests the OTPState validation functionality for MD5""" - state = otp2289.OTPState('0x7965e05436f5029f', - 1, - 'TeSt', - otp2289.OTP_ALGO_MD5) + state = otp2289.OTPState( + '0x7965e05436f5029f', + 1, + 'TeSt', + otp2289.OTP_ALGO_MD5, + ) assert state.validated is False assert state.response_validates('0x9e876134d90499dd') is True assert state.response_validates('INCH SEA ANNE LONG AHEM TOUR') is True @@ -76,10 +85,12 @@ def test_state_validation_md5(): def test_state_validation_sha1(): """Tests the OTPState validation functionality for SHA1""" - state = otp2289.OTPState('0x63d936639734385b', - 1, - 'TeSt', - otp2289.OTP_ALGO_SHA1) + state = otp2289.OTPState( + '0x63d936639734385b', + 1, + 'TeSt', + otp2289.OTP_ALGO_SHA1, + ) assert state.validated is False assert state.response_validates('0xbb9e6ae1979d8ff4') is True assert state.response_validates('MILT VARY MAST OK SEES WENT') is True @@ -88,14 +99,20 @@ def test_state_validation_sha1(): def test_store(): """Tests the OTPStore functionality""" - store_data = {'sgs': {'ot_hex': '0x7965e05436f5029f', - 'current_step': 1, - 'seed': 'TeSt', - 'hash_algo': 'md5'}, - 'blackmore': {'ot_hex': '0x63d936639734385b', - 'current_step': 1, - 'seed': 'TeSt', - 'hash_algo': 'sha1'}} + store_data = { + 'sgs': { + 'ot_hex': '0x7965e05436f5029f', + 'current_step': 1, + 'seed': 'TeSt', + 'hash_algo': 'md5', + }, + 'blackmore': { + 'ot_hex': '0x63d936639734385b', + 'current_step': 1, + 'seed': 'TeSt', + 'hash_algo': 'sha1', + }, + } store = otp2289.OTPStore(store_data) assert len(store) == 2 assert isinstance(json.dumps(store.to_dict()), str) # serializable? -- cgit v1.3