Repository navigation
bpo-11671: add header validation from http.client to wsgiref.headers.Headers #15299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
221779a
501ac89
6928b31
6cd271a
8446cfd
71d5819
d172a8e
db98184
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -525,16 +525,37 @@ def testExtras(self): | |
| '\r\n' | ||
| ) | ||
|
|
||
| def testValidateHeaders(self): | ||
| validation_cases = ( | ||
| ('Invalid\r\nName', 'ValidValue'), | ||
| ('Invalid\rName', 'ValidValue'), | ||
| ('Invalid\nName', 'ValidValue'), | ||
| ('\r\nInvalidName', 'ValidValue'), | ||
| ('\rInvalidName', 'ValidValue'), | ||
| ('\nInvalidName', 'ValidValue'), | ||
| (' InvalidName', 'ValidValue'), | ||
| ('\tInvalidName', 'ValidValue'), | ||
| ('Invalid:Name', 'ValidValue'), | ||
| (':InvalidName', 'ValidValue'), | ||
| ('ValidName', 'Invalid\r\nValue'), | ||
| ('ValidName', 'Invalid\rValue'), | ||
| ('ValidName', 'Invalid\nValue'), | ||
| ('ValidName', 'InvalidValue\r\n'), | ||
| ('ValidName', 'InvalidValue\r'), | ||
| ('ValidName', 'InvalidValue\n') | ||
| ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there already tests for header names which cannot be encoded to ASCII? And tests for values not encodable to Latin1? |
||
|
|
||
| def test_add_header_validation(self): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to merge the two tests a single test, to factorize code. I suggest to remove the b'InvalidName' and b'InvalidValue' from validation_cases. Maybe create a second list, maybe put it directly in the test method to avoid |
||
| h = Headers([]) | ||
| self.assertRaises(ValueError, h.add_header, 'foo', 'bar\rbaz: bat') | ||
| self.assertRaises(ValueError, h.add_header, 'foo', 'bar\nbaz: bat') | ||
| self.assertRaises(ValueError, h.add_header, 'foo: bar', 'baz') | ||
| self.assertRaises(ValueError, h.add_header, 'foo:\rbar', 'baz') | ||
| self.assertRaises(ValueError, h.add_header, 'foo:\nbar', 'baz') | ||
| self.assertRaises(ValueError, h.add_header, 'foo', 'bar\nbaz: bat') | ||
| self.assertRaises(ValueError, h.add_header, 'foo', 'bar', baz='bat\rqux: spam') | ||
| self.assertRaises(ValueError, h.add_header, 'foo', 'bar', baz='bat\nqux: spam') | ||
| for name, value in self.validation_cases: | ||
| with self.subTest((name, value)): | ||
| with self.assertRaisesRegex(ValueError, 'Invalid header'): | ||
| h.add_header(name, value) | ||
|
|
||
| def test_initialize_validation(self): | ||
|
epicfaace marked this conversation as resolved.
|
||
| for name, value in self.validation_cases: | ||
| with self.subTest((name, value)): | ||
| with self.assertRaisesRegex(ValueError, 'Invalid header'): | ||
| Headers([(name, value)]) | ||
|
|
||
| class ErrorHandler(BaseCGIHandler): | ||
| """Simple handler subclass for testing BaseHandler""" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment mentioning bpo-11671.
Rather than an hardcoded list, why not building such list using a few invalid characters. For example for header names:
Are whitespaces (" ") and colon (":") only invalid at the beginning of the name?