Fix swift3 authentication bug about the Date and X-Amz-Date handling.
This commit is contained in:
commit
fe27d30c5e
@ -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)
|
||||
|
@ -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=
|
||||
|
Loading…
Reference in New Issue
Block a user