def test_totp_verify(): secret = os.urandom(20) key_length = 6 current_time = 400 hash_algorithm = "SHA256" totp = auth.get_totp(secret, key_length, hash_algorithm, 30) value = totp.generate(current_time) assert auth.totp_verify(secret, key_length, hash_algorithm, 30, value, current_time, 0) assert auth.totp_verify(secret, key_length, hash_algorithm, 30, value, current_time, 1) with pytest.raises(auth.ValidationException): auth.totp_verify(secret, key_length, hash_algorithm, 60, value, current_time, 0) with pytest.raises(auth.ValidationException): auth.totp_verify(secret, key_length, hash_algorithm, 30, b"999999", current_time, 0)
def test_totp_verify(): secret = os.urandom(20) key_length = 6 current_time = 400 hash_algorithm = 'SHA256' totp = auth.get_totp(secret, key_length, hash_algorithm, 30) value = totp.generate(current_time) assert auth.totp_verify(secret, key_length, hash_algorithm, 30, value, current_time, 0) assert auth.totp_verify(secret, key_length, hash_algorithm, 30, value, current_time, 1) with pytest.raises(auth.ValidationException): auth.totp_verify(secret, key_length, hash_algorithm, 60, value, current_time, 0) with pytest.raises(auth.ValidationException): auth.totp_verify(secret, key_length, hash_algorithm, 30, b'999999', current_time, 0)
def test_totp_verify_60_second_window(): secret = os.urandom(20) key_length = 6 current_time = 400 hash_algorithm = 'SHA256' totp = auth.get_totp(secret, key_length, hash_algorithm, 60) value = totp.generate(current_time) previous_window_value = totp.generate(340) next_window_value = totp.generate(460) assert auth.totp_verify(secret, key_length, hash_algorithm, 60, value, current_time, 0) with pytest.raises(auth.ValidationException): auth.totp_verify(secret, key_length, hash_algorithm, 60, previous_window_value, current_time, 0) with pytest.raises(auth.ValidationException): auth.totp_verify(secret, key_length, hash_algorithm, 60, next_window_value, current_time, 0) assert auth.totp_verify(secret, key_length, hash_algorithm, 60, value, current_time, 1) assert auth.totp_verify(secret, key_length, hash_algorithm, 60, previous_window_value, current_time, 1) assert auth.totp_verify(secret, key_length, hash_algorithm, 60, next_window_value, current_time, 1) with pytest.raises(auth.ValidationException): auth.totp_verify(secret, key_length, hash_algorithm, 60, b'999999', current_time, 0) with pytest.raises(auth.ValidationException): auth.totp_verify(secret, key_length, hash_algorithm, 30, value, current_time, 0)
def test_totp_verify_60_second_window(): secret = os.urandom(20) key_length = 6 current_time = 400 hash_algorithm = "SHA256" totp = auth.get_totp(secret, key_length, hash_algorithm, 60) value = totp.generate(current_time) previous_window_value = totp.generate(340) next_window_value = totp.generate(460) assert auth.totp_verify(secret, key_length, hash_algorithm, 60, value, current_time, 0) with pytest.raises(auth.ValidationException): auth.totp_verify(secret, key_length, hash_algorithm, 60, previous_window_value, current_time, 0) with pytest.raises(auth.ValidationException): auth.totp_verify(secret, key_length, hash_algorithm, 60, next_window_value, current_time, 0) assert auth.totp_verify(secret, key_length, hash_algorithm, 60, value, current_time, 1) assert auth.totp_verify(secret, key_length, hash_algorithm, 60, previous_window_value, current_time, 1) assert auth.totp_verify(secret, key_length, hash_algorithm, 60, next_window_value, current_time, 1) with pytest.raises(auth.ValidationException): auth.totp_verify(secret, key_length, hash_algorithm, 60, b"999999", current_time, 0) with pytest.raises(auth.ValidationException): auth.totp_verify(secret, key_length, hash_algorithm, 30, value, current_time, 0)