Permalink
Browse files

Merge pull request #3734 from edmorley/anon-generate_url

Fix generate_url() AttributeError when using anonymous connections
  • Loading branch information...
mfschwartz committed Jun 28, 2017
2 parents 0a9b114 + 9c2fc7e commit 83481807ccf1615d692366f6ce1c6faba262b672
Showing with 17 additions and 5 deletions.
  1. +5 −5 boto/s3/connection.py
  2. +12 −0 tests/unit/s3/test_connection.py
@@ -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:
@@ -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

0 comments on commit 8348180

Please sign in to comment.