예제 #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.iteritems():
         if isinstance(expected, type) and issubclass(expected, Exception):
             self.assertRaises(expected, CGIHTTPServer._url_collapse_path_split, path)
         else:
             actual = CGIHTTPServer._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):
     path = self.path
     i = path.rfind('?')
     if i >= 0:
         path, query = path[:i], path[i:]
     else:
         query = ''
     root, ext = os.path.splitext(path)
     if self.is_cgi_extension(ext):
         self.cgi_info = CGIHTTPServer._url_collapse_path_split(self.path)
         return True
     return False
예제 #3
0
 def is_cgi(self):
     path = self.path
     i = path.rfind("?")
     if i >= 0:
         path, query = path[:i], path[i:]
     else:
         query = ""
     root, ext = os.path.splitext(path)
     if self.is_cgi_extension(ext):
         self.cgi_info = CGIHTTPServer._url_collapse_path_split(self.path)
         return True
     return False
예제 #4
0
 def is_cgi(self):
     splitpath = CGIHTTPServer._url_collapse_path_split(self.path)
     script_query = splitpath[1].split("?", 1)
     if script_query[0].endswith(".py"):
         if splitpath[0].startswith("/"):
             # Workaround for some weirdness with how CGIHTTPServer
             # computes the SCRIPT_NAME environment variable.
             splitpath = list(splitpath)
             splitpath[0] = ''
             splitpath = tuple(splitpath)
         self.cgi_info = splitpath
         return True
     return False
예제 #5
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'),
         '/cgi-bin/file1.py/PATH-INFO': ('/cgi-bin', 'file1.py/PATH-INFO'),
         '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.iteritems():
         if isinstance(expected, type) and issubclass(expected, Exception):
             self.assertRaises(expected,
                               CGIHTTPServer._url_collapse_path_split, path)
         else:
             actual = CGIHTTPServer._url_collapse_path_split(path)
             self.assertEqual(expected,
                              actual,
                              msg='path = %r\nGot:    %r\nWanted: %r' %
                              (path, actual, expected))
예제 #6
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'),
         '/cgi-bin/file1.py/PATH-INFO': ('/cgi-bin', 'file1.py/PATH-INFO'),
         '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.iteritems():
         if isinstance(expected, type) and issubclass(expected, Exception):
             self.assertRaises(expected,
                               CGIHTTPServer._url_collapse_path_split, path)
         else:
             actual = CGIHTTPServer._url_collapse_path_split(path)
             self.assertEqual(expected, actual,
                              msg='path = %r\nGot:    %r\nWanted: %r' %
                              (path, actual, expected))