Issue #13308: Fix test_httpservers failures when run as root.

This commit is contained in:
Charles-François Natali 2011-11-02 19:36:02 +01:00
commit b2cca00c14
1 changed files with 6 additions and 2 deletions

View File

@ -259,8 +259,9 @@ class SimpleHTTPServerTestCase(BaseTestCase):
with open(os.path.join(self.tempdir_name, 'index.html'), 'w') as f: with open(os.path.join(self.tempdir_name, 'index.html'), 'w') as f:
response = self.request('/' + self.tempdir_name + '/') response = self.request('/' + self.tempdir_name + '/')
self.check_status_and_reason(response, 200) self.check_status_and_reason(response, 200)
if os.name == 'posix': # chmod() doesn't work as expected on Windows, and filesystem
# chmod won't work as expected on Windows platforms # permissions are ignored by root on Unix.
if os.name == 'posix' and os.geteuid() != 0:
os.chmod(self.tempdir, 0) os.chmod(self.tempdir, 0)
response = self.request(self.tempdir_name + '/') response = self.request(self.tempdir_name + '/')
self.check_status_and_reason(response, 404) self.check_status_and_reason(response, 404)
@ -305,6 +306,9 @@ print("%%s, %%s, %%s" %% (form.getfirst("spam"), form.getfirst("eggs"),
form.getfirst("bacon"))) form.getfirst("bacon")))
""" """
@unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0,
"This test can't be run reliably as root (issue #13308).")
class CGIHTTPServerTestCase(BaseTestCase): class CGIHTTPServerTestCase(BaseTestCase):
class request_handler(NoLogRequestHandler, CGIHTTPRequestHandler): class request_handler(NoLogRequestHandler, CGIHTTPRequestHandler):
pass pass