summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKun Huang <gareth@unitedstack.com>2013-07-07 16:45:56 +0800
committerDarrell Bishop <darrell@swiftstack.com>2013-07-12 15:18:49 -0700
commit7d88d14def2541227fb4d3f96016a51b0bafa36b (patch)
treeadc3117986b3b0a95f0c549f30d3b98b3894f210 /tests
parent65e5ef7b8137062a9a82b3fc99f33074f1e7c2e7 (diff)
downloadpython-swiftclient-7d88d14def2541227fb4d3f96016a51b0bafa36b.tar.gz
Refuse carriage return in header value
See bug #1188896. Comparing with Curl and Django, they both refuse carriage returns in header values, so the request() method on the HTTP(S)Connection instance returned by swiftclient.client.http_connection() will raise an InvalidHeadersException if any of the headers to be sent contain a newline. Drive-by fix for a couple of header values which were integers instead of strings (Content-Length getting set to zero). Fixes bug #1188896 Change-Id: Ic6afdb92882284f843aacb06d20f682ddcb47151
Diffstat (limited to 'tests')
-rw-r--r--tests/test_swiftclient.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/tests/test_swiftclient.py b/tests/test_swiftclient.py
index e0fa400..2b4782a 100644
--- a/tests/test_swiftclient.py
+++ b/tests/test_swiftclient.py
@@ -193,6 +193,18 @@ class TestHttpHelpers(MockHttpTest):
url = 'ftp://www.test.com'
self.assertRaises(c.ClientException, c.http_connection, url)
+ def test_validate_headers(self):
+ headers = {'key': 'value'}
+ self.assertEquals(c.validate_headers(headers), None)
+
+ headers = {'key': 'value1\nvalue2'}
+ self.assertRaises(c.InvalidHeadersException, c.validate_headers,
+ headers)
+
+ headers = {'key': 'value1\rvalue2'}
+ self.assertRaises(c.InvalidHeadersException, c.validate_headers,
+ headers)
+
# TODO: following tests are placeholders, need more tests, better coverage
@@ -595,7 +607,7 @@ class TestPostObject(MockHttpTest):
u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91')
headers = {'X-Header1': u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
- 'X-2': 1, 'X-3': {'a': 'b'}, 'a-b': '.x:yz mn:kl:qr'}
+ 'X-2': '1', 'X-3': {'a': 'b'}, 'a-b': '.x:yz mn:kl:qr'}
resp = MockHttpResponse()
conn[1].getresponse = resp.fake_response