]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-35565: Add detail to assertion failure message in wsgiref (GH-11293)
authorCheryl Sabella <cheryl.sabella@gmail.com>
Tue, 25 Dec 2018 23:19:11 +0000 (18:19 -0500)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>
Tue, 25 Dec 2018 23:19:11 +0000 (15:19 -0800)
Lib/test/test_wsgiref.py
Lib/wsgiref/handlers.py

index 737dfed3a51e574ebb91cf28e1bf0821ffab46d0..3a953d841b8846d711069241497472165df104b2 100644 (file)
@@ -193,6 +193,19 @@ class IntegrationTests(TestCase):
                 ))
                 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()
index f4300b831a44e40e41966d1d5c578566b4bb805e..28ed9b7a6d0353db063ab8802083d78e329a18ef 100644 (file)
@@ -233,7 +233,8 @@ class BaseHandler:
             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