def test_session_not_exists(self): with patch("app.src.common.auth.config.redis", new=self.mock_redis) as mock_redis: exists = Auth.session_exists("session_id", "not") self.assertFalse(exists)
def wrapper(*args, **kwars): token = request.headers.get("Authorization") role = Utils.request_role() try: if not token or token.split(" ")[0] != "Bearer": raise InvalidTokenError(token, "Token must be a bearer token", "Invalid token") token_decode = Auth.token_decode(token.split(" ")[1]) session_id = token_decode["token"] exists = Auth.session_exists(session_id, role) if not exists: raise InvalidTokenError( token, "User does not have an active session", "Invalid token") except InvalidTokenError as e: return Utils.response(status=e.status, message="Invalid token", data=e.errors) return f(*args, **kwars)
def test_session_exists(self): with patch("app.src.common.auth.config.redis", new=self.mock_redis) as mock_redis: exists = Auth.session_exists("session_id", self.role) self.assertTrue(exists)