Exemplo n.º 1
0
class TestSessionDB(object):
    @pytest.fixture(autouse=True)
    def create_sdb(self):
        self.sso_db = SSODb()

    def test_map_sid2uid(self):
        self.sso_db.map_sid2uid("session id 1", "Lizz")
        assert self.sso_db.get_sids_by_uid("Lizz") == ["session id 1"]

    def test_missing_map(self):
        assert self.sso_db.get_sids_by_uid("Lizz") is None

    def test_multiple_map_sid2uid(self):
        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Lizz")
        assert set(self.sso_db.get_sids_by_uid("Lizz")) == {
            "session id 1",
            "session id 2",
        }

    def test_map_unmap_sid2uid(self):
        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Lizz")
        assert set(self.sso_db.get_sids_by_uid("Lizz")) == {
            "session id 1",
            "session id 2",
        }

        self.sso_db.remove_sid2uid("session id 1", "Lizz")
        assert self.sso_db.get_sids_by_uid("Lizz") == ["session id 2"]

    def test_get_uid_by_sid(self):
        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Lizz")

        assert self.sso_db.get_uid_by_sid("session id 1") == "Lizz"
        assert self.sso_db.get_uid_by_sid("session id 2") == "Lizz"

    def test_remove_uid(self):
        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Diana")

        self.sso_db.remove_uid("Lizz")
        assert self.sso_db.get_uid_by_sid("session id 1") is None
        assert self.sso_db.get_sids_by_uid("Lizz") is None

    def test_map_sid2sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        assert self.sso_db.get_sids_by_sub("abcdefgh") == ["session id 1"]

    def test_missing_sid2sub_map(self):
        assert self.sso_db.get_sids_by_sub("abcdefgh") is None

    def test_multiple_map_sid2sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "abcdefgh")
        assert set(self.sso_db.get_sids_by_sub("abcdefgh")) == {
            "session id 1",
            "session id 2",
        }

    def test_map_unmap_sid2sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "abcdefgh")
        assert set(self.sso_db.get_sids_by_sub("abcdefgh")) == {
            "session id 1",
            "session id 2",
        }

        self.sso_db.remove_sid2sub("session id 1", "abcdefgh")
        assert self.sso_db.get_sids_by_sub("abcdefgh") == ["session id 2"]

    def test_get_sub_by_sid(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "abcdefgh")

        assert set(self.sso_db.get_sids_by_sub("abcdefgh")) == {
            "session id 1",
            "session id 2",
        }

    def test_remove_sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "012346789")

        self.sso_db.remove_sub("abcdefgh")
        assert self.sso_db.get_sub_by_sid("session id 1") is None
        assert self.sso_db.get_sids_by_sub("abcdefgh") is None
        # have not touched the others
        assert self.sso_db.get_sub_by_sid("session id 2") == "012346789"
        assert self.sso_db.get_sids_by_sub("012346789") == ["session id 2"]

    def test_get_sub_by_uid_same_sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "abcdefgh")

        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Lizz")

        res = self.sso_db.get_subs_by_uid("Lizz")

        assert set(res) == {"abcdefgh"}

    def test_get_sub_by_uid_different_sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "012346789")

        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Lizz")

        res = self.sso_db.get_subs_by_uid("Lizz")

        assert set(res) == {"abcdefgh", "012346789"}
