Skip to content

Commit

Permalink
Merge pull request boto#3734 from edmorley/anon-generate_url
Browse files Browse the repository at this point in the history
Fix generate_url() AttributeError when using anonymous connections
  • Loading branch information
mfschwartz authored Jun 28, 2017
2 parents 0a9b114 + 9c2fc7e commit 8348180
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 5 additions & 5 deletions boto/s3/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,12 @@ def generate_url(self, expires_in, method, bucket='', key='', headers=None,
if extra_qp:
delimiter = '?' if '?' not in auth_path else '&'
auth_path += delimiter + '&'.join(extra_qp)
c_string = boto.utils.canonical_string(method, auth_path, headers,
expires, self.provider)
b64_hmac = self._auth_handler.sign_string(c_string)
encoded_canonical = urllib.parse.quote(b64_hmac, safe='')
self.calling_format.build_path_base(bucket, key)
if query_auth:
if query_auth and not self.anon:
c_string = boto.utils.canonical_string(method, auth_path, headers,
expires, self.provider)
b64_hmac = self._auth_handler.sign_string(c_string)
encoded_canonical = urllib.parse.quote(b64_hmac, safe='')
query_part = '?' + self.QueryString % (encoded_canonical, expires,
self.aws_access_key_id)
else:
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/s3/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ def test_switched(self):
)


class TestAnon(MockServiceWithConfigTestCase):
connection_class = S3Connection

def test_generate_url(self):
conn = self.connection_class(
anon=True,
host='s3.amazonaws.com'
)
url = conn.generate_url(0, 'GET', bucket='examplebucket', key='test.txt')
self.assertNotIn('Signature=', url)


class TestPresigned(MockServiceWithConfigTestCase):
connection_class = S3Connection

Expand Down

0 comments on commit 8348180

Please sign in to comment.