Exemplo n.º 1
0
 def test_7_session_cookies(self):
     self.getPage('/setsessiontype/ram')
     self.getPage('/clear')
     self.getPage('/session_cookie')
     cookie_parts = dict(
         [p.strip().split('=') for p in self.cookies[0][1].split(';')])
     self.assertEqual(set(cookie_parts.keys()), set(['temp', 'Path']))
     id1 = cookie_parts['temp']
     self.assertEqual(copykeys(sessions.RamSession.cache), [id1])
     self.getPage('/session_cookie', self.cookies)
     cookie_parts = dict(
         [p.strip().split('=') for p in self.cookies[0][1].split(';')])
     self.assertEqual(set(cookie_parts.keys()), set(['temp', 'Path']))
     self.assertBody(id1)
     self.assertEqual(copykeys(sessions.RamSession.cache), [id1])
     self.getPage('/session_cookie')
     cookie_parts = dict(
         [p.strip().split('=') for p in self.cookies[0][1].split(';')])
     self.assertEqual(set(cookie_parts.keys()), set(['temp', 'Path']))
     id2 = cookie_parts['temp']
     self.assertNotEqual(id1, id2)
     self.assertEqual(set(sessions.RamSession.cache.keys()), set([id1,
                                                                  id2]))
     time.sleep(2.5)
     cache = copykeys(sessions.RamSession.cache)
     if cache:
         if cache == [id2]:
             self.fail('The second session did not time out.')
         else:
             self.fail('Unknown session id in cache: %r', cache)
Exemplo n.º 2
0
 def _known_ns(self, app):
     ns = ['wsgi']
     ns.extend(copykeys(app.toolboxes))
     ns.extend(copykeys(app.namespaces))
     ns.extend(copykeys(app.request_class.namespaces))
     ns.extend(copykeys(cherrypy.config.namespaces))
     ns += self.extra_config_namespaces
     for section, conf in app.config.items():
         is_path_section = section.startswith('/')
         if is_path_section and isinstance(conf, dict):
             for k, v in conf.items():
                 atoms = k.split('.')
                 if len(atoms) > 1:
                     if atoms[0] not in ns:
                         if atoms[0] == 'cherrypy' and atoms[1] in ns:
                             msg = 'The config entry %r is invalid; try %r instead.\nsection: [%s]' % (
                                 k, '.'.join(atoms[1:]), section)
                         else:
                             msg = 'The config entry %r is invalid, because the %r config namespace is unknown.\nsection: [%s]' % (
                                 k, atoms[0], section)
                         warnings.warn(msg)
                     elif atoms[0] == 'tools':
                         if atoms[1] not in dir(cherrypy.tools):
                             msg = 'The config entry %r may be invalid, because the %r tool was not found.\nsection: [%s]' % (
                                 k, atoms[1], section)
                             warnings.warn(msg)
Exemplo n.º 3
0
 def _known_ns(self, app):
     ns = ["wsgi"]
     ns.extend(copykeys(app.toolboxes))
     ns.extend(copykeys(app.namespaces))
     ns.extend(copykeys(app.request_class.namespaces))
     ns.extend(copykeys(cherrypy.config.namespaces))
     ns += self.extra_config_namespaces
     
     for section, conf in app.config.items():
         is_path_section = section.startswith("/")
         if is_path_section and isinstance(conf, dict):
             for k, v in conf.items():
                 atoms = k.split(".")
                 if len(atoms) > 1:
                     if atoms[0] not in ns:
                         # Spit out a special warning if a known
                         # namespace is preceded by "cherrypy."
                         if (atoms[0] == "cherrypy" and atoms[1] in ns):
                             msg = ("The config entry %r is invalid; "
                                    "try %r instead.\nsection: [%s]"
                                    % (k, ".".join(atoms[1:]), section))
                         else:
                             msg = ("The config entry %r is invalid, because "
                                    "the %r config namespace is unknown.\n"
                                    "section: [%s]" % (k, atoms[0], section))
                         warnings.warn(msg)
                     elif atoms[0] == "tools":
                         if atoms[1] not in dir(cherrypy.tools):
                             msg = ("The config entry %r may be invalid, "
                                    "because the %r tool was not found.\n"
                                    "section: [%s]" % (k, atoms[1], section))
                             warnings.warn(msg)
