Merge pull request #978 from immerrr/fix-s3-authorization-for-quoted-paths

S3DownloadHandler: fix auth for requests with quoted paths/query params
This commit is contained in:
Pablo Hoffman 2014-12-15 17:15:11 -02:00
commit 78954bc7f4
2 changed files with 19 additions and 2 deletions

View File

@ -1,3 +1,5 @@
from urlparse import unquote
from scrapy import optional_features
from scrapy.exceptions import NotConfigured
from scrapy.utils.httpobj import urlparse_cached
@ -54,8 +56,8 @@ class S3DownloadHandler(object):
signed_headers = self.conn.make_request(
method=request.method,
bucket=bucket,
key=p.path,
query_args=p.query,
key=unquote(p.path),
query_args=unquote(p.query),
headers=request.headers,
data=request.body)
httpreq = request.replace(url=url, headers=signed_headers)

View File

@ -482,6 +482,21 @@ class S3TestCase(unittest.TestCase):
self.assertEqual(httpreq.headers['Authorization'], \
'AWS 0PN5J17HBGZHT7JJ3X82:C0FlOtU8Ylb9KDTpZqYkZPX91iI=')
def test_request_signing7(self):
# ensure that spaces are quoted properly before signing
req = Request(
("s3://johnsmith/photos/my puppy.jpg"
"?response-content-disposition=my puppy.jpg"),
method='GET',
headers={
'Date': 'Tue, 27 Mar 2007 19:42:41 +0000',
})
httpreq = self.download_request(req, self.spider)
self.assertEqual(
httpreq.headers['Authorization'],
'AWS 0PN5J17HBGZHT7JJ3X82:+CfvG8EZ3YccOrRVMXNaK2eKZmM=')
class FTPTestCase(unittest.TestCase):
username = "scrapy"