Skip to content
Open
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
8 changes: 4 additions & 4 deletions lib/ex_aws/s3.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1367,9 +1367,9 @@ defmodule ExAws.S3 do
def presigned_url(config, http_method, bucket, object, opts \\ []) do
expires_in = Keyword.get(opts, :expires_in, 3600)
query_params = Keyword.get(opts, :query_params, [])
virtual_host = Keyword.get(opts, :virtual_host, false)
virtual_host = Keyword.get(opts, :virtual_host, config[:virtual_host] || false)
s3_accelerate = Keyword.get(opts, :s3_accelerate, false)
bucket_as_host = Keyword.get(opts, :bucket_as_host, false)
bucket_as_host = Keyword.get(opts, :bucket_as_host, config[:bucket_as_host] || false)
headers = Keyword.get(opts, :headers, [])

{config, virtual_host} =
Expand Down Expand Up @@ -1431,9 +1431,9 @@ defmodule ExAws.S3 do
) :: presigned_post_result()
def presigned_post(config, bucket, key, opts \\ []) do
expires_in = Keyword.get(opts, :expires_in, 3600)
virtual_host = Keyword.get(opts, :virtual_host, false)
virtual_host = Keyword.get(opts, :virtual_host, config[:virtual_host] || false)
s3_accelerate = Keyword.get(opts, :s3_accelerate, false)
bucket_as_host = Keyword.get(opts, :bucket_as_host, false)
bucket_as_host = Keyword.get(opts, :bucket_as_host, config[:bucket_as_host] || false)
{:ok, datetime} = DateTime.now("Etc/UTC")
expiration_date = DateTime.add(datetime, expires_in, :second)
datetime = datetime_to_erlang_time(datetime)
Expand Down
45 changes: 45 additions & 0 deletions test/lib/s3_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,51 @@ defmodule ExAws.S3Test do
assert_pre_signed_url(url, "https://bucket.custom-domain.com/foo.txt", "3600")
end

test "#initiate_multipart_upload returns proper operation structure" do
# Test that the operation structure is created correctly
operation = S3.initiate_multipart_upload("my-bucket.custom-domain.com", "test-key.txt")

assert operation.http_method == :post
assert operation.bucket == "my-bucket.custom-domain.com"
assert operation.path == "test-key.txt"
assert operation.resource == "uploads"
end

test "#presigned_url with bucket_as_host should not duplicate bucket in path" do
# Test the specific issue where bucket domain appears twice
config = config()
opts = [virtual_host: true, bucket_as_host: true]

{:ok, url} = S3.presigned_url(config, :get, "my-custom-domain.com", "path/to/file.txt", opts)

# Parse the URL to check the path component specifically
uri = URI.parse(url)

# The path should NOT contain the bucket name (which would indicate duplication)
refute String.contains?(uri.path, "my-custom-domain.com")
# Should contain the correct path
assert uri.path == "/path/to/file.txt"
# Should use the bucket as the hostname
assert uri.host == "my-custom-domain.com"
end

test "#presigned_url reads bucket_as_host and virtual_host from config" do
# Test that config values are used when options are not provided
config = config() |> Map.put(:virtual_host, true) |> Map.put(:bucket_as_host, true)

{:ok, url} = S3.presigned_url(config, :get, "my-custom-domain.com", "path/to/file.txt")

# Parse the URL to check components specifically
uri = URI.parse(url)

# Should use bucket as hostname even without explicit opts
assert uri.host == "my-custom-domain.com"
# The path should NOT contain the bucket name (which would indicate duplication)
refute String.contains?(uri.path, "my-custom-domain.com")
# Should contain the correct path
assert uri.path == "/path/to/file.txt"
end

test "#presigned_url passing query_params option" do
query_params = [
key_one: "value_one",
Expand Down