comparison Lib/test/test_httpservers.py @ 86780:493a99acaf00

merge 3.3 (#19435)
author Benjamin Peterson <benjamin@python.org>
date Wed, 30 Oct 2013 12:51:16 -0400
parents b85c9d2a5227 544b654d000c
children d6ad412dee40
comparison
equal deleted inserted replaced
86773:28c04e954bb6 86780:493a99acaf00
344 BaseTestCase.setUp(self) 344 BaseTestCase.setUp(self)
345 self.cwd = os.getcwd() 345 self.cwd = os.getcwd()
346 self.parent_dir = tempfile.mkdtemp() 346 self.parent_dir = tempfile.mkdtemp()
347 self.cgi_dir = os.path.join(self.parent_dir, 'cgi-bin') 347 self.cgi_dir = os.path.join(self.parent_dir, 'cgi-bin')
348 os.mkdir(self.cgi_dir) 348 os.mkdir(self.cgi_dir)
349 self.nocgi_path = None
349 self.file1_path = None 350 self.file1_path = None
350 self.file2_path = None 351 self.file2_path = None
351 352
352 # The shebang line should be pure ASCII: use symlink if possible. 353 # The shebang line should be pure ASCII: use symlink if possible.
353 # See issue #7668. 354 # See issue #7668.
364 self.pythonexe.encode('utf-8') 365 self.pythonexe.encode('utf-8')
365 except UnicodeEncodeError: 366 except UnicodeEncodeError:
366 self.tearDown() 367 self.tearDown()
367 self.skipTest("Python executable path is not encodable to utf-8") 368 self.skipTest("Python executable path is not encodable to utf-8")
368 369
370 self.nocgi_path = os.path.join(self.parent_dir, 'nocgi.py')
371 with open(self.nocgi_path, 'w') as fp:
372 fp.write(cgi_file1 % self.pythonexe)
373 os.chmod(self.nocgi_path, 0o777)
374
369 self.file1_path = os.path.join(self.cgi_dir, 'file1.py') 375 self.file1_path = os.path.join(self.cgi_dir, 'file1.py')
370 with open(self.file1_path, 'w', encoding='utf-8') as file1: 376 with open(self.file1_path, 'w', encoding='utf-8') as file1:
371 file1.write(cgi_file1 % self.pythonexe) 377 file1.write(cgi_file1 % self.pythonexe)
372 os.chmod(self.file1_path, 0o777) 378 os.chmod(self.file1_path, 0o777)
373 379
381 def tearDown(self): 387 def tearDown(self):
382 try: 388 try:
383 os.chdir(self.cwd) 389 os.chdir(self.cwd)
384 if self.pythonexe != sys.executable: 390 if self.pythonexe != sys.executable:
385 os.remove(self.pythonexe) 391 os.remove(self.pythonexe)
392 if self.nocgi_path:
393 os.remove(self.nocgi_path)
386 if self.file1_path: 394 if self.file1_path:
387 os.remove(self.file1_path) 395 os.remove(self.file1_path)
388 if self.file2_path: 396 if self.file2_path:
389 os.remove(self.file2_path) 397 os.remove(self.file2_path)
390 os.rmdir(self.cgi_dir) 398 os.rmdir(self.cgi_dir)
437 def test_headers_and_content(self): 445 def test_headers_and_content(self):
438 res = self.request('/cgi-bin/file1.py') 446 res = self.request('/cgi-bin/file1.py')
439 self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200), 447 self.assertEqual((b'Hello World' + self.linesep, 'text/html', 200),
440 (res.read(), res.getheader('Content-type'), res.status)) 448 (res.read(), res.getheader('Content-type'), res.status))
441 449
450 def test_issue19435(self):
451 res = self.request('///////////nocgi.py/../cgi-bin/nothere.sh')
452 self.assertEqual(res.status, 404)
453
442 def test_post(self): 454 def test_post(self):
443 params = urllib.parse.urlencode( 455 params = urllib.parse.urlencode(
444 {'spam' : 1, 'eggs' : 'python', 'bacon' : 123456}) 456 {'spam' : 1, 'eggs' : 'python', 'bacon' : 123456})
445 headers = {'Content-type' : 'application/x-www-form-urlencoded'} 457 headers = {'Content-type' : 'application/x-www-form-urlencoded'}
446 res = self.request('/cgi-bin/file2.py', 'POST', params, headers) 458 res = self.request('/cgi-bin/file2.py', 'POST', params, headers)