예제 #1
0
 def test_log_tail(self):
     from Products.PlonePAS.events import UserLoggedOutEvent
     from zope.event import notify
     event = UserLoggedOutEvent(self.request)
     notify(event)
     audit_log = self.view.get_audit_log.split('\n')
     # user logged out event is first on log (newer entries first)
     self.assertIn('user=test ip=127.0.0.1 action=logout', audit_log[0])
예제 #2
0
 def test_user_logout(self):
     event = UserLoggedOutEvent(self.request)
     with LogCapture('collective.fingerpointing', level=INFO) as log:
         notify(event)
         log.check(
             ('collective.fingerpointing', 'INFO',
              'user=test_user_1_ ip=None action=logout '),  # noqa: E501
         )
예제 #3
0
    def test_susbcriber_ignored_when_package_not_installed(self):
        # authentication events should not raise errors
        # if package is not installed
        self.uninstall()  # BBB: QI compatibility

        event = UserLoggedInEvent(self.request)
        notify(event)
        event = UserLoggedOutEvent(self.request)
        notify(event)
        event = PrincipalCreated('foo')
        notify(event)
        event = PrincipalDeleted('foo')
        notify(event)
예제 #4
0
    def logoutUser(self, REQUEST=None):
        """Process a user logout.

        This takes care of all the standard logout work:
        - ask the user folder to logout
        - expire a skin selection cookie
        - invalidate a Zope session if there is one
        """
        # Invalidate existing sessions, but only if they exist.
        sdm = getToolByName(self, 'session_data_manager', None)
        if sdm is not None:
            try:
                # XXX This causes write on read to happen which
                # causes plone.protect to freak out.
                # Please remove this once write on read is fixed
                req = REQUEST or self.REQUEST
                alsoProvides(req, IDisableCSRFProtection)
            except AttributeError:
                pass
            session = sdm.getSessionData(create=0)
            if session is not None:
                session.invalidate()

        if REQUEST is None:
            REQUEST = getattr(self, 'REQUEST', None)
        if REQUEST is not None:
            pas = getToolByName(self, 'acl_users')
            try:
                pas.logout(REQUEST)
            except:
                # XXX Bare except copied from logout.cpy. This should be
                # changed in the next Plone release.
                pass

            # Expire the skin cookie if it is not configured to persist
            st = getToolByName(self, "portal_skins")
            skinvar = st.getRequestVarname()
            if skinvar in REQUEST and not st.getCookiePersistence():
                portal = getToolByName(self, "portal_url").getPortalObject()
                path = '/' + portal.absolute_url(1)
                # XXX check if this path is sane
                REQUEST.RESPONSE.expireCookie(skinvar, path=path)

        user = getSecurityManager().getUser()
        if user is not None:
            event.notify(UserLoggedOutEvent(user))
예제 #5
0
    def test_susbcriber_ignored_when_package_not_installed(self):
        # authentication events should not raise errors
        # if package is not installed
        portal = self.layer['portal']
        qi = portal['portal_quickinstaller']

        with api.env.adopt_roles(['Manager']):
            qi.uninstallProducts(products=[PROJECTNAME])

        event = UserLoggedInEvent(self.request)
        notify(event)
        event = UserLoggedOutEvent(self.request)
        notify(event)
        event = PrincipalCreated('foo')
        notify(event)
        event = PrincipalDeleted('foo')
        notify(event)