def __init__(self): CookieClientIdManager.__init__(self) self.namespace = config.launchpad_session.cookie # Set the cookie life time to something big. # It should be larger than our session expiry time. self.cookieLifetime = 1 * YEARS self._secret = None
def setRequestId(self, request, id): """As per CookieClientIdManager.setRequestID, except we force the domain key on the cookie to be set to allow our session to be shared between virtual hosts where possible, and we set the secure key to stop the session key being sent to insecure URLs like the Librarian. We also log the referrer url on creation of a new requestid so we can track where first time users arrive from. """ CookieClientIdManager.setRequestId(self, request, id) cookie = request.response.getCookie(self.namespace) uri = URI(request.getURL()) # Forbid browsers from exposing it to JS. cookie['HttpOnly'] = True # Set secure flag on cookie. if uri.scheme != 'http': cookie['secure'] = True else: cookie['secure'] = False # Set domain attribute on cookie if vhosting requires it. cookie_domain = get_cookie_domain(uri.host) if cookie_domain is not None: cookie['domain'] = cookie_domain
def sessionSetUp(session_data_container_class=PersistentSessionDataContainer): placelesssetup.setUp() ztapi.provideAdapter(IRequest, IClientId, TestClientId) ztapi.provideAdapter(IRequest, ISession, Session) ztapi.provideUtility(IClientIdManager, CookieClientIdManager()) sdc = session_data_container_class() ztapi.provideUtility(ISessionDataContainer, sdc, '')
def nonHTTPSessionTestCaseSetUp(sdc_class=PersistentSessionDataContainer): # I am getting an error with ClientId and not TestClientId placelesssetup.setUp() ztapi.provideAdapter(IRequest, IClientId, ClientId) ztapi.provideAdapter(IRequest, ISession, Session) ztapi.provideUtility(IClientIdManager, CookieClientIdManager()) sdc = sdc_class() ztapi.provideUtility(ISessionDataContainer, sdc, '')
def setUpSessions(): """Set up the session machinery. Do this after placelessSetUp(). """ provideAdapter(ClientId) provideAdapter(Session, (IRequest,), ISession) provideUtility(CookieClientIdManager(), IClientIdManager) sdc = PersistentSessionDataContainer() provideUtility(sdc, ISessionDataContainer)