def test_getHiddenFormField(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     request = DummyRequest(browser_id_=bid)
     mgr = self._makeOne(request)
     mgr.setBrowserIdName('bid')
     self.assertEqual(mgr.getHiddenFormField(),
                      '<input type="hidden" name="bid" value="%s" />' % bid)
Esempio n. 2
0
 def test_getHiddenFormField(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     request = DummyRequest(browser_id_=bid)
     mgr = self._makeOne(request)
     mgr.setBrowserIdName('bid')
     self.assertEqual(mgr.getHiddenFormField(),
                      '<input type="hidden" name="bid" value="%s" />' % bid)
 def test_getBrowserId_namespace_hit(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     request = DummyRequest(cookies={'bid': bid})
     mgr = self._makeOne(request)
     mgr.setBrowserIdName('bid')
     self.assertTrue(mgr.hasBrowserId())
     self.assertEqual(request.browser_id_, bid)
     self.assertEqual(request.browser_id_ns_, 'cookies')
Esempio n. 4
0
 def test_getBrowserId_namespace_hit(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     request = DummyRequest(cookies={'bid': bid})
     mgr = self._makeOne(request)
     mgr.setBrowserIdName('bid')
     self.assertTrue(mgr.hasBrowserId())
     self.assertEqual(request.browser_id_, bid)
     self.assertEqual(request.browser_id_ns_, 'cookies')
 def test_encodeUrl_no_create_w_bid_querystring_style(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     URL = 'http://example.com/'
     bid = getNewBrowserId()
     request = DummyRequest(browser_id_=bid)
     mgr = self._makeOne(request)
     mgr.setBrowserIdName('bid')
     munged = mgr.encodeUrl(URL, create=False)
     self.assertEqual(munged, '%s?bid=%s' % (URL, bid))
Esempio n. 6
0
 def test_encodeUrl_no_create_w_bid_querystring_style(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     URL = 'http://example.com/'
     bid = getNewBrowserId()
     request = DummyRequest(browser_id_=bid)
     mgr = self._makeOne(request)
     mgr.setBrowserIdName('bid')
     munged = mgr.encodeUrl(URL, create=False)
     self.assertEqual(munged, '%s?bid=%s' % (URL, bid))
 def test_setBrowserIdCookieByForce_ok(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     response = DummyResponse(cookies={})
     request = DummyRequest(RESPONSE=response)
     mgr = self._makeOne(request)
     mgr.setBrowserIdName('bid')
     mgr.setBrowserIdNamespaces(('cookies',))
     mgr.setBrowserIdCookieByForce(bid)
     self.assertEqual(response.cookies['bid'], {'path': '/', 'value': bid})
Esempio n. 8
0
 def test_setBrowserIdCookieByForce_ok(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     response = DummyResponse(cookies={})
     request = DummyRequest(RESPONSE=response)
     mgr = self._makeOne(request)
     mgr.setBrowserIdName('bid')
     mgr.setBrowserIdNamespaces(('cookies',))
     mgr.setBrowserIdCookieByForce(bid)
     self.assertEqual(response.cookies['bid'], {'path': '/', 'value': bid})
 def test_encodeUrl_no_create_w_bid_inline_style(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     NETHOST = 'http://example.com'
     PATH_INFO = 'path/to/page'
     URL = '%s/%s' % (NETHOST, PATH_INFO)
     bid = getNewBrowserId()
     request = DummyRequest(browser_id_=bid)
     mgr = self._makeOne(request)
     mgr.setBrowserIdName('bid')
     munged = mgr.encodeUrl(URL, style='inline', create=False)
     self.assertEqual(munged, '%s/bid/%s/%s' % (NETHOST, bid, PATH_INFO))
 def __init__(self, db, iters, token=None):
     self.conn = db.open()
     self.app = self.conn.root()['Application']
     self.app = makerequest.makerequest(self.app)
     if token is None:
         token = getNewBrowserId()
     self.app.REQUEST.browser_id_ = token
     self.iters = iters
     self.sdm_name = sdm_name
     self.out = []
     threading.Thread.__init__(self)
Esempio n. 11
0
 def test_encodeUrl_no_create_w_bid_inline_style(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     NETHOST = 'http://example.com'
     PATH_INFO = 'path/to/page'
     URL = '%s/%s' % (NETHOST, PATH_INFO)
     bid = getNewBrowserId()
     request = DummyRequest(browser_id_=bid)
     mgr = self._makeOne(request)
     mgr.setBrowserIdName('bid')
     munged = mgr.encodeUrl(URL, style='inline', create=False)
     self.assertEqual(munged, '%s/bid/%s/%s' % (NETHOST, bid, PATH_INFO))
Esempio n. 12
0
 def test___call___w_mgr_request_has_stack_no_auto_encode(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     traverser = self._makeOne()
     mgr = DummyBrowserIdManager()
     container = DummyObject(browser_id_manager=mgr)
     request = DummyRequest(TraversalRequestNameStack=[bid, 'bid'])
     traverser(container, request)
     self.assertEqual(request.browser_id_, bid)
     self.assertEqual(request.browser_id_ns_, 'url')
     self.assertEqual(len(request.TraversalRequestNameStack), 0)
Esempio n. 13
0
 def test___call___w_mgr_request_has_stack_no_auto_encode(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     traverser = self._makeOne()
     mgr = DummyBrowserIdManager()
     container = DummyObject(browser_id_manager=mgr)
     request = DummyRequest(
                 TraversalRequestNameStack=[bid, 'bid'])
     traverser(container, request)
     self.assertEqual(request.browser_id_, bid)
     self.assertEqual(request.browser_id_ns_, 'url')
     self.assertEqual(len(request.TraversalRequestNameStack), 0)
    def run(self):
        i = 0
        try:
            while 1:
                self.conn = self.db.open()
                self.app = self.conn.root()['Application']
                self.app = makerequest.makerequest(self.app)
                if self.token is None:
                    token = getNewBrowserId()
                else:
                    token = self.token
                    self.app.REQUEST.browser_id_ = token

                try:
                    self.run1()
                    return
                except ReadConflictError:
                    # traceback.print_exc()
                    print("R", end=' ')
                except BTreesConflictError:
                    print("B", end=' ')
                except ConflictError:
                    print("W", end=' ')
                except Exception as err:
                    transaction.abort()
                    print(log_time())
                    traceback.print_exc()
                    print(err.msg)
                    raise

                i = i + 1
                transaction.abort()
                self.conn.close()
                time.sleep(random.randrange(10) * .1)
        finally:
            transaction.abort()
            self.conn.close()
            del self.app
            self.finished = 1
            print("%s finished" % self.__class__)
Esempio n. 15
0
    def run(self):
        i = 0
        try:
            while 1:
                self.conn = self.db.open()
                self.app = self.conn.root()['Application']
                self.app = makerequest.makerequest(self.app)
                if self.token is None:
                    token = getNewBrowserId()
                else:
                    token = self.token
                    self.app.REQUEST.browser_id_ = token

                try:
                    self.run1()
                    return
                except ReadConflictError:
                    #traceback.print_exc()
                    print "R",
                except BTreesConflictError:
                    print "B",
                except ConflictError:
                    print "W",
                except:
                    transaction.abort()
                    print log_time()
                    traceback.print_exc()
                    raise

                i = i + 1
                transaction.abort()
                self.conn.close()
                time.sleep(random.randrange(10) * .1)
        finally:
            transaction.abort()
            self.conn.close()
            del self.app
            self.finished = 1
            print '%s finished' % self.__class__
Esempio n. 16
0
 def test_getBrowserId_already_set_on_request(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     request = DummyRequest(browser_id_=bid)
     mgr = self._makeOne(request)
     self.assertEqual(mgr.getBrowserId(), bid)
Esempio n. 17
0
 def test_hasBrowserId_namespace_hit(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     request = DummyRequest(cookies={'bid': getNewBrowserId()})
     mgr = self._makeOne(request)
     mgr.setBrowserIdName('bid')
     self.assertTrue(mgr.hasBrowserId())
Esempio n. 18
0
 def test_hasBrowserId_already_set_on_request(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     request = DummyRequest(browser_id_=getNewBrowserId())
     mgr = self._makeOne(request)
     self.assertTrue(mgr.hasBrowserId())
Esempio n. 19
0
 def test_setBrowserIdCookieByForce_wrong_ns_raises(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     mgr = self._makeOne()
     mgr.setBrowserIdNamespaces(('url', 'form'))
     self.assertRaises(ValueError, mgr.setBrowserIdCookieByForce, bid)
Esempio n. 20
0
 def test_hasBrowserId_already_set_on_request(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     request = DummyRequest(browser_id_=getNewBrowserId())
     mgr = self._makeOne(request)
     self.assertTrue(mgr.hasBrowserId())
Esempio n. 21
0
 def test_setBrowserIdCookieByForce_wrong_ns_raises(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     mgr = self._makeOne()
     mgr.setBrowserIdNamespaces(('url', 'form'))
     self.assertRaises(ValueError, mgr.setBrowserIdCookieByForce, bid)
Esempio n. 22
0
 def testOverlappingBrowserIds(self):
     token = getNewBrowserId()
     self.go(token)
Esempio n. 23
0
 def test_isBrowserIdFromForm_wrong_ns(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     request = DummyRequest(browser_id_=bid, browser_id_ns_='url')
     mgr = self._makeOne(request)
     self.assertFalse(mgr.isBrowserIdFromForm())
Esempio n. 24
0
 def test_isBrowserIdFromUrl_right_ns(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     request = DummyRequest(browser_id_=bid, browser_id_ns_='url')
     mgr = self._makeOne(request)
     self.assertTrue(mgr.isBrowserIdFromUrl())
Esempio n. 25
0
 def test_isBrowserIdNew_no_ns(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     request = DummyRequest(browser_id_=bid, browser_id_ns_=None)
     mgr = self._makeOne(request)
     self.assertTrue(mgr.isBrowserIdNew())
Esempio n. 26
0
 def test_isBrowserIdFromForm_wrong_ns(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     request = DummyRequest(browser_id_=bid, browser_id_ns_='url')
     mgr = self._makeOne(request)
     self.assertFalse(mgr.isBrowserIdFromForm())
 def testOverlappingBrowserIds(self):
     token = getNewBrowserId()
     self.go(token)
Esempio n. 28
0
 def test_isBrowserIdFromUrl_right_ns(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     request = DummyRequest(browser_id_=bid, browser_id_ns_='url')
     mgr = self._makeOne(request)
     self.assertTrue(mgr.isBrowserIdFromUrl())
Esempio n. 29
0
 def test_hasBrowserId_namespace_hit(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     request = DummyRequest(cookies={'bid': getNewBrowserId()})
     mgr = self._makeOne(request)
     mgr.setBrowserIdName('bid')
     self.assertTrue(mgr.hasBrowserId())
Esempio n. 30
0
 def test_isBrowserIdNew_no_ns(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     request = DummyRequest(browser_id_=bid, browser_id_ns_=None)
     mgr = self._makeOne(request)
     self.assertTrue(mgr.isBrowserIdNew())
Esempio n. 31
0
 def test_getBrowserId_already_set_on_request(self):
     from Products.Sessions.BrowserIdManager import getNewBrowserId
     bid = getNewBrowserId()
     request = DummyRequest(browser_id_=bid)
     mgr = self._makeOne(request)
     self.assertEqual(mgr.getBrowserId(), bid)