예제 #1
0
def test_obtain_session(session_fixture):
    session = UbusSession(TIMEOUT, session_fixture)
    assert session.expires_in == TIMEOUT
    assert len(session) == 3
    assert sorted([e for e in session]) == ['test1', 'test2', 'test3']
    assert session['test1'] == 1
    assert session['test2'] == "2"
    assert session['test3']
    assert session.get('test3', False)
예제 #2
0
def test_obtain_session(session_fixture):
    session = UbusSession(TIMEOUT, session_fixture)
    assert session.expires_in == TIMEOUT
    assert len(session) == 3
    assert sorted([e for e in session]) == ["test1", "test2", "test3"]
    assert session["test1"] == 1
    assert session["test2"] == "2"
    assert session["test3"]
    assert session.get("test3", False)
예제 #3
0
def test_save():
    session = UbusSession(TIMEOUT)
    session['test1'] = 1
    session['test2'] = 2
    session['test3'] = 3
    session.save()

    session = UbusSession(TIMEOUT, session_id=session.session_id)
    assert len(session) == 3
    assert sorted([e for e in session]) == ['test1', 'test2', 'test3']
    assert [session[s] for s in sorted([e for e in session])] == [1, 2, 3]
    assert session['test1'] == 1
    assert session['test2'] == 2
    assert session['test3'] == 3
    assert 'test1' in session
    assert 'test2' in session
    assert 'test3' in session

    del session['test2']
    session['test1'] = 0
    session['test4'] = 4
    session['test5'] = 5
    session.save()

    session = UbusSession(TIMEOUT, session_id=session.session_id)
    assert len(session) == 4
    assert sorted([e for e in session]) == ['test1', 'test3', 'test4', 'test5']
    assert [session[s] for s in sorted([e for e in session])] == [0, 3, 4, 5]
    assert session['test1'] == 0
    assert session['test2'] is None
    assert session['test3'] == 3
    assert session['test4'] == 4
    assert session['test5'] == 5
    assert session.get('test2') is None
    assert session.get('test2', True)
    assert session.get('test5', False) == 5

    assert 'test1' in session
    assert 'test2' not in session
    assert 'test3' in session
    assert 'test4' in session
    assert 'test5' in session

    session.destroy()
예제 #4
0
def test_save():
    session = UbusSession(TIMEOUT)
    session["test1"] = 1
    session["test2"] = 2
    session["test3"] = 3
    session.save()

    session = UbusSession(TIMEOUT, session_id=session.session_id)
    assert len(session) == 3
    assert sorted([e for e in session]) == ["test1", "test2", "test3"]
    assert [session[s] for s in sorted([e for e in session])] == [1, 2, 3]
    assert session["test1"] == 1
    assert session["test2"] == 2
    assert session["test3"] == 3
    assert "test1" in session
    assert "test2" in session
    assert "test3" in session

    del session["test2"]
    session["test1"] = 0
    session["test4"] = 4
    session["test5"] = 5
    session.save()

    session = UbusSession(TIMEOUT, session_id=session.session_id)
    assert len(session) == 4
    assert sorted([e for e in session]) == ["test1", "test3", "test4", "test5"]
    assert [session[s] for s in sorted([e for e in session])] == [0, 3, 4, 5]
    assert session["test1"] == 0
    assert session["test2"] is None
    assert session["test3"] == 3
    assert session["test4"] == 4
    assert session["test5"] == 5
    assert session.get("test2") is None
    assert session.get("test2", True)
    assert session.get("test5", False) == 5

    assert "test1" in session
    assert "test2" not in session
    assert "test3" in session
    assert "test4" in session
    assert "test5" in session

    session.destroy()
