Skip to content

Commit

Permalink
fix: fix canonical path for OSS4 signature
Browse files Browse the repository at this point in the history
  • Loading branch information
c4710n committed Jul 16, 2024
1 parent 203e5a1 commit 9f90f2b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions examples/file_store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule FileStore do
request =
build_request(
method: :put,
path: Path.join("/", key),
path: URI.encode(Path.join("/", key)),
body: data
)

Expand All @@ -30,7 +30,7 @@ defmodule FileStore do
request =
build_request(
method: :get,
path: Path.join("/", key)
path: URI.encode(Path.join("/", key))
)

opts = build_opts(sign_type: :header)
Expand All @@ -48,7 +48,7 @@ defmodule FileStore do
request =
build_request(
method: :delete,
path: Path.join("/", key)
path: URI.encode(Path.join("/", key))
)

opts = build_opts(sign_type: :header)
Expand All @@ -66,7 +66,7 @@ defmodule FileStore do
request =
build_request(
method: :get,
path: Path.join("/", key),
path: URI.encode(Path.join("/", key)),
query: "x-oss-expires=300"
)

Expand Down
4 changes: 2 additions & 2 deletions lib/alibaba_cloud_kit/signature/oss4.ex
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ defmodule AlibabaCloudKit.Signature.OSS4 do
path = request.path

if(bucket,
do: "/#{bucket}#{path}",
else: path
do: "/#{bucket}#{URI.decode(path)}",
else: URI.decode(path)
)
|> URI.encode()
end
Expand Down
8 changes: 4 additions & 4 deletions test/examples/file_store_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule FileStoreTest do

@tag external: true
test "manage files" do
key = "examples/file_store/temporary/lenna.png"
key = "examples/file_store/temporary/lenna woman.png"
assert {:ok, _key} = FileStore.put_file(key, @example_image_binary)
assert {:ok, _data} = FileStore.get_file(key)
assert {:ok, _key} = FileStore.delete_file(key)
Expand All @@ -27,7 +27,7 @@ defmodule FileStoreTest do

@tag external: true
test "generates a signed URL which can be accessed in Web browser" do
key = "examples/file_store/persistent/lenna.png"
key = "examples/file_store/persistent/lenna woman.png"
{:ok, key} = FileStore.put_file(key, @example_image_binary)
url = FileStore.get_access_url(key)
assert {:ok, %{status: 200}} = Tesla.get(url)
Expand All @@ -37,7 +37,7 @@ defmodule FileStoreTest do
test "presigns a file and uploading a file with related information" do
alias Tesla.Multipart

key = "examples/file_store/presign/lenna.png"
key = "examples/file_store/presign/lenna woman.png"

%{
endpoint: endpoint,
Expand Down Expand Up @@ -66,7 +66,7 @@ defmodule FileStoreTest do
test "presigns a file with OSS v1 signature and uploading a file with related information" do
alias Tesla.Multipart

key = "examples/file_store/presign_v1/lenna.png"
key = "examples/file_store/presign_v1/lenna woman.png"

%{
endpoint: endpoint,
Expand Down

0 comments on commit 9f90f2b

Please sign in to comment.