Exemplo n.º 2
0
class TestSessionShelveDB(object):
    @pytest.fixture(autouse=True)
    def create_sdb(self):
        # Create fresh database each time
        _db = ShelveDataBase(filename='shelf', flag='n', writeback=True)
        self.sso_db = SSODb(_db)

    def _reset(self):
        self.sso_db.clear()
        self.sso_db.close()

    def test_map_sid2uid(self):
        self.sso_db.map_sid2uid("session id 1", "Lizz")
        assert self.sso_db.get_sids_by_uid("Lizz") == ["session id 1"]
        self._reset()

    def test_missing_map(self):
        assert self.sso_db.get_sids_by_uid("Lizz") is None
        self._reset()

    def test_multiple_map_sid2uid(self):
        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Lizz")
        assert set(self.sso_db.get_sids_by_uid("Lizz")) == {
            "session id 1",
            "session id 2",
        }
        self._reset()

    def test_map_unmap_sid2uid(self):
        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Lizz")
        assert set(self.sso_db.get_sids_by_uid("Lizz")) == {
            "session id 1",
            "session id 2",
        }

        self.sso_db.remove_sid2uid("session id 1", "Lizz")
        assert self.sso_db.get_sids_by_uid("Lizz") == ["session id 2"]
        self._reset()

    def test_get_uid_by_sid(self):
        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Lizz")

        assert self.sso_db.get_uid_by_sid("session id 1") == "Lizz"
        assert self.sso_db.get_uid_by_sid("session id 2") == "Lizz"
        self._reset()

    def test_remove_uid(self):
        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Diana")

        self.sso_db.remove_uid("Lizz")
        assert self.sso_db.get_uid_by_sid("session id 1") is None
        assert self.sso_db.get_sids_by_uid("Lizz") is None
        self._reset()

    def test_map_sid2sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        assert self.sso_db.get_sids_by_sub("abcdefgh") == ["session id 1"]
        self._reset()

    def test_missing_sid2sub_map(self):
        assert self.sso_db.get_sids_by_sub("abcdefgh") is None
        self._reset()

    def test_multiple_map_sid2sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "abcdefgh")
        assert set(self.sso_db.get_sids_by_sub("abcdefgh")) == {
            "session id 1",
            "session id 2",
        }
        self._reset()

    def test_map_unmap_sid2sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "abcdefgh")
        assert set(self.sso_db.get_sids_by_sub("abcdefgh")) == {
            "session id 1",
            "session id 2",
        }

        self.sso_db.remove_sid2sub("session id 1", "abcdefgh")
        assert self.sso_db.get_sids_by_sub("abcdefgh") == ["session id 2"]
        self._reset()

    def test_get_sub_by_sid(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "abcdefgh")

        assert set(self.sso_db.get_sids_by_sub("abcdefgh")) == {
            "session id 1",
            "session id 2",
        }
        self._reset()

    def test_remove_sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "012346789")

        self.sso_db.remove_sub("abcdefgh")
        assert self.sso_db.get_sub_by_sid("session id 1") is None
        assert self.sso_db.get_sids_by_sub("abcdefgh") is None
        # have not touched the others
        assert self.sso_db.get_sub_by_sid("session id 2") == "012346789"
        assert self.sso_db.get_sids_by_sub("012346789") == ["session id 2"]
        self._reset()

    def test_get_sub_by_uid_same_sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "abcdefgh")

        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Lizz")

        res = self.sso_db.get_subs_by_uid("Lizz")

        assert set(res) == {"abcdefgh"}
        self._reset()

    def test_get_sub_by_uid_different_sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "012346789")

        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Lizz")

        res = self.sso_db.get_subs_by_uid("Lizz")

        assert set(res) == {"abcdefgh", "012346789"}
        self._reset()
