Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
it "generates a signed post object v4 simple" do
post_object = bucket.generate_signed_post_policy_v4 "test-object", expires: 10

_(post_object.fields.keys.sort).must_equal [
"key",
"policy",
"x-goog-algorithm",
"x-goog-credential",
"x-goog-date",
"x-goog-signature"
]

form_data = [['file', File.open(data)]]

post_object.fields.each do |key, value|
Expand All @@ -55,6 +64,15 @@
it "generates a signed post object v4 virtual hosted style" do
post_object = bucket.generate_signed_post_policy_v4 "test-object", expires: 10, virtual_hosted_style: true

_(post_object.fields.keys.sort).must_equal [
"key",
"policy",
"x-goog-algorithm",
"x-goog-credential",
"x-goog-date",
"x-goog-signature"
]

form_data = [['file', File.open(data)]]

post_object.fields.each do |key, value|
Expand Down Expand Up @@ -84,6 +102,17 @@
}
post_object = bucket.generate_signed_post_policy_v4 "test-object", expires: 10, fields: fields

_(post_object.fields.keys.sort).must_equal [
"acl",
"cache-control",
"key",
"policy",
"x-goog-algorithm",
"x-goog-credential",
"x-goog-date",
"x-goog-signature"
]

form_data = [['file', File.open(data)]]

post_object.fields.each do |key, value|
Expand Down Expand Up @@ -113,6 +142,16 @@
}
post_object = bucket.generate_signed_post_policy_v4 "test-object", expires: 10, fields: fields

_(post_object.fields.keys.sort).must_equal [
"key",
"policy",
"success_action_status",
"x-goog-algorithm",
"x-goog-credential",
"x-goog-date",
"x-goog-signature"
]

form_data = [['file', File.open(data)]]

post_object.fields.each do |key, value|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def post_object issuer: nil,
expires ||= 60*60*24
p["expiration"] = (now + expires).strftime "%Y-%m-%dT%H:%M:%SZ"


policy_str = escape_characters p.to_json

policy = Base64.strict_encode64(policy_str).force_encoding "utf-8"
Expand Down Expand Up @@ -164,7 +163,6 @@ def escape_special_unicode str

def required_fields issuer, time
{
"bucket" => @bucket_name,
"key" => @file_name,
"x-goog-date" => time.strftime("%Y%m%dT%H%M%SZ"),
"x-goog-credential" => "#{issuer}/#{time.strftime '%Y%m%d'}/auto/storage/goog4_request",
Expand All @@ -175,6 +173,8 @@ def required_fields issuer, time
def policy_conditions base_fields, user_conditions, user_fields
# Convert each pair in base_fields hash to a single-entry hash in an array.
conditions = base_fields.to_a.map { |f| Hash[*f] }
# Add the bucket to the head of the base_fields. This is not returned in the PostObject fields.
conditions.unshift "bucket" => @bucket_name
# Add user-provided conditions to the head of the conditions array.
conditions.unshift user_conditions if user_conditions && !user_conditions.empty?
if user_fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def self.signer_v4_test_for description, input, output, index
bucket_bound_hostname: bucket_bound_hostname

_(post_object.url).must_equal output.url

_(post_object.fields.keys.sort).must_equal output.fields.keys.sort

_(post_object.fields["key"]).must_equal output.fields["key"]
_(post_object.fields["x-goog-algorithm"]).must_equal output.fields["x-goog-algorithm"]
_(post_object.fields["x-goog-credential"]).must_equal output.fields["x-goog-credential"]
Expand Down Expand Up @@ -84,6 +87,9 @@ def self.bucket_test_for description, input, output, index
bucket_bound_hostname: bucket_bound_hostname

_(post_object.url).must_equal output.url

_(post_object.fields.keys.sort).must_equal output.fields.keys.sort

_(post_object.fields["key"]).must_equal output.fields["key"]
_(post_object.fields["x-goog-algorithm"]).must_equal output.fields["x-goog-algorithm"]
_(post_object.fields["x-goog-credential"]).must_equal output.fields["x-goog-credential"]
Expand Down