Exemplo n.º 1
0
 def is_cgi(self):
     collapsed_path = CGIHTTPServer._url_collapse_path(self.path)
     dir_sep = collapsed_path.find('/', 1)
     head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep+1:]
     if head in self.cgi_directories:
         self.cgi_info = head, tail
         return True
     return False
 def do_POST(self):
     collapsed_path = CGIHTTPServer._url_collapse_path(urllib.unquote(self.path))
     if collapsed_path.endswith("/") and collapsed_path != "/":
         collapsed_path = collapsed_path[:-1]
     if collapsed_path == "/sink/a":
         return self.do_sink_a()
     else:
         self.send_error(404, "No such endpoint (%s)" % collapsed_path)
         return
Exemplo n.º 3
0
 def test_url_collapse_path(self):
     # verify tail is the last portion and head is the rest on proper urls
     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/.': '/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/..': '//',
         '/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,
                               path)
         else:
             actual = CGIHTTPServer._url_collapse_path(path)
             self.assertEqual(expected,
                              actual,
                              msg='path = %r\nGot:    %r\nWanted: %r' %
                              (path, actual, expected))
Exemplo n.º 4
0
    def is_cgi(self):
        #                v added `CGIHTTPServer.`

        collapsed_path = CGIHTTPServer._url_collapse_path(self.path)
        dir_sep = collapsed_path.find('/', 1)
        head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep + 1:]

        if ".class" in tail:
            self.cgi_info = head, tail
            return True

        if head == "/" and tail == "":
            print('head' + head + 'tail' + tail)
            return False
        if head in self.cgi_directories:
            if not tail.endswith('.html'):  # <-- new line
                #if tail.endswith('.py'): # <-- new line
                self.cgi_info = head, tail
                return True
        return False
Exemplo n.º 5
0
 def test_url_collapse_path(self):
     # verify tail is the last portion and head is the rest on proper urls
     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/.': '/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/..': '//',
         '/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, path)
         else:
             actual = CGIHTTPServer._url_collapse_path(path)
             self.assertEqual(expected, actual,
                              msg='path = %r\nGot:    %r\nWanted: %r' %
                              (path, actual, expected))