Skip to content
Permalink
Browse files
fix(storage): use OrderedDict while encoding POST policy (#95)
* use OrderedDict() while encoding POST policy

* fix(storage): use OrderedDict() while encoding POST policy
  • Loading branch information
IlyaFaer committed Apr 1, 2020
1 parent b451e2d commit df560e178369a6d03140e412a25af6ec7444f5a1
Showing with 13 additions and 4 deletions.
  1. +9 −1 google/cloud/storage/client.py
  2. +4 −3 tests/unit/test_client.py
@@ -16,6 +16,7 @@

import base64
import binascii
import collections
import datetime
import functools
import json
@@ -972,7 +973,14 @@ def generate_signed_post_policy_v4(

# encode policy for signing
policy = json.dumps(
{"conditions": conditions, "expiration": policy_expires.isoformat() + "Z"},
collections.OrderedDict(
sorted(
{
"conditions": conditions,
"expiration": policy_expires.isoformat() + "Z",
}.items()
)
),
separators=(",", ":"),
)
str_to_sign = base64.b64encode(policy.encode("utf-8"))
@@ -1762,6 +1762,10 @@ def test_conformance_post_policy(test_data):
scheme=in_data.get("scheme"),
)
fields = policy["fields"]
out_data = test_data["policyOutput"]

decoded_policy = base64.b64decode(fields["policy"]).decode("unicode_escape")
assert decoded_policy == out_data["expectedDecodedPolicy"]

for field in (
"x-goog-algorithm",
@@ -1771,9 +1775,6 @@ def test_conformance_post_policy(test_data):
):
assert fields[field] == test_data["policyOutput"]["fields"][field]

out_data = test_data["policyOutput"]
decoded_policy = base64.b64decode(fields["policy"]).decode("unicode_escape")
assert decoded_policy == out_data["expectedDecodedPolicy"]
assert policy["url"] == out_data["url"]


0 comments on commit df560e1

Please sign in to comment.