Пример #1
0
class TestDefaultToken(object):
    @pytest.fixture(autouse=True)
    def setup_token_handler(self):
        password = "******"
        grant_expires_in = 600
        self.th = DefaultToken(password, typ="A", lifetime=grant_expires_in)

    def test_default_token_split_token(self):
        _token = self.th("session_id")
        p = self.th.split_token(_token)
        assert p[1] == "A"
        assert p[2] == "session_id"

    def test_default_token_info(self):
        _token = self.th("another_id")
        _info = self.th.info(_token)

        assert set(_info.keys()) == {
            "_id",
            "type",
            "sid",
            "exp",
            "handler",
        }
        assert _info["handler"] == self.th

    def test_is_expired(self):
        _token = self.th("another_id")
        assert self.th.is_expired(_token) is False

        when = time.time() + 900
        assert self.th.is_expired(_token, when)
Пример #2
0
    def setup_token_handler(self):
        password = "******"
        grant_expires_in = 600
        token_expires_in = 900
        refresh_token_expires_in = 86400

        code_handler = DefaultToken(password, typ="A", lifetime=grant_expires_in)
        access_token_handler = DefaultToken(
            password, typ="T", lifetime=token_expires_in
        )
        refresh_token_handler = DefaultToken(
            password, typ="R", lifetime=refresh_token_expires_in
        )

        self.handler = TokenHandler(
            code_handler=code_handler,
            access_token_handler=access_token_handler,
            refresh_token_handler=refresh_token_handler,
        )
class TestDefaultToken(object):
    @pytest.fixture(autouse=True)
    def setup_token_handler(self):
        password = "******"
        grant_expires_in = 600
        self.th = DefaultToken(password, typ='A', lifetime=grant_expires_in)

    def test_default_token_split_token(self):
        _token = self.th('session_id')
        p = self.th.split_token(_token)
        assert p[1] == 'A'
        assert p[2] == 'session_id'

    def test_default_token_info(self):
        _token = self.th('another_id')
        _info = self.th.info(_token)

        assert set(_info.keys()) == {
            '_id', 'type', 'sid', 'exp', 'handler', 'black_listed'
        }
        assert _info['handler'] == self.th
        assert _info['black_listed'] is False

    def test_is_expired(self):
        _token = self.th('another_id')
        assert self.th.is_expired(_token) is False

        when = time.time() + 900
        assert self.th.is_expired(_token, when)

    def test_blacklist(self):
        _token = self.th('another_id')
        self.th.black_list(_token)
        assert self.th.is_black_listed(_token)

        _info = self.th.info(_token)
        assert _info['black_listed'] is True
Пример #4
0
 def setup_token_handler(self):
     password = "******"
     grant_expires_in = 600
     self.th = DefaultToken(password, typ="A", lifetime=grant_expires_in)