Пример #1
0
 def test_url_collapse_path_split(self):
     test_vectors = {
         "": ("/", ""),
         "..": IndexError,
         "/.//..": IndexError,
         "/": ("/", ""),
         "//": ("/", ""),
         "/\\": ("/", "\\"),
         "/.//": ("/", ""),
         "cgi-bin/file1.py": ("/cgi-bin", "file1.py"),
         "/cgi-bin/file1.py": ("/cgi-bin", "file1.py"),
         "a": ("/", "a"),
         "/a": ("/", "a"),
         "//a": ("/", "a"),
         "./a": ("/", "a"),
         "./C:/": ("/C:", ""),
         "/a/b": ("/a", "b"),
         "/a/b/": ("/a/b", ""),
         "/a/b/c/..": ("/a/b", ""),
         "/a/b/c/../d": ("/a/b", "d"),
         "/a/b/c/../d/e/../f": ("/a/b/d", "f"),
         "/a/b/c/../d/e/../../f": ("/a/b", "f"),
         "/a/b/c/../d/e/.././././..//f": ("/a/b", "f"),
         "../a/b/c/../d/e/.././././..//f": IndexError,
         "/a/b/c/../d/e/../../../f": ("/a", "f"),
         "/a/b/c/../d/e/../../../../f": ("/", "f"),
         "/a/b/c/../d/e/../../../../../f": IndexError,
         "/a/b/c/../d/e/../../../../f/..": ("/", ""),
     }
     for path, expected in test_vectors.items():
         if isinstance(expected, type) and issubclass(expected, Exception):
             self.assertRaises(expected, server._url_collapse_path_split, path)
         else:
             actual = server._url_collapse_path_split(path)
             self.assertEqual(expected, actual, msg="path = %r\nGot:    %r\nWanted: %r" % (path, actual, expected))
Пример #2
0
 def is_cgi(self):
     # Having a CGI suffix is really a big hint of being a CGI script.
     if urlparse(self.path).path.endswith('.cgi'):
         self.cgi_info = _url_collapse_path_split(self.path)
         return True
     else:
         return CGIHTTPRequestHandler.is_cgi(self)
Пример #3
0
 def test_url_collapse_path_split(self):
     test_vectors = {
         '': ('/', ''),
         '..': IndexError,
         '/.//..': IndexError,
         '/': ('/', ''),
         '//': ('/', ''),
         '/\\': ('/', '\\'),
         '/.//': ('/', ''),
         'cgi-bin/file1.py': ('/cgi-bin', 'file1.py'),
         '/cgi-bin/file1.py': ('/cgi-bin', 'file1.py'),
         'a': ('/', 'a'),
         '/a': ('/', 'a'),
         '//a': ('/', 'a'),
         './a': ('/', 'a'),
         './C:/': ('/C:', ''),
         '/a/b': ('/a', 'b'),
         '/a/b/': ('/a/b', ''),
         '/a/b/c/..': ('/a/b', ''),
         '/a/b/c/../d': ('/a/b', 'd'),
         '/a/b/c/../d/e/../f': ('/a/b/d', 'f'),
         '/a/b/c/../d/e/../../f': ('/a/b', 'f'),
         '/a/b/c/../d/e/.././././..//f': ('/a/b', 'f'),
         '../a/b/c/../d/e/.././././..//f': IndexError,
         '/a/b/c/../d/e/../../../f': ('/a', 'f'),
         '/a/b/c/../d/e/../../../../f': ('/', 'f'),
         '/a/b/c/../d/e/../../../../../f': IndexError,
         '/a/b/c/../d/e/../../../../f/..': ('/', ''),
     }
     for path, expected in test_vectors.items():
         if isinstance(expected, type) and issubclass(expected, Exception):
             self.assertRaises(expected, server._url_collapse_path_split,
                               path)
         else:
             actual = server._url_collapse_path_split(path)
             self.assertEqual(expected,
                              actual,
                              msg='path = %r\nGot:    %r\nWanted: %r' %
                              (path, actual, expected))
 def test_url_collapse_path_split(self):
     test_vectors = {
         '': ('/', ''),
         '..': IndexError,
         '/.//..': IndexError,
         '/': ('/', ''),
         '//': ('/', ''),
         '/\\': ('/', '\\'),
         '/.//': ('/', ''),
         'cgi-bin/file1.py': ('/cgi-bin', 'file1.py'),
         '/cgi-bin/file1.py': ('/cgi-bin', 'file1.py'),
         'a': ('/', 'a'),
         '/a': ('/', 'a'),
         '//a': ('/', 'a'),
         './a': ('/', 'a'),
         './C:/': ('/C:', ''),
         '/a/b': ('/a', 'b'),
         '/a/b/': ('/a/b', ''),
         '/a/b/c/..': ('/a/b', ''),
         '/a/b/c/../d': ('/a/b', 'd'),
         '/a/b/c/../d/e/../f': ('/a/b/d', 'f'),
         '/a/b/c/../d/e/../../f': ('/a/b', 'f'),
         '/a/b/c/../d/e/.././././..//f': ('/a/b', 'f'),
         '../a/b/c/../d/e/.././././..//f': IndexError,
         '/a/b/c/../d/e/../../../f': ('/a', 'f'),
         '/a/b/c/../d/e/../../../../f': ('/', 'f'),
         '/a/b/c/../d/e/../../../../../f': IndexError,
         '/a/b/c/../d/e/../../../../f/..': ('/', ''),
     }
     for path, expected in test_vectors.items():
         if isinstance(expected, type) and issubclass(expected, Exception):
             self.assertRaises(expected,
                               server._url_collapse_path_split, path)
         else:
             actual = server._url_collapse_path_split(path)
             self.assertEqual(expected, actual,
                              msg='path = %r\nGot:    %r\nWanted: %r' % (
                              path, actual, expected))