Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add empty value checks for delete_object #269

Merged
merged 1 commit into from
Sep 10, 2024
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
13 changes: 12 additions & 1 deletion lib/ex_aws/s3.ex
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,24 @@ defmodule ExAws.S3 do
@spec delete_object(bucket :: binary, object :: binary) :: ExAws.Operation.S3.t()
@spec delete_object(bucket :: binary, object :: binary, opts :: delete_object_opts) ::
ExAws.Operation.S3.t()
@spec delete_object(bucket :: binary, object :: nil) :: no_return
@request_headers [
:x_amz_mfa,
:x_amz_request_payer,
:x_amz_bypass_governance_retention,
:x_amz_expected_bucket_owner
]
def delete_object(bucket, object, opts \\ []) do
def delete_object(bucket, object, opts \\ [])

def delete_object(_bucket, nil = _object, _opts) do
raise "object must not be nil"
end

def delete_object(_bucket, "" = _object, _opts) do
raise "object must not be empty string"
end

def delete_object(bucket, object, opts) do
opts = opts |> Map.new()

params =
Expand Down
12 changes: 12 additions & 0 deletions test/lib/s3_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ defmodule ExAws.S3Test do
assert expected == S3.delete_object("bucket", "object")
end

test "#delete_object object must not be nil" do
assert_raise RuntimeError, "object must not be nil", fn ->
S3.delete_object("bucket", nil)
end
end

test "#delete_object object must not be empty string" do
assert_raise RuntimeError, "object must not be empty string", fn ->
S3.delete_object("bucket", "")
end
end

test "#delete_object version_id option" do
expected = %Operation.S3{
body: "",
Expand Down
Loading