Exemplo n.º 3
0
class TestSessionDB(object):
    @pytest.fixture(autouse=True)
    def create_sdb(self):
        self.sso_db = SSODb()

    def test_map_sid2uid(self):
        self.sso_db.map_sid2uid('session id 1', 'Lizz')
        assert self.sso_db.get_sids_by_uid('Lizz') == ['session id 1']

    def test_missing_map(self):
        assert self.sso_db.get_sids_by_uid('Lizz') is None

    def test_multiple_map_sid2uid(self):
        self.sso_db.map_sid2uid('session id 1', 'Lizz')
        self.sso_db.map_sid2uid('session id 2', 'Lizz')
        assert set(self.sso_db.get_sids_by_uid('Lizz')) == {
            'session id 1', 'session id 2'
        }

    def test_map_unmap_sid2uid(self):
        self.sso_db.map_sid2uid('session id 1', 'Lizz')
        self.sso_db.map_sid2uid('session id 2', 'Lizz')
        assert set(self.sso_db.get_sids_by_uid('Lizz')) == {
            'session id 1', 'session id 2'
        }

        self.sso_db.remove_sid2uid('session id 1', 'Lizz')
        assert self.sso_db.get_sids_by_uid('Lizz') == ['session id 2']

    def test_get_uid_by_sid(self):
        self.sso_db.map_sid2uid('session id 1', 'Lizz')
        self.sso_db.map_sid2uid('session id 2', 'Lizz')

        assert self.sso_db.get_uid_by_sid('session id 1') == 'Lizz'
        assert self.sso_db.get_uid_by_sid('session id 2') == 'Lizz'

    def test_remove_uid(self):
        self.sso_db.map_sid2uid('session id 1', 'Lizz')
        self.sso_db.map_sid2uid('session id 2', 'Diana')

        self.sso_db.remove_uid('Lizz')
        assert self.sso_db.get_uid_by_sid('session id 1') is None
        assert self.sso_db.get_sids_by_uid('Lizz') is None

    def test_map_sid2sub(self):
        self.sso_db.map_sid2sub('session id 1', 'abcdefgh')
        assert self.sso_db.get_sids_by_sub('abcdefgh') == ['session id 1']

    def test_missing_sid2sub_map(self):
        assert self.sso_db.get_sids_by_sub('abcdefgh') is None

    def test_multiple_map_sid2sub(self):
        self.sso_db.map_sid2sub('session id 1', 'abcdefgh')
        self.sso_db.map_sid2sub('session id 2', 'abcdefgh')
        assert set(self.sso_db.get_sids_by_sub('abcdefgh')) == {
            'session id 1', 'session id 2'
        }

    def test_map_unmap_sid2sub(self):
        self.sso_db.map_sid2sub('session id 1', 'abcdefgh')
        self.sso_db.map_sid2sub('session id 2', 'abcdefgh')
        assert set(self.sso_db.get_sids_by_sub('abcdefgh')) == {
            'session id 1', 'session id 2'
        }

        self.sso_db.remove_sid2sub('session id 1', 'abcdefgh')
        assert self.sso_db.get_sids_by_sub('abcdefgh') == ['session id 2']

    def test_get_sub_by_sid(self):
        self.sso_db.map_sid2sub('session id 1', 'abcdefgh')
        self.sso_db.map_sid2sub('session id 2', 'abcdefgh')

        assert set(self.sso_db.get_sids_by_sub('abcdefgh')) == {
            'session id 1', 'session id 2'
        }

    def test_remove_sub(self):
        self.sso_db.map_sid2sub('session id 1', 'abcdefgh')
        self.sso_db.map_sid2sub('session id 2', '012346789')

        self.sso_db.remove_sub('abcdefgh')
        assert self.sso_db.get_sub_by_sid('session id 1') is None
        assert self.sso_db.get_sids_by_sub('abcdefgh') is None
        # have not touched the others
        assert self.sso_db.get_sub_by_sid('session id 2') == '012346789'
        assert self.sso_db.get_sids_by_sub('012346789') == ['session id 2']

    def test_get_sub_by_uid_same_sub(self):
        self.sso_db.map_sid2sub('session id 1', 'abcdefgh')
        self.sso_db.map_sid2sub('session id 2', 'abcdefgh')

        self.sso_db.map_sid2uid('session id 1', 'Lizz')
        self.sso_db.map_sid2uid('session id 2', 'Lizz')

        res = self.sso_db.get_subs_by_uid('Lizz')

        assert set(res) == {'abcdefgh'}

    def test_get_sub_by_uid_different_sub(self):
        self.sso_db.map_sid2sub('session id 1', 'abcdefgh')
        self.sso_db.map_sid2sub('session id 2', '012346789')

        self.sso_db.map_sid2uid('session id 1', 'Lizz')
        self.sso_db.map_sid2uid('session id 2', 'Lizz')

        res = self.sso_db.get_subs_by_uid('Lizz')

        assert set(res) == {'abcdefgh', '012346789'}