Exemplo n.º 4
0
 def test_7_session_cookies(self):
     self.getPage('/setsessiontype/ram')
     self.getPage('/clear')
     self.getPage('/session_cookie')
     cookie_parts = dict([ p.strip().split('=') for p in self.cookies[0][1].split(';') ])
     self.assertEqual(set(cookie_parts.keys()), set(['temp', 'Path']))
     id1 = cookie_parts['temp']
     self.assertEqual(copykeys(sessions.RamSession.cache), [id1])
     self.getPage('/session_cookie', self.cookies)
     cookie_parts = dict([ p.strip().split('=') for p in self.cookies[0][1].split(';') ])
     self.assertEqual(set(cookie_parts.keys()), set(['temp', 'Path']))
     self.assertBody(id1)
     self.assertEqual(copykeys(sessions.RamSession.cache), [id1])
     self.getPage('/session_cookie')
     cookie_parts = dict([ p.strip().split('=') for p in self.cookies[0][1].split(';') ])
     self.assertEqual(set(cookie_parts.keys()), set(['temp', 'Path']))
     id2 = cookie_parts['temp']
     self.assertNotEqual(id1, id2)
     self.assertEqual(set(sessions.RamSession.cache.keys()), set([id1, id2]))
     time.sleep(2.5)
     cache = copykeys(sessions.RamSession.cache)
     if cache:
         if cache == [id2]:
             self.fail('The second session did not time out.')
         else:
             self.fail('Unknown session id in cache: %r', cache)
Exemplo n.º 5
0
    def _known_ns(self, app):
        ns = ["wsgi"]
        ns.extend(copykeys(app.toolboxes))
        ns.extend(copykeys(app.namespaces))
        ns.extend(copykeys(app.request_class.namespaces))
        ns.extend(copykeys(cherrypy.config.namespaces))
        ns += self.extra_config_namespaces

        for section, conf in app.config.items():
            is_path_section = section.startswith("/")
            if is_path_section and isinstance(conf, dict):
                for k, v in conf.items():
                    atoms = k.split(".")
                    if len(atoms) > 1:
                        if atoms[0] not in ns:
                            # Spit out a special warning if a known
                            # namespace is preceded by "cherrypy."
                            if (atoms[0] == "cherrypy" and atoms[1] in ns):
                                msg = ("The config entry %r is invalid; "
                                       "try %r instead.\nsection: [%s]" %
                                       (k, ".".join(atoms[1:]), section))
                            else:
                                msg = (
                                    "The config entry %r is invalid, because "
                                    "the %r config namespace is unknown.\n"
                                    "section: [%s]" % (k, atoms[0], section))
                            warnings.warn(msg)
                        elif atoms[0] == "tools":
                            if atoms[1] not in dir(cherrypy.tools):
                                msg = ("The config entry %r may be invalid, "
                                       "because the %r tool was not found.\n"
                                       "section: [%s]" %
                                       (k, atoms[1], section))
                                warnings.warn(msg)
Exemplo n.º 6
0
 def __repr__(self):
     cls = self.__class__
     return '%s.%s(points=%r)' % (
         cls.__module__,
         cls.__name__,
         copykeys(self)
     )
