diff --git a/muranoapi/utils.py b/muranoapi/utils.py index 2b5c8548..33490954 100644 --- a/muranoapi/utils.py +++ b/muranoapi/utils.py @@ -25,7 +25,7 @@ log = logging.getLogger(__name__) def verify_session(func): @functools.wraps(func) def __inner(self, request, *args, **kwargs): - if not hasattr(request, 'context') and not request.context.session: + if hasattr(request, 'context') and not request.context.session: log.info('Session is required for this call') raise exc.HTTPForbidden() @@ -34,6 +34,10 @@ def verify_session(func): unit = get_session() session = unit.query(Session).get(session_id) + if session is None: + log.info('Session is not found'.format(session_id)) + raise exc.HTTPForbidden() + if not SessionServices.validate(session): log.info('Session is invalid'.format(session_id)) raise exc.HTTPForbidden()