Exemplo n.º 4
0
class TestSessionDB(object):
    @pytest.fixture(autouse=True)
    def create_sdb(self):
        self.sso_db = SSODb()

    def test_map_sid2uid(self):
        self.sso_db.map_sid2uid('session id 1', 'Lizz')
        assert self.sso_db.get_sids_by_uid('Lizz') == ['session id 1']

    def test_missing_map(self):
        with pytest.raises(KeyError):
            self.sso_db.get_sids_by_uid('Lizz')

    def test_multiple_map_sid2uid(self):
        self.sso_db.map_sid2uid('session id 1', 'Lizz')
        self.sso_db.map_sid2uid('session id 2', 'Lizz')
        assert set(self.sso_db.get_sids_by_uid('Lizz')) == {
            'session id 1', 'session id 2'
        }

    def test_map_unmap_sid2uid(self):
        self.sso_db.map_sid2uid('session id 1', 'Lizz')
        self.sso_db.map_sid2uid('session id 2', 'Lizz')
        assert set(self.sso_db.get_sids_by_uid('Lizz')) == {
            'session id 1', 'session id 2'
        }

        self.sso_db.unmap_sid2uid('session id 1', 'Lizz')
        assert self.sso_db.get_sids_by_uid('Lizz') == ['session id 2']

    def test_get_uid_by_sid(self):
        self.sso_db.map_sid2uid('session id 1', 'Lizz')
        self.sso_db.map_sid2uid('session id 2', 'Lizz')

        assert self.sso_db.get_uid_by_sid('session id 1') == 'Lizz'
        assert self.sso_db.get_uid_by_sid('session id 2') == 'Lizz'

    def test_remove_uid(self):
        self.sso_db.map_sid2uid('session id 1', 'Lizz')
        self.sso_db.map_sid2uid('session id 2', 'Diana')

        self.sso_db.remove_uid('Lizz')
        assert set(self.sso_db.uid2sid.keys()) == {'Diana'}
        assert set(self.sso_db.uid2sid_rev.keys()) == {'session id 2'}

    def test_map_sid2sub(self):
        self.sso_db.map_sid2sub('session id 1', 'abcdefgh')
        assert self.sso_db.get_sids_by_sub('abcdefgh') == ['session id 1']

    def test_missing_sid2sub_map(self):
        with pytest.raises(KeyError):
            self.sso_db.get_sids_by_sub('abcdefgh')

    def test_multiple_map_sid2sub(self):
        self.sso_db.map_sid2sub('session id 1', 'abcdefgh')
        self.sso_db.map_sid2sub('session id 2', 'abcdefgh')
        assert set(self.sso_db.get_sids_by_sub('abcdefgh')) == {
            'session id 1', 'session id 2'
        }

    def test_map_unmap_sid2sub(self):
        self.sso_db.map_sid2sub('session id 1', 'abcdefgh')
        self.sso_db.map_sid2sub('session id 2', 'abcdefgh')
        assert set(self.sso_db.get_sids_by_sub('abcdefgh')) == {
            'session id 1', 'session id 2'
        }

        self.sso_db.unmap_sid2sub('session id 1', 'abcdefgh')
        assert self.sso_db.get_sids_by_sub('abcdefgh') == ['session id 2']

    def test_get_sub_by_sid(self):
        self.sso_db.map_sid2sub('session id 1', 'abcdefgh')
        self.sso_db.map_sid2sub('session id 2', 'abcdefgh')

        assert set(self.sso_db.get_sids_by_sub('abcdefgh')) == {
            'session id 1', 'session id 2'
        }

    def test_remove_sub(self):
        self.sso_db.map_sid2sub('session id 1', 'abcdefgh')
        self.sso_db.map_sid2sub('session id 2', '012346789')

        self.sso_db.remove_sub('012346789')
        assert set(self.sso_db.sub2sid.keys()) == {'abcdefgh'}
        assert set(self.sso_db.sub2sid_rev.keys()) == {'session id 1'}

    def test_get_sub_by_uid_same_sub(self):
        self.sso_db.map_sid2sub('session id 1', 'abcdefgh')
        self.sso_db.map_sid2sub('session id 2', 'abcdefgh')

        self.sso_db.map_sid2uid('session id 1', 'Lizz')
        self.sso_db.map_sid2uid('session id 2', 'Lizz')

        res = self.sso_db.get_sub_by_uid('Lizz')

        assert res == {'abcdefgh'}

    def test_get_sub_by_uid_different_sub(self):
        self.sso_db.map_sid2sub('session id 1', 'abcdefgh')
        self.sso_db.map_sid2sub('session id 2', '012346789')

        self.sso_db.map_sid2uid('session id 1', 'Lizz')
        self.sso_db.map_sid2uid('session id 2', 'Lizz')

        res = self.sso_db.get_sub_by_uid('Lizz')

        assert res == {'abcdefgh', '012346789'}
