Skip to content

Commit

Permalink
bpo-35565: Add detail to assertion failure message in wsgiref (python…
Browse files Browse the repository at this point in the history
  • Loading branch information
csabella authored and rhettinger committed Dec 25, 2018
1 parent 32d96a2 commit 5ef4fc2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Lib/test/test_wsgiref.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,19 @@ def bad_app(environ, start_response):
))
self.assertEqual(err.splitlines()[-2], exc_message)

@unittest.skipIf(support.python_is_optimized(),
"Python was compiled with optimizations")
def test_hop_by_hop_validation_error(self):
def bad_app(environ, start_response):
start_response("200 OK", [('Content-Type', 'text/plain'),
('Connection', 'close')])
return ["Hello, world!"]
out, err = run_amock(bad_app)
self.assertTrue(out.endswith(
b"A server error occurred. Please contact the administrator."
))
self.assertRaises(AssertionError)

def test_wsgi_input(self):
def bad_app(e,s):
e["wsgi.input"].read()
Expand Down
3 changes: 2 additions & 1 deletion Lib/wsgiref/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ def start_response(self, status, headers,exc_info=None):
for name, val in headers:
name = self._convert_string_type(name, "Header name")
val = self._convert_string_type(val, "Header value")
assert not is_hop_by_hop(name),"Hop-by-hop headers not allowed"
assert not is_hop_by_hop(name),\
f"Hop-by-hop header, '{name}: {val}', not allowed"

return self.write

Expand Down

0 comments on commit 5ef4fc2

Please sign in to comment.