diff options
-rw-r--r-- | Lib/test/test_httpservers.py | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py index c84f48f..ab74e5b 100644 --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -288,6 +288,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 +313,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 +361,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, HTTPStatus.OK, data=self.data) + response = self.request(self.tempdir_name + '/test/') + self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) + response = self.request(self.tempdir_name + '/') + self.check_status_and_reason(response, HTTPStatus.OK) + response = self.request(self.tempdir_name) + self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) + response = self.request(self.tempdir_name + '/?hi=2') + self.check_status_and_reason(response, HTTPStatus.OK) + response = self.request(self.tempdir_name + '?hi=1') + self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) + self.assertEqual(response.getheader("Location"), + self.tempdir_name + "/?hi=1") + cgi_file1 = """\ #!%s |