def test_cookie_to_state_handle_broken_cookies(self, cookie_str, name, encryption_key, expected_exception): """ Test that the cookie_to_state raises exception if the input is bad """ with pytest.raises(expected_exception): cookie_to_state(cookie_str, name, encryption_key)
def _load_state(self, context): """ Load a state to the context :type context: satosa.context.Context :param context: Session context """ try: state = cookie_to_state(context.cookie, self.config.COOKIE_STATE_NAME, self.config.STATE_ENCRYPTION_KEY) except SATOSAStateError: state = State() context.state = state
def test_state_cookie(): """ Test that the state can be converted between cookie and state """ state_key = "27614gjkrn" saved_data = "data" state = State() state.add(state_key, saved_data) cookie_name = "state_cookie" path = "/" encrypt_key = "2781y4hef90" cookie = state_to_cookie(state, cookie_name, path, encrypt_key) cookie_str = cookie.output() loaded_state = cookie_to_state(cookie_str, cookie_name, encrypt_key) assert loaded_state.get(state_key) == saved_data
def test_encode_decode_of_state(self): """ Test that the state can be converted between cookie and state """ state_key = "27614gjkrn" saved_data = "data" state = State() state[state_key] = saved_data cookie_name = "state_cookie" path = "/" encrypt_key = "2781y4hef90" cookie = state_to_cookie(state, cookie_name, path, encrypt_key) cookie_str = cookie[cookie_name].OutputString() loaded_state = cookie_to_state(cookie_str, cookie_name, encrypt_key) assert loaded_state[state_key] == saved_data
def test_fail_cookie_to_state(cookie_str, name, encryption_key, exception): """ Test that the cookie_to_state raises exception if the input is bad """ with pytest.raises(exception): cookie_to_state(cookie_str, name, encryption_key)