Commit 7bda809a authored by Jason Madden's avatar Jason Madden

Update test_httpservers to 2.7.13 (and be explicit about that version on...

Update test_httpservers to 2.7.13 (and be explicit about that version on travis). Fixes #924. Works in 2.7.12, haven't yet tried 2.7.8.
parent 91b408fb
...@@ -105,7 +105,7 @@ travis_test_linters: ...@@ -105,7 +105,7 @@ travis_test_linters:
BUILD_RUNTIMES?=$(PWD)/.runtimes BUILD_RUNTIMES?=$(PWD)/.runtimes
PY278=$(BUILD_RUNTIMES)/snakepit/python2.7.8 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 PY34=$(BUILD_RUNTIMES)/snakepit/python3.4.5
PY35=$(BUILD_RUNTIMES)/snakepit/python3.5.2 PY35=$(BUILD_RUNTIMES)/snakepit/python3.5.2
PY36=$(BUILD_RUNTIMES)/snakepit/python3.6.0 PY36=$(BUILD_RUNTIMES)/snakepit/python3.6.0
...@@ -159,10 +159,10 @@ develop: ...@@ -159,10 +159,10 @@ develop:
${PIP} install -U -r dev-requirements.txt ${PIP} install -U -r dev-requirements.txt
lint-py27: $(PY27) 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) 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) test-py278: $(PY278)
ls $(BUILD_RUNTIMES)/versions/python2.7.8/bin/ ls $(BUILD_RUNTIMES)/versions/python2.7.8/bin/
......
...@@ -85,7 +85,7 @@ for var in "$@"; do ...@@ -85,7 +85,7 @@ for var in "$@"; do
install 2.7.8 python2.7.8 install 2.7.8 python2.7.8
;; ;;
2.7) 2.7)
install 2.7.12 python2.7 install 2.7.13 python2.7.13
;; ;;
3.2) 3.2)
install 3.2.6 python3.2 install 3.2.6 python3.2
......
...@@ -8,6 +8,7 @@ import os ...@@ -8,6 +8,7 @@ import os
import sys import sys
import re import re
import base64 import base64
import ntpath
import shutil import shutil
import urllib import urllib
import httplib import httplib
...@@ -177,6 +178,12 @@ class BaseHTTPServerTestCase(BaseTestCase): ...@@ -177,6 +178,12 @@ class BaseHTTPServerTestCase(BaseTestCase):
self.send_header('Connection', 'close') self.send_header('Connection', 'close')
self.end_headers() 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): def setUp(self):
BaseTestCase.setUp(self) BaseTestCase.setUp(self)
self.con = httplib.HTTPConnection('localhost', self.PORT) self.con = httplib.HTTPConnection('localhost', self.PORT)
...@@ -275,6 +282,38 @@ class BaseHTTPServerTestCase(BaseTestCase): ...@@ -275,6 +282,38 @@ class BaseHTTPServerTestCase(BaseTestCase):
res = self.con.getresponse() res = self.con.getresponse()
self.assertEqual(res.status, 999) 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 SimpleHTTPServerTestCase(BaseTestCase):
class request_handler(NoLogRequestHandler, SimpleHTTPRequestHandler): class request_handler(NoLogRequestHandler, SimpleHTTPRequestHandler):
...@@ -288,6 +327,7 @@ class SimpleHTTPServerTestCase(BaseTestCase): ...@@ -288,6 +327,7 @@ class SimpleHTTPServerTestCase(BaseTestCase):
self.data = 'We are the knights who say Ni!' self.data = 'We are the knights who say Ni!'
self.tempdir = tempfile.mkdtemp(dir=basetempdir) self.tempdir = tempfile.mkdtemp(dir=basetempdir)
self.tempdir_name = os.path.basename(self.tempdir) self.tempdir_name = os.path.basename(self.tempdir)
self.base_url = '/' + self.tempdir_name
temp = open(os.path.join(self.tempdir, 'test'), 'wb') temp = open(os.path.join(self.tempdir, 'test'), 'wb')
temp.write(self.data) temp.write(self.data)
temp.close() temp.close()
...@@ -312,39 +352,39 @@ class SimpleHTTPServerTestCase(BaseTestCase): ...@@ -312,39 +352,39 @@ class SimpleHTTPServerTestCase(BaseTestCase):
def test_get(self): def test_get(self):
#constructs the path relative to the root directory of the HTTPServer #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) self.check_status_and_reason(response, 200, data=self.data)
# check for trailing "/" which should return 404. See Issue17324 # 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) 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) 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) 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) 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.check_status_and_reason(response, 301)
self.assertEqual(response.getheader("Location"), self.assertEqual(response.getheader("Location"),
self.tempdir_name + "/?hi=1") self.base_url + "/?hi=1")
response = self.request('/ThisDoesNotExist') response = self.request('/ThisDoesNotExist')
self.check_status_and_reason(response, 404) self.check_status_and_reason(response, 404)
response = self.request('/' + 'ThisDoesNotExist' + '/') response = self.request('/' + 'ThisDoesNotExist' + '/')
self.check_status_and_reason(response, 404) self.check_status_and_reason(response, 404)
with open(os.path.join(self.tempdir_name, 'index.html'), 'w') as fp: 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) self.check_status_and_reason(response, 200)
# chmod() doesn't work as expected on Windows, and filesystem # chmod() doesn't work as expected on Windows, and filesystem
# permissions are ignored by root on Unix. # permissions are ignored by root on Unix.
if os.name == 'posix' and os.geteuid() != 0: 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.base_url + '/')
self.check_status_and_reason(response, 404) self.check_status_and_reason(response, 404)
os.chmod(self.tempdir, 0755) os.chmod(self.tempdir, 0755)
def test_head(self): def test_head(self):
response = self.request( response = self.request(
self.tempdir_name + '/test', method='HEAD') self.base_url + '/test', method='HEAD')
self.check_status_and_reason(response, 200) self.check_status_and_reason(response, 200)
self.assertEqual(response.getheader('content-length'), self.assertEqual(response.getheader('content-length'),
str(len(self.data))) str(len(self.data)))
...@@ -360,6 +400,22 @@ class SimpleHTTPServerTestCase(BaseTestCase): ...@@ -360,6 +400,22 @@ class SimpleHTTPServerTestCase(BaseTestCase):
response = self.request('/', method='GETs') response = self.request('/', method='GETs')
self.check_status_and_reason(response, 501) 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 = """\ cgi_file1 = """\
#!%s #!%s
...@@ -386,7 +442,7 @@ cgi_file4 = """\ ...@@ -386,7 +442,7 @@ cgi_file4 = """\
import os import os
print("Content-type: text/html") print("Content-type: text/html")
print() print("")
print(os.environ["%s"]) print(os.environ["%s"])
""" """
...@@ -587,6 +643,25 @@ class SimpleHTTPRequestHandlerTestCase(unittest.TestCase): ...@@ -587,6 +643,25 @@ class SimpleHTTPRequestHandlerTestCase(unittest.TestCase):
path = self.handler.translate_path('//filename?foo=bar') path = self.handler.translate_path('//filename?foo=bar')
self.assertEqual(path, self.translated) 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): def test_main(verbose=None):
try: try:
......
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