예제 #5
0
class SessionForisProxy(SessionProxy):
    DONT_STORE_IN_ANONYMOUS = [
        "user_authenticated",
    ]

    def __init__(self, env_key, timeout, session_id):
        super(SessionForisProxy, self).__init__(env_key, timeout)
        self._session = UbusSession(self.timeout, session_id)
        self.tainted = False
        if self.is_anonymous:
            self._session.filtered_keys = list(
                SessionForisProxy.DONT_STORE_IN_ANONYMOUS)
        self.ws_session = None
        logger.debug("session '%s' loaded" % self.session_id)

    def __len__(self):
        return self._session.__len__()

    def __setitem__(self, key, value):
        self.tainted = True
        return self._session.__setitem__(key, value)

    def __contains__(self, key):
        return self._session.__contains__(key)

    def __iter__(self):
        return self._session.__iter__()

    def __delitem__(self, key):
        self.tainted = True
        return self._session.__delitem__(key)

    def __getitem__(self, key):
        return self._session.__getitem__(key)

    def get(self, *args, **kwargs):
        return self._session.get(*args, **kwargs)

    def save(self):
        self._session.save()
        self.tainted = False
        logger.debug("session '%s' stored" % self.session_id)

    def destroy(self):
        self._session.destroy()
        self.tainted = False
        logger.debug("session '%s' destroyed" % self.session_id)
        if self.ws_session:
            self.ws_session.destroy()

    def recreate(self):
        if not self.is_anonymous:
            self.unload()
            self.ws_session.unload()
            self.destroy()

        self._session = UbusSession(self.timeout)
        logger.debug("session '%s' created" % self.session_id)
        self._session.filtered_keys = []
        self.load()

    def load_anonymous(self):
        if self.is_anonymous:
            return  # already loaded

        self.destroy()
        self.unload()
        self._session = UbusSession(self.timeout,
                                    session_id=UbusSession.ANONYMOUS)
        self._session.filtered_keys = list(
            SessionForisProxy.DONT_STORE_IN_ANONYMOUS)
        self.ws_session = None
예제 #6
0
파일: sessions.py 프로젝트: CZ-NIC/foris
class SessionForisProxy(SessionProxy):
    DONT_STORE_IN_ANONYMOUS = ["user_authenticated"]

    def __init__(self, env_key, timeout, session_id):
        super(SessionForisProxy, self).__init__(env_key, timeout)
        self._session = UbusSession(self.timeout, session_id)
        self.tainted = False
        if self.is_anonymous:
            self._session.filtered_keys = list(SessionForisProxy.DONT_STORE_IN_ANONYMOUS)
        self.ws_session = None
        logger.debug("session '%s' loaded" % self.session_id)

    def __len__(self):
        return self._session.__len__()

    def __setitem__(self, key, value):
        self.tainted = True
        return self._session.__setitem__(key, value)

    def __contains__(self, key):
        return self._session.__contains__(key)

    def __iter__(self):
        return self._session.__iter__()

    def __delitem__(self, key):
        self.tainted = True
        return self._session.__delitem__(key)

    def __getitem__(self, key):
        return self._session.__getitem__(key)

    def get(self, *args, **kwargs):
        return self._session.get(*args, **kwargs)

    def save(self):
        self._session.save()
        self.tainted = False
        logger.debug("session '%s' stored" % self.session_id)

    def destroy(self):
        self._session.destroy()
        self.tainted = False
        logger.debug("session '%s' destroyed" % self.session_id)
        if self.ws_session:
            self.ws_session.destroy()

    def recreate(self):
        if not self.is_anonymous:
            self.unload()
            self.ws_session.unload()
            self.destroy()

        self._session = UbusSession(self.timeout)
        logger.debug("session '%s' created" % self.session_id)
        self._session.filtered_keys = []
        self.load()

    def load_anonymous(self):
        if self.is_anonymous:
            return  # already loaded

        self.destroy()
        self.unload()
        self._session = UbusSession(self.timeout, session_id=UbusSession.ANONYMOUS)
        self._session.filtered_keys = list(SessionForisProxy.DONT_STORE_IN_ANONYMOUS)
        self.ws_session = None