Exemplo n.º 7
0
    def test_7_session_cookies(self):
        self.getPage('/setsessiontype/ram')
        self.getPage('/clear')
        self.getPage('/session_cookie')
        # grab the cookie ID
        cookie_parts = dict(
            [p.strip().split('=') for p in self.cookies[0][1].split(";")])
        # Assert there is no 'expires' param
        self.assertEqual(set(cookie_parts.keys()), set(['temp', 'Path']))
        id1 = cookie_parts['temp']
        self.assertEqual(copykeys(sessions.RamSession.cache), [id1])

        # Send another request in the same "browser session".
        self.getPage('/session_cookie', self.cookies)
        cookie_parts = dict(
            [p.strip().split('=') for p in self.cookies[0][1].split(";")])
        # Assert there is no 'expires' param
        self.assertEqual(set(cookie_parts.keys()), set(['temp', 'Path']))
        self.assertBody(id1)
        self.assertEqual(copykeys(sessions.RamSession.cache), [id1])

        # Simulate a browser close by just not sending the cookies
        self.getPage('/session_cookie')
        # grab the cookie ID
        cookie_parts = dict(
            [p.strip().split('=') for p in self.cookies[0][1].split(";")])
        # Assert there is no 'expires' param
        self.assertEqual(set(cookie_parts.keys()), set(['temp', 'Path']))
        # Assert a new id has been generated...
        id2 = cookie_parts['temp']
        self.assertNotEqual(id1, id2)
        self.assertEqual(set(sessions.RamSession.cache.keys()), set([id1,
                                                                     id2]))

        # Wait for the session.timeout on both sessions
        time.sleep(2.5)
        cache = copykeys(sessions.RamSession.cache)
        if cache:
            if cache == [id2]:
                self.fail("The second session did not time out.")
            else:
                self.fail("Unknown session id in cache: %r", cache)
Exemplo n.º 8
0
    def test_7_session_cookies(self):
        self.getPage('/set_session_cls/cherrypy.lib.sessions.RamSession')
        self.getPage('/clear')
        self.getPage('/session_cookie')
        # grab the cookie ID
        cookie_parts = dict([p.strip().split('=')
                            for p in self.cookies[0][1].split(';')])
        # Assert there is no 'expires' param
        self.assertEqual(set(cookie_parts.keys()), set(['temp', 'Path']))
        id1 = cookie_parts['temp']
        self.assertEqual(copykeys(sessions.RamSession.cache), [id1])

        # Send another request in the same "browser session".
        self.getPage('/session_cookie', self.cookies)
        cookie_parts = dict([p.strip().split('=')
                            for p in self.cookies[0][1].split(';')])
        # Assert there is no 'expires' param
        self.assertEqual(set(cookie_parts.keys()), set(['temp', 'Path']))
        self.assertBody(id1)
        self.assertEqual(copykeys(sessions.RamSession.cache), [id1])

        # Simulate a browser close by just not sending the cookies
        self.getPage('/session_cookie')
        # grab the cookie ID
        cookie_parts = dict([p.strip().split('=')
                            for p in self.cookies[0][1].split(';')])
        # Assert there is no 'expires' param
        self.assertEqual(set(cookie_parts.keys()), set(['temp', 'Path']))
        # Assert a new id has been generated...
        id2 = cookie_parts['temp']
        self.assertNotEqual(id1, id2)
        self.assertEqual(set(sessions.RamSession.cache.keys()),
                         set([id1, id2]))

        # Wait for the session.timeout on both sessions
        time.sleep(2.5)
        cache = copykeys(sessions.RamSession.cache)
        if cache:
            if cache == [id2]:
                self.fail('The second session did not time out.')
            else:
                self.fail('Unknown session id in cache: %r', cache)
Exemplo n.º 9
0
 def _known_ns(self, app):
     ns = ['wsgi']
     ns.extend(copykeys(app.toolboxes))
     ns.extend(copykeys(app.namespaces))
     ns.extend(copykeys(app.request_class.namespaces))
     ns.extend(copykeys(cherrypy.config.namespaces))
     ns += self.extra_config_namespaces
     for section, conf in app.config.items():
         is_path_section = section.startswith('/')
         if is_path_section and isinstance(conf, dict):
             for k, v in conf.items():
                 atoms = k.split('.')
                 if len(atoms) > 1:
                     if atoms[0] not in ns:
                         if atoms[0] == 'cherrypy' and atoms[1] in ns:
                             msg = 'The config entry %r is invalid; try %r instead.\nsection: [%s]' % (k, '.'.join(atoms[1:]), section)
                         else:
                             msg = 'The config entry %r is invalid, because the %r config namespace is unknown.\nsection: [%s]' % (k, atoms[0], section)
                         warnings.warn(msg)
                     elif atoms[0] == 'tools':
                         if atoms[1] not in dir(cherrypy.tools):
                             msg = 'The config entry %r may be invalid, because the %r tool was not found.\nsection: [%s]' % (k, atoms[1], section)
                             warnings.warn(msg)