From 6efeab60d93688be2663ec68d5f65911819713d4 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Mon, 11 Jul 2011 20:17:58 +0900 Subject: [PATCH 1/2] s3api: fix canonical_string for Date and X-Amz-Date header handling canonical_string needs to reset the Date header if it sees the X-Amz-Date header. --- swift/common/middleware/swift3.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/swift/common/middleware/swift3.py b/swift/common/middleware/swift3.py index df1ca3f755..95952bc3eb 100644 --- a/swift/common/middleware/swift3.py +++ b/swift/common/middleware/swift3.py @@ -128,13 +128,23 @@ def canonical_string(req): """ Canonicalize a request to a token that can be signed. """ + amz_headers = {} + buf = "%s\n%s\n%s\n" % (req.method, req.headers.get('Content-MD5', ''), req.headers.get('Content-Type') or '') - if 'Date' in req.headers: - buf += "%s\n" % req.headers['Date'] + for amz_header in sorted((key.lower() for key in req.headers if key.lower().startswith('x-amz-'))): - buf += "%s:%s\n" % (amz_header, req.headers[amz_header]) + amz_headers[amz_header] = req.headers[amz_header] + + if 'x-amz-date' in amz_headers: + buf += "\n" + elif 'Date' in req.headers: + buf += "%s\n" % req.headers['Date'] + + for k in sorted(key.lower() for key in amz_headers): + buf += "%s:%s\n" % (k, amz_headers[k]) + path = req.path_qs if '?' in path: path, args = path.split('?', 1) From e0bc916ccd1fd558775ebbd664c319702088173f Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Mon, 11 Jul 2011 20:19:43 +0900 Subject: [PATCH 2/2] s3api: add more unittests for canonical_string For the Date and X-Amz-Date header handling. --- test/unit/common/middleware/test_swift3.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/unit/common/middleware/test_swift3.py b/test/unit/common/middleware/test_swift3.py index bca9badacb..2579cce83d 100644 --- a/test/unit/common/middleware/test_swift3.py +++ b/test/unit/common/middleware/test_swift3.py @@ -573,6 +573,15 @@ class TestSwift3(unittest.TestCase): verify('7506d97002c7d2de922cc0ec34af8846', '/bucket/object', {'Content-Type': None, 'X-Amz-Something': 'test'}) + verify('28f76d6162444a193b612cd6cb20e0be', '/bucket/object', + {'Content-Type': None, + 'X-Amz-Date': 'Mon, 11 Jul 2011 10:52:57 +0000', + 'Date': 'Tue, 12 Jul 2011 10:52:57 +0000'}) + + verify('ed6971e3eca5af4ee361f05d7c272e49', '/bucket/object', + {'Content-Type': None, + 'Date': 'Tue, 12 Jul 2011 10:52:57 +0000'}) + req1 = Request.blank('/', headers= {'Content-Type': None, 'X-Amz-Something': 'test'}) req2 = Request.blank('/', headers=