Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly encode bytes for V2 signature #382

Merged
merged 3 commits into from Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion google/cloud/storage/_signing.py
Expand Up @@ -77,7 +77,7 @@ def get_signed_query_params_v2(credentials, expiration, string_to_sign):
signed payload.
"""
ensure_signed_credentials(credentials)
signature_bytes = credentials.sign_bytes(string_to_sign)
signature_bytes = credentials.sign_bytes(string_to_sign.encode("ascii"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

signature = base64.b64encode(signature_bytes)
service_account_name = credentials.signer_email
return {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test__signing.py
Expand Up @@ -255,7 +255,7 @@ def test_it(self):
"Signature": base64.b64encode(sig_bytes),
}
self.assertEqual(result, expected)
credentials.sign_bytes.assert_called_once_with(string_to_sign)
credentials.sign_bytes.assert_called_once_with(bytes(string_to_sign, encoding="ascii"))


class Test_get_canonical_headers(unittest.TestCase):
Expand Down Expand Up @@ -418,7 +418,7 @@ def _generate_helper(
elements.extend(["{}:{}".format(*header) for header in headers])
elements.append(expected_resource)

string_to_sign = "\n".join(elements)
string_to_sign = bytes("\n".join(elements), encoding="ascii")

credentials.sign_bytes.assert_called_once_with(string_to_sign)

Expand Down