def test_generate_code_from_time_period_wrong_type(self): """Test Otp.generate_code_from_time(). Check for appropriate exception to wrong period type. """ cut = HOTP() with self.assertRaises(TypeError): cut.generate_code_from_time(self.secret, period=(6, 3))
def test_generate_code_from_time_period_not_numeric(self): """Test Otp.generate_code_from_time(). Check for appropriate exception to non-numeric period. """ cut = HOTP() with self.assertRaises(ValueError): cut.generate_code_from_time(self.secret, period="abc")
def test_generate_code_from_time_secret_wrong_type(self): """Test Otp.generate_code_from_time(). Check for appropriate exception to wrong secret type. """ cut = HOTP() with self.assertRaises(TypeError): cut.generate_code_from_time(1.234)
def test_generate_code_from_time_secret_wrong_type(self): """Test Otp.generate_code_from_time(). Check for appropriate exception to wrong secret type. """ cut = HOTP() with self.assertRaises(TypeError): cut.generate_code_from_time(1.234)
def test_generate_code_from_time_secret_wrong_base32_length(self): """Test Otp.generate_code_from_time(). Check for appropriate exception to secret string that is invalid base32 encoding (too long, bad padding). """ cut = HOTP() with self.assertRaises(ValueError): cut.generate_code_from_time("GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQAAA")
def test_generate_code_from_time_secret_bad_base32(self): """Test Otp.generate_code_from_time(). Check for appropriate exception to secret string that is invalid base32 encoding. """ cut = HOTP() with self.assertRaises(ValueError): cut.generate_code_from_time("GEZDGNBVGY1TQOJQGEZDGNBVGY1TQOJQ")
def test_generate_code_from_time_period_not_numeric(self): """Test Otp.generate_code_from_time(). Check for appropriate exception to non-numeric period. """ cut = HOTP() with self.assertRaises(ValueError): cut.generate_code_from_time( self.secret, period="abc")
def test_generate_code_from_time_period_wrong_type(self): """Test Otp.generate_code_from_time(). Check for appropriate exception to wrong period type. """ cut = HOTP() with self.assertRaises(TypeError): cut.generate_code_from_time( self.secret, period=(6, 3))
def test_generate_code_from_time_period_out_of_range(self): """Test Otp.generate_code_from_time(). Check for appropriate exception to out-of-range period. """ cut = HOTP() with self.assertRaises(ValueError): cut.generate_code_from_time(self.secret, period="0") with self.assertRaises(ValueError): cut.generate_code_from_time(self.secret, period=-1)
def test_generate_code_from_time_secret_wrong_base32_length(self): """Test Otp.generate_code_from_time(). Check for appropriate exception to secret string that is invalid base32 encoding (too long, bad padding). """ cut = HOTP() with self.assertRaises(ValueError): cut.generate_code_from_time( "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQAAA")
def test_generate_code_from_time_secret_bad_base32(self): """Test Otp.generate_code_from_time(). Check for appropriate exception to secret string that is invalid base32 encoding. """ cut = HOTP() with self.assertRaises(ValueError): cut.generate_code_from_time( "GEZDGNBVGY1TQOJQGEZDGNBVGY1TQOJQ")
def test_generate_code_from_time_period_out_of_range(self): """Test Otp.generate_code_from_time(). Check for appropriate exception to out-of-range period. """ cut = HOTP() with self.assertRaises(ValueError): cut.generate_code_from_time( self.secret, period="0") with self.assertRaises(ValueError): cut.generate_code_from_time( self.secret, period=-1)
def test_generate_code_from_time_b32_secret(self): """Test Otp.generate_code_from_time(). Check generate_code_from_time() against a reference implementation when passed secret as base32 string. """ cut = HOTP() # test with secret as base32 string # code_string, remaining_seconds = cut.generate_code_from_time( self.secret_base32) expected_code, expected_seconds = \ self.reference_generate_code_from_time(self.secret) if expected_seconds != remaining_seconds: # try again because the clocks were not the same when actual # and reference calls were made code_string, remaining_seconds = cut.generate_code_from_time( self.secret_base32) expected_code, expected_seconds = \ self.reference_generate_code_from_time(self.secret) self.assertEqual(expected_seconds, remaining_seconds) self.assertEqual(expected_code, code_string)
def test_generate_code_from_time_b32_secret(self): """Test Otp.generate_code_from_time(). Check generate_code_from_time() against a reference implementation when passed secret as base32 string. """ cut = HOTP() # test with secret as base32 string # code_string, remaining_seconds = cut.generate_code_from_time( self.secret_base32) expected_code, expected_seconds = \ self.reference_generate_code_from_time(self.secret) if expected_seconds != remaining_seconds: # try again because the clocks were not the same when actual # and reference calls were made code_string, remaining_seconds = cut.generate_code_from_time( self.secret_base32) expected_code, expected_seconds = \ self.reference_generate_code_from_time(self.secret) self.assertEqual(expected_seconds, remaining_seconds) self.assertEqual(expected_code, code_string)