Skip to content

Commit

Permalink
fix(storage): Fix encoding of space characters in file names in signe…
Browse files Browse the repository at this point in the history
…d_url v4

closes: #7835
pr: #7860
  • Loading branch information
quartzmo committed Oct 2, 2020
1 parent a28225f commit 4380c02
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions google-cloud-storage/acceptance/storage/bucket_test.rb
Expand Up @@ -195,9 +195,9 @@

_(bucket.lifecycle.last.created_before).must_be_kind_of Date
_(bucket.lifecycle.last.created_before).must_equal created_before_2
_(bucket.lifecycle.last.custom_time_before).must_be_kind_of DateTime
_(bucket.lifecycle.last.custom_time_before).must_be_kind_of Date
_(bucket.lifecycle.last.custom_time_before).must_equal custom_time_before_2
_(bucket.lifecycle.last.noncurrent_time_before).must_be_kind_of DateTime
_(bucket.lifecycle.last.noncurrent_time_before).must_be_kind_of Date
_(bucket.lifecycle.last.noncurrent_time_before).must_equal noncurrent_time_before_2


Expand All @@ -210,13 +210,13 @@
_(bucket.lifecycle.last.age).must_equal 20
_(bucket.lifecycle.last.created_before).must_be_kind_of Date
_(bucket.lifecycle.last.created_before).must_equal created_before_2
_(bucket.lifecycle.last.custom_time_before).must_be_kind_of DateTime
_(bucket.lifecycle.last.custom_time_before).must_be_kind_of Date
_(bucket.lifecycle.last.custom_time_before).must_equal custom_time_before_2
_(bucket.lifecycle.last.days_since_custom_time).must_equal 6
_(bucket.lifecycle.last.days_since_noncurrent_time).must_equal 15
_(bucket.lifecycle.last.is_live).must_equal false
_(bucket.lifecycle.last.matches_storage_class).must_equal ["NEARLINE"]
_(bucket.lifecycle.last.noncurrent_time_before).must_be_kind_of DateTime
_(bucket.lifecycle.last.noncurrent_time_before).must_be_kind_of Date
_(bucket.lifecycle.last.noncurrent_time_before).must_equal noncurrent_time_before_2
_(bucket.lifecycle.last.num_newer_versions).must_equal 4

Expand Down
16 changes: 8 additions & 8 deletions google-cloud-storage/acceptance/storage/signed_url_v2_test.rb
Expand Up @@ -44,9 +44,9 @@
end

describe Google::Cloud::Storage::Project, :signed_url do
it "should create a signed read url" do
it "should create a signed read url with space in file name" do
local_file = File.new files[:logo][:path]
file = bucket.create_file local_file, "CloudLogoSignedUrlGetBucket.png"
file = bucket.create_file local_file, "CloudLogoSignedUrl GetBucket.png"

five_min_from_now = 5 * 60
url = storage.signed_url bucket.name, file.name, method: "GET",
Expand All @@ -69,9 +69,9 @@
end
end

it "should create a signed POST url version v2" do
it "should create a signed POST url version v2 with space in file name" do
url = storage.signed_url bucket.name,
"CloudLogoProjectSignedUrlPost.png",
"CloudLogoProjectSignedUrl Post.png",
method: "POST",
content_type: "image/png", # Required for V2
headers: { "x-goog-resumable" => "start" },
Expand All @@ -90,9 +90,9 @@
end

describe Google::Cloud::Storage::Bucket, :signed_url do
it "should create a signed read url" do
it "should create a signed read url with space in file name" do
local_file = File.new files[:logo][:path]
file = bucket.create_file local_file, "CloudLogoSignedUrlGetBucket.png"
file = bucket.create_file local_file, "CloudLogoSignedUrl GetBucket.png"

five_min_from_now = 5 * 60
url = bucket.signed_url file.name, method: "GET",
Expand Down Expand Up @@ -197,9 +197,9 @@
end

