Exemplo n.º 1
0
    def __init__(self,
                 user=None,
                 session_id=None,
                 has_otp=False,
                 has_sudo=False):
        super(MockRequest, self).__init__()
        self.method = "GET"

        if user is None:
            self.user = AnonymousUser()
        else:
            self.user = user

        session = SessionMiddleware()
        self.session = session.SessionStore(session_id)
        self._messages = SessionStorage(self)
        self.META = {"REMOTE_ADDR": "127.0.0.1"}

        # sudo
        ElevateMiddleware(lambda x: x)(self)
        if has_sudo:
            grant_sudo(self)

        # otp
        if has_otp:
            grant_otp(self, self.user)
        OTPMiddleware(lambda x: x)(self)
Exemplo n.º 2
0
            def validate_absolute_path(self, *args, **kwargs):
                session_id = getattr(
                    self.request.cookies.get('sessionid', None), 'value', None)
                from django.contrib.sessions.middleware import SessionMiddleware
                mw = SessionMiddleware()
                session_data = mw.SessionStore(session_id)
                if not session_data.get('logged_in', False):
                    raise tornado.web.HTTPError(403, 'not logged in')

                return super().validate_absolute_path(*args, **kwargs)
Exemplo n.º 3
0
            def open(self):
                self.session_id = session_id = getattr(
                    self.request.cookies.get('sessionid', None), 'value', None)
                from django.contrib.sessions.middleware import SessionMiddleware
                mw = SessionMiddleware()
                session_data = mw.SessionStore(session_id)

                if session_data.get('logged_in',
                                    False) or not service.http_auth:
                    self.logged_in = True
                else:
                    service.logger.warning("Not (yet) logged in %s",
                                           session_id)

                service.logger.debug("WebSocket opened for session %s",
                                     session_id)
                service._sockets.append(self)