Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
 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)