Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix generate_url() AttributeError when using anonymous connections
Browse files Browse the repository at this point in the history
Previously generating a URL would fail for anonymous connections
(even when using `query_auth=False`), with:
`AttributeError: 'AnonAuthHandler' object has no attribute '_hmac_256'`

That now works, and in addition the `query_auth=False` parameter
is now optional for anonymous connections.

Fixes #1540.
  • Loading branch information
edmorley committed May 25, 2017
1 parent af045f9 commit eeb5115
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
Expand Up @@ -406,12 +406,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
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.assertEqual(url, 'https://examplebucket.s3.amazonaws.com/test.txt')


class TestPresigned(MockServiceWithConfigTestCase):
connection_class = S3Connection

Expand Down

0 comments on commit eeb5115

Please sign in to comment.