Exemplo n.º 5
0
class TestSessionDB(object):
    @pytest.fixture(autouse=True)
    def create_sdb(self):
        self.sso_db = SSODb()

    def test_map_sid2uid(self):
        self.sso_db.map_sid2uid("session id 1", "Lizz")
        assert self.sso_db.get_sids_by_uid("Lizz") == ["session id 1"]

    def test_missing_map(self):
        with pytest.raises(KeyError):
            self.sso_db.get_sids_by_uid("Lizz")

    def test_multiple_map_sid2uid(self):
        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Lizz")
        assert set(self.sso_db.get_sids_by_uid("Lizz")) == {
            "session id 1",
            "session id 2",
        }

    def test_map_unmap_sid2uid(self):
        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Lizz")
        assert set(self.sso_db.get_sids_by_uid("Lizz")) == {
            "session id 1",
            "session id 2",
        }

        self.sso_db.unmap_sid2uid("session id 1", "Lizz")
        assert self.sso_db.get_sids_by_uid("Lizz") == ["session id 2"]

    def test_get_uid_by_sid(self):
        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Lizz")

        assert self.sso_db.get_uid_by_sid("session id 1") == "Lizz"
        assert self.sso_db.get_uid_by_sid("session id 2") == "Lizz"

    def test_remove_uid(self):
        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Diana")

        self.sso_db.remove_uid("Lizz")
        assert set(self.sso_db.uid2sid.keys()) == {"Diana"}
        assert set(self.sso_db.uid2sid_rev.keys()) == {"session id 2"}

    def test_map_sid2sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        assert self.sso_db.get_sids_by_sub("abcdefgh") == ["session id 1"]

    def test_missing_sid2sub_map(self):
        with pytest.raises(KeyError):
            self.sso_db.get_sids_by_sub("abcdefgh")

    def test_multiple_map_sid2sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "abcdefgh")
        assert set(self.sso_db.get_sids_by_sub("abcdefgh")) == {
            "session id 1",
            "session id 2",
        }

    def test_map_unmap_sid2sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "abcdefgh")
        assert set(self.sso_db.get_sids_by_sub("abcdefgh")) == {
            "session id 1",
            "session id 2",
        }

        self.sso_db.unmap_sid2sub("session id 1", "abcdefgh")
        assert self.sso_db.get_sids_by_sub("abcdefgh") == ["session id 2"]

    def test_get_sub_by_sid(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "abcdefgh")

        assert set(self.sso_db.get_sids_by_sub("abcdefgh")) == {
            "session id 1",
            "session id 2",
        }

    def test_remove_sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "012346789")

        self.sso_db.remove_sub("012346789")
        assert set(self.sso_db.sub2sid.keys()) == {"abcdefgh"}
        assert set(self.sso_db.sub2sid_rev.keys()) == {"session id 1"}

    def test_get_sub_by_uid_same_sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "abcdefgh")

        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Lizz")

        res = self.sso_db.get_sub_by_uid("Lizz")

        assert res == {"abcdefgh"}

    def test_get_sub_by_uid_different_sub(self):
        self.sso_db.map_sid2sub("session id 1", "abcdefgh")
        self.sso_db.map_sid2sub("session id 2", "012346789")

        self.sso_db.map_sid2uid("session id 1", "Lizz")
        self.sso_db.map_sid2uid("session id 2", "Lizz")

        res = self.sso_db.get_sub_by_uid("Lizz")

        assert res == {"abcdefgh", "012346789"}