Пример #1
0
 def test_last_activity_in_future(self):
     self.client.login(username='******', password='******')
     now = datetime.now()
     future = now + timedelta(0, 30)
     set_last_activity(self.client.session, future)
     response = self.client.get('/admin/')
     self.assertTrue('_auth_user_id' in self.client.session)
 def test_last_activity_in_future(self):
     self.client.login(username='******', password='******')
     now = datetime.now()
     future = now + timedelta(0, 30)
     set_last_activity(self.client.session, future)
     response = self.client.get('/admin/')
     self.assertTrue('_auth_user_id' in self.client.session)
Пример #3
0
 def test_last_activity_in_future(self):
     self.client.login(username="******", password="******")
     now = datetime.now()
     future = now + timedelta(0, 30)
     set_last_activity(self.client.session, future)
     response = self.client.get("/admin/")
     self.assertTrue("_auth_user_id" in self.client.session)
Пример #4
0
    def test_ping(self, server, client, expected, authenticated=True):
        self.client.login(username="******", password="******")
        self.client.get("/admin/")

        now = datetime.now()
        session = self.client.session
        set_last_activity(session, now - timedelta(seconds=server))
        session.save()
        response = self.client.get("/session_security/ping/?idleFor=%s" % client)

        self.assertEqual(response.content, six.b(expected))
        self.assertEqual(authenticated, "_auth_user_id" in self.client.session)
Пример #5
0
    def process_request(self, request):
        """ Update last activity time or logout. """
        if not request.user.is_authenticated():
            return

        now = datetime.now()
        self.update_last_activity(request, now)

        delta = now - get_last_activity(request.session)
        if delta >= timedelta(seconds=EXPIRE_AFTER):
            logout(request)
        elif not self.is_passive_request(request):
            set_last_activity(request.session, now)
Пример #6
0
    def test_ping(self, server, client, expected, authenticated=True):
        self.client.login(username='******', password='******')
        self.client.get('/admin/')

        now = datetime.now()
        session = self.client.session
        set_last_activity(session, now - timedelta(seconds=server))
        session.save()
        response = self.client.get('/session_security/ping/?idleFor=%s' %
                                   client)

        self.assertEqual(response.content, six.b(expected))
        self.assertEqual(authenticated, '_auth_user_id' in self.client.session)
    def process_request(self, request):
        """ Update last activity time or logout. """
        if not request.user.is_authenticated():
            return

        now = datetime.now()
        self.update_last_activity(request, now)

        delta = now - get_last_activity(request.session)
        if delta >= timedelta(seconds=EXPIRE_AFTER):
            logout(request)
        elif not self.is_passive_request(request):
            set_last_activity(request.session, now)
Пример #8
0
    def test_ping(self, server, client, expected, authenticated=True):
        old_warn, old_expire = settings.WARN_AFTER, settings.EXPIRE_AFTER
        settings.WARN_AFTER, settings.EXPIRE_AFTER = 5, 10

        self.client.login(username='******', password='******')
        self.client.get('/admin/')

        now = datetime.now()
        session = self.client.session
        set_last_activity(session, now - timedelta(seconds=server))
        session.save()
        response = self.client.get('/session_security/ping/?idleFor=%s' %
                                   client)

        self.assertEqual(response.content, expected.encode("utf-8"))
        self.assertEqual(authenticated, '_auth_user_id' in self.client.session)

        settings.WARN_AFTER, settings.EXPIRE_AFTER = old_warn, old_expire
    def test_ping(self, server, client, expected, authenticated=True):
        old_warn, old_expire = settings.WARN_AFTER, settings.EXPIRE_AFTER
        settings.WARN_AFTER, settings.EXPIRE_AFTER = 5, 10

        self.client.login(username='******', password='******')
        self.client.get('/admin/')

        now = datetime.now()
        session = self.client.session
        set_last_activity(session, now - timedelta(seconds=server))
        session.save()
        response = self.client.get('/session_security/ping/?idleFor=%s' %
                                   client)

        self.assertEqual(response.content, six.b(expected))
        self.assertEqual(authenticated, '_auth_user_id' in self.client.session)

        settings.WARN_AFTER, settings.EXPIRE_AFTER = old_warn, old_expire
Пример #10
0
    def process_request(self, request):
        from django.contrib.auth import authenticate, login

        if request.user.is_authenticated():
            if _HAVE_SESSION_AUTH:
                set_last_activity(request.session, datetime.now())
            return None

        auth_data = self._extractAuthData(request)
        if not auth_data:
            # not valid basic auth, ignore request
            return None

        try:
            auth_data = base64.b64decode(auth_data)
        except (TypeError, binascii.Error):
            return None

        try:
            encoding = request.encoding or "utf-8"
        except AttributeError:
            encoding = "utf-8"

        try:
            auth_data = auth_data.decode(encoding)
        except UnicodeDecodeError:
            return None

        auth_parts = auth_data.split(':', 1)
        if len(auth_parts) != 2:
            # not valid basic auth, ignore request
            return None

        uname, passwd = [unquote_plus(x) for x in auth_parts]
        user = authenticate(username=uname, password=passwd)

        if user is not None and user.is_active:
            login(request, user)
            request.user = user
            request._basic_authenticated = True
            return None
        else:
            return self.unauthorisedResponse()