Skip to content

Commit

Permalink
Respect is_secure parameter in generate_url_sigv4
Browse files Browse the repository at this point in the history
Previously, the protocol was hardcoded to https.
  • Loading branch information
tipabu committed Jun 6, 2016
1 parent 0df80e6 commit b856be3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions boto/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,8 @@ def presign(self, req, expires, iso_date=None):
# Add signature to params now that we have it
req.params['X-Amz-Signature'] = signature

return 'https://%s%s?%s' % (req.host, req.path,
urllib.parse.urlencode(req.params))
return '%s://%s%s?%s' % (req.protocol, req.host, req.path,
urllib.parse.urlencode(req.params))


class STSAnonHandler(AuthHandler):
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/s3/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,37 @@ def test_sigv4_presign(self):
'a937f5fbc125d98ac8f04c49e0204ea1526a7b8ca058000a54c192457be05b7d',
url)

def test_sigv4_presign_respects_is_secure(self):
self.config = {
's3': {
'use-sigv4': True,
}
}

conn = self.connection_class(
aws_access_key_id='less',
aws_secret_access_key='more',
host='s3.amazonaws.com',
is_secure=True,
)

url = conn.generate_url_sigv4(86400, 'GET', bucket='examplebucket',
key='test.txt')
self.assertTrue(url.startswith(
'https://examplebucket.s3.amazonaws.com/test.txt?'))

conn = self.connection_class(
aws_access_key_id='less',
aws_secret_access_key='more',
host='s3.amazonaws.com',
is_secure=False,
)

url = conn.generate_url_sigv4(86400, 'GET', bucket='examplebucket',
key='test.txt')
self.assertTrue(url.startswith(
'http://examplebucket.s3.amazonaws.com/test.txt?'))

def test_sigv4_presign_optional_params(self):
self.config = {
's3': {
Expand Down

0 comments on commit b856be3

Please sign in to comment.