describe Google::Cloud::Storage::File, :signed_url do
it "should create a signed read url" do
it "should create a signed read url with space in file name" do
local_file = File.new files[:logo][:path]
file = bucket.create_file local_file, "CloudLogoSignedUrlGetFile.png"
file = bucket.create_file local_file, "CloudLogoSignedUrl GetFile.png"

five_min_from_now = 5 * 60
url = file.signed_url method: "GET",
Expand Down
20 changes: 10 additions & 10 deletions google-cloud-storage/acceptance/storage/signed_url_v4_test.rb
Expand Up @@ -44,9 +44,9 @@
end

describe Google::Cloud::Storage::Project, :signed_url do
it "should create a signed read url version v4" do
it "should create a signed read url version v4 with space in file name" do
local_file = File.new files[:logo][:path]
file = bucket.create_file local_file, "CloudLogoSignedUrlGetBucket.png"
file = bucket.create_file local_file, "CloudLogoSignedUrl GetBucket.png"

five_min_from_now = 5 * 60
url = storage.signed_url bucket.name, file.name, method: "GET",
Expand All @@ -69,10 +69,10 @@
end
end

it "should create a signed POST url version v4" do
it "should create a signed POST url version v4 with space in file name" do
five_min_from_now = 60 * 60
url = storage.signed_url bucket.name,
"CloudLogoProjectSignedUrlPost.png",
"CloudLogoProjectSignedUrl Post.png",
method: "POST",
expires: five_min_from_now,
headers: { "x-goog-resumable" => "start" },
Expand All @@ -90,9 +90,9 @@
end

describe Google::Cloud::Storage::Bucket, :signed_url do
it "should create a signed read url version v4" do
it "should create a signed read url version v4 with space in file name" do
local_file = File.new files[:logo][:path]
file = bucket.create_file local_file, "CloudLogoSignedUrlGetBucket.png"
file = bucket.create_file local_file, "CloudLogoSignedUrl GetBucket.png"

five_min_from_now = 5 * 60
url = bucket.signed_url file.name, method: "GET",
Expand Down Expand Up @@ -197,9 +197,9 @@
end

describe Google::Cloud::Storage::File, :signed_url do
it "should create a signed read url version v4" do
it "should create a signed read url version v4 with space in file name" do
local_file = File.new files[:logo][:path]
file = bucket.create_file local_file, "CloudLogoSignedUrlGetFile.png"
file = bucket.create_file local_file, "CloudLogoSignedUrl GetFile.png"

five_min_from_now = 5 * 60
url = file.signed_url method: "GET",
Expand All @@ -222,9 +222,9 @@
end
end

it "should create a signed POST url version v4" do
it "should create a signed POST url version v4 with space in file name" do
five_min_from_now = 60 * 60
file = bucket.file "CloudLogoFileSignedUrlPost.png", skip_lookup: true
file = bucket.file "CloudLogoFileSignedUrl Post.png", skip_lookup: true
url = file.signed_url method: "POST",
expires: five_min_from_now,
headers: { "x-goog-resumable" => "start"},
Expand Down
Expand Up @@ -273,7 +273,7 @@ def canonical_query query, algorithm, credential, goog_date, expires, signed_hea
# Only the characters in the regex set [A-Za-z0-9.~_-] must be left un-escaped; all others must be
# percent-encoded using %XX UTF-8 style.
def escape_query_param str
CGI.escape(str.to_s).gsub("%7E", "~").gsub("+", "%20")
CGI.escape(str.to_s).gsub("%7E", "~").gsub "+", "%20"
end

def host_name virtual_hosted_style, bucket_bound_hostname
Expand All @@ -287,7 +287,7 @@ def file_path path_style
path = []
path << "/#{@bucket_name}" if path_style
path << "/#{String(@file_name)}" if @file_name && !@file_name.empty?
CGI.escape(path.join).gsub "%2F", "/"
CGI.escape(path.join).gsub("%2F", "/").gsub "+", "%20"
end

##
Expand Down

0 comments on commit 4380c02

Please sign in to comment.