comparison Lib/test/test_httpservers.py @ 76248:fc001124a3ee 3.2

3.2 - Issue 10484 - Incorporate improvements to CGI module - Suggested by Glenn Linderman. Refactor code and tests
author Senthil Kumaran <senthil@uthcode.com>
date Thu, 12 Apr 2012 02:34:32 +0800
parents 827a4062b1d6
children bc4fdb758b8c 23f648d7053b
comparison
equal deleted inserted replaced
76245:9d4109af8f3b 76248:fc001124a3ee
364 os.rmdir(self.cgi_dir) 364 os.rmdir(self.cgi_dir)
365 os.rmdir(self.parent_dir) 365 os.rmdir(self.parent_dir)
366 finally: 366 finally:
367 BaseTestCase.tearDown(self) 367 BaseTestCase.tearDown(self)
368 368
369 def test_url_collapse_path_split(self): 369 def test_url_collapse_path(self):
370 # verify tail is the last portion and head is the rest on proper urls
370 test_vectors = { 371 test_vectors = {
371 '': ('/', ''), 372 '': '//',
372 '..': IndexError, 373 '..': IndexError,
373 '/.//..': IndexError, 374 '/.//..': IndexError,
374 '/': ('/', ''), 375 '/': '//',
375 '//': ('/', ''), 376 '//': '//',
376 '/\\': ('/', '\\'), 377 '/\\': '//\\',
377 '/.//': ('/', ''), 378 '/.//': '//',
378 'cgi-bin/file1.py': ('/cgi-bin', 'file1.py'), 379 'cgi-bin/file1.py': '/cgi-bin/file1.py',
379 '/cgi-bin/file1.py': ('/cgi-bin', 'file1.py'), 380 '/cgi-bin/file1.py': '/cgi-bin/file1.py',
380 'a': ('/', 'a'), 381 'a': '//a',
381 '/a': ('/', 'a'), 382 '/a': '//a',
382 '//a': ('/', 'a'), 383 '//a': '//a',
383 './a': ('/', 'a'), 384 './a': '//a',
384 './C:/': ('/C:', ''), 385 './C:/': '/C:/',
385 '/a/b': ('/a', 'b'), 386 '/a/b': '/a/b',
386 '/a/b/': ('/a/b', ''), 387 '/a/b/': '/a/b/',
387 '/a/b/c/..': ('/a/b', ''), 388 '/a/b/.': '/a/b/',
388 '/a/b/c/../d': ('/a/b', 'd'), 389 '/a/b/c/..': '/a/b/',
389 '/a/b/c/../d/e/../f': ('/a/b/d', 'f'), 390 '/a/b/c/../d': '/a/b/d',
390 '/a/b/c/../d/e/../../f': ('/a/b', 'f'), 391 '/a/b/c/../d/e/../f': '/a/b/d/f',
391 '/a/b/c/../d/e/.././././..//f': ('/a/b', 'f'), 392 '/a/b/c/../d/e/../../f': '/a/b/f',
393 '/a/b/c/../d/e/.././././..//f': '/a/b/f',
392 '../a/b/c/../d/e/.././././..//f': IndexError, 394 '../a/b/c/../d/e/.././././..//f': IndexError,
393 '/a/b/c/../d/e/../../../f': ('/a', 'f'), 395 '/a/b/c/../d/e/../../../f': '/a/f',
394 '/a/b/c/../d/e/../../../../f': ('/', 'f'), 396 '/a/b/c/../d/e/../../../../f': '//f',
395 '/a/b/c/../d/e/../../../../../f': IndexError, 397 '/a/b/c/../d/e/../../../../../f': IndexError,
396 '/a/b/c/../d/e/../../../../f/..': ('/', ''), 398 '/a/b/c/../d/e/../../../../f/..': '//',
399 '/a/b/c/../d/e/../../../../f/../.': '//',
397 } 400 }
398 for path, expected in test_vectors.items(): 401 for path, expected in test_vectors.items():
399 if isinstance(expected, type) and issubclass(expected, Exception): 402 if isinstance(expected, type) and issubclass(expected, Exception):
400 self.assertRaises(expected, 403 self.assertRaises(expected,
401 server._url_collapse_path_split, path) 404 server._url_collapse_path, path)
402 else: 405 else:
403 actual = server._url_collapse_path_split(path) 406 actual = server._url_collapse_path(path)
404 self.assertEqual(expected, actual, 407 self.assertEqual(expected, actual,
405 msg='path = %r\nGot: %r\nWanted: %r' % 408 msg='path = %r\nGot: %r\nWanted: %r' %
406 (path, actual, expected)) 409 (path, actual, expected))
407 410
408 def test_headers_and_content(self): 411 def test_headers_and_content(self):