Commit bcd19af2 authored by Jason Madden's avatar Jason Madden Committed by GitHub

Merge pull request #925 from gevent/issue924

Update test_httpservers to 2.7.13 (and be explicit about that version…
parents 91b408fb c7683fab
......@@ -105,7 +105,7 @@ travis_test_linters:
BUILD_RUNTIMES?=$(PWD)/.runtimes
PY278=$(BUILD_RUNTIMES)/snakepit/python2.7.8
PY27=$(BUILD_RUNTIMES)/snakepit/python2.7
PY27=$(BUILD_RUNTIMES)/snakepit/python2.7.13
PY34=$(BUILD_RUNTIMES)/snakepit/python3.4.5
PY35=$(BUILD_RUNTIMES)/snakepit/python3.5.2
PY36=$(BUILD_RUNTIMES)/snakepit/python3.6.0
......@@ -159,10 +159,10 @@ develop:
${PIP} install -U -r dev-requirements.txt
lint-py27: $(PY27)
PYTHON=python2.7 PATH=$(BUILD_RUNTIMES)/versions/python2.7/bin:$(PATH) make develop travis_test_linters
PYTHON=python2.7.13 PATH=$(BUILD_RUNTIMES)/versions/python2.7.13/bin:$(PATH) make develop travis_test_linters
test-py27: $(PY27)
PYTHON=python2.7 PATH=$(BUILD_RUNTIMES)/versions/python2.7/bin:$(PATH) make develop fulltoxtest
PYTHON=python2.7.13 PATH=$(BUILD_RUNTIMES)/versions/python2.7.13/bin:$(PATH) make develop fulltoxtest
test-py278: $(PY278)
ls $(BUILD_RUNTIMES)/versions/python2.7.8/bin/
......
......@@ -85,7 +85,7 @@ for var in "$@"; do
install 2.7.8 python2.7.8
;;
2.7)
install 2.7.12 python2.7
install 2.7.13 python2.7.13
;;
3.2)
install 3.2.6 python3.2
......
......@@ -8,6 +8,7 @@ import os
import sys
import re
import base64
import ntpath
import shutil
import urllib
import httplib
......@@ -177,6 +178,12 @@ class BaseHTTPServerTestCase(BaseTestCase):
self.send_header('Connection', 'close')
self.end_headers()
def do_SEND_ERROR(self):
self.send_error(int(self.path[1:]))
def do_HEAD(self):
self.send_error(int(self.path[1:]))
def setUp(self):
BaseTestCase.setUp(self)
self.con = httplib.HTTPConnection('localhost', self.PORT)
......@@ -275,6 +282,38 @@ class BaseHTTPServerTestCase(BaseTestCase):
res = self.con.getresponse()
self.assertEqual(res.status, 999)
def test_send_error(self):
allow_transfer_encoding_codes = (205, 304)
for code in (101, 102, 204, 205, 304):
self.con.request('SEND_ERROR', '/{}'.format(code))
res = self.con.getresponse()
self.assertEqual(code, res.status)
self.assertEqual(None, res.getheader('Content-Length'))
self.assertEqual(None, res.getheader('Content-Type'))
if code not in allow_transfer_encoding_codes:
self.assertEqual(None, res.getheader('Transfer-Encoding'))
data = res.read()
self.assertEqual(b'', data)
def test_head_via_send_error(self):
allow_transfer_encoding_codes = (205, 304)
for code in (101, 200, 204, 205, 304):
self.con.request('HEAD', '/{}'.format(code))
res = self.con.getresponse()
self.assertEqual(code, res.status)
if code == 200:
self.assertEqual(None, res.getheader('Content-Length'))
self.assertIn('text/html', res.getheader('Content-Type'))
else:
self.assertEqual(None, res.getheader('Content-Length'))
self.assertEqual(None, res.getheader('Content-Type'))
if code not in allow_transfer_encoding_codes:
self.assertEqual(None, res.getheader('Transfer-Encoding'))
data = res.read()
self.assertEqual(b'', data)
class SimpleHTTPServerTestCase(BaseTestCase):
class request_handler(NoLogRequestHandler, SimpleHTTPRequestHandler):
......@@ -288,6 +327,7 @@ class SimpleHTTPServerTestCase(BaseTestCase):
self.data = 'We are the knights who say Ni!'
self.tempdir = tempfile.mkdtemp(dir=basetempdir)
self.tempdir_name = os.path.basename(self.tempdir)
self.base_url = '/' + self.tempdir_name
temp = open(os.path.join(self.tempdir, 'test'), 'wb')
temp.write(self.data)
temp.close()
......@@ -312,39 +352,39 @@ class SimpleHTTPServerTestCase(BaseTestCase):
def test_get(self):
#constructs the path relative to the root directory of the HTTPServer
response = self.request(self.tempdir_name + '/test')
response = self.request(self.base_url + '/test')
self.check_status_and_reason(response, 200, data=self.data)
# check for trailing "/" which should return 404. See Issue17324
response = self.request(self.tempdir_name + '/test/')
response = self.request(self.base_url + '/test/')
self.check_status_and_reason(response, 404)
response = self.request(self.tempdir_name + '/')
response = self.request(self.base_url + '/')
self.check_status_and_reason(response, 200)
response = self.request(self.tempdir_name)
response = self.request(self.base_url)
self.check_status_and_reason(response, 301)
response = self.request(self.tempdir_name + '/?hi=2')
response = self.request(self.base_url + '/?hi=2')
self.check_status_and_reason(response, 200)
response = self.request(self.tempdir_name + '?hi=1')
response = self.request(self.base_url + '?hi=1')
self.check_status_and_reason(response, 301)
self.assertEqual(response.getheader("Location"),
self.tempdir_name + "/?hi=1")
self.base_url + "/?hi=1")
response = self.request('/ThisDoesNotExist')
self.check_status_and_reason(response, 404)
response = self.request('/' + 'ThisDoesNotExist' + '/')
self.check_status_and_reason(response, 404)
with open(os.path.join(self.tempdir_name, 'index.html'), 'w') as fp:
response = self.request('/' + self.tempdir_name + '/')
response = self.request(self.base_url + '/')
self.check_status_and_reason(response, 200)
# chmod() doesn't work as expected on Windows, and filesystem
# permissions are ignored by root on Unix.
if os.name == 'posix' and os.geteuid() != 0:
os.chmod(self.tempdir, 0)
response = self.request(self.tempdir_name + '/')
response = self.request(self.base_url + '/')
self.check_status_and_reason(response, 404)
os.chmod(self.tempdir, 0755)
def test_head(self):
response = self.request(
self.tempdir_name + '/test', method='HEAD')
self.base_url + '/test', method='HEAD')
self.check_status_and_reason(response, 200)
self.assertEqual(response.getheader('content-length'),
str(len(self.data)))
......@@ -360,6 +400,22 @@ class SimpleHTTPServerTestCase(BaseTestCase):
response = self.request('/', method='GETs')
self.check_status_and_reason(response, 501)
def test_path_without_leading_slash(self):
response = self.request(self.tempdir_name + '/test')
self.check_status_and_reason(response, 200, data=self.data)
response = self.request(self.tempdir_name + '/test/')
self.check_status_and_reason(response, 404)
response = self.request(self.tempdir_name + '/')
self.check_status_and_reason(response, 200)
response = self.request(self.tempdir_name)
self.check_status_and_reason(response, 301)
response = self.request(self.tempdir_name + '/?hi=2')
self.check_status_and_reason(response, 200)
response = self.request(self.tempdir_name + '?hi=1')
self.check_status_and_reason(response, 301)
self.assertEqual(response.getheader("Location"),
self.tempdir_name + "/?hi=1")
cgi_file1 = """\
#!%s
......@@ -386,7 +442,7 @@ cgi_file4 = """\
import os
print("Content-type: text/html")
print()
print("")
print(os.environ["%s"])
"""
......@@ -587,6 +643,25 @@ class SimpleHTTPRequestHandlerTestCase(unittest.TestCase):
path = self.handler.translate_path('//filename?foo=bar')
self.assertEqual(path, self.translated)
def test_windows_colon(self):
import SimpleHTTPServer
with test_support.swap_attr(SimpleHTTPServer.os, 'path', ntpath):
path = self.handler.translate_path('c:c:c:foo/filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
path = self.handler.translate_path('\\c:../filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
path = self.handler.translate_path('c:\\c:..\\foo/filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
path = self.handler.translate_path('c:c:foo\\c:c:bar/filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
def test_main(verbose=None):
try:
......
......@@ -251,6 +251,12 @@ if sys.version_info[:3] <= (2, 7, 8):
'test_threading_local.PyThreadingLocalTests.test_derived',
'test_urllib.UtilityTests.test_toBytes',
'test_httplib.HTTPSTest.test_networked_trusted_by_default_cert',
# Exposed as broken with the update of test_httpservers.py to 2.7.13
'test_httpservers.SimpleHTTPRequestHandlerTestCase.test_windows_colon',
'test_httpservers.BaseHTTPServerTestCase.test_head_via_send_error',
'test_httpservers.BaseHTTPServerTestCase.test_send_error',
'test_httpservers.SimpleHTTPServerTestCase.test_path_without_leading_slash',
]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment