Skip to content

Commit

Permalink
Add regression test for special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
onno-vos-dev committed Feb 23, 2023
1 parent 4c43e15 commit 5905fc1
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions test/aws_s3_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end_per_testcase/2]).
%% Test cases
-export([bucket_exists/1, create_delete_bucket/1, delete/1, exists/1, list_objects/1,
delete_objects/1, read/1, write/1]).
delete_objects/1, read/1, write/1, write_special_chars/1, write_ampersand/1]).

%%--------------------------------------------------------------------
%% Common test callback functions
Expand All @@ -18,7 +18,11 @@ suite() ->
init_per_suite(Config) ->
application:ensure_all_started(aws),
Bucket = <<"test-bucket">>,
ok = aws_s3_util:create_bucket(client(), Bucket, []),
case aws_s3_util:bucket_exists(client(), Bucket, []) of
true -> ok;
false ->
ok = aws_s3_util:create_bucket(client(), Bucket, [])
end,
[{bucket, Bucket} | Config].

end_per_suite(Config) ->
Expand All @@ -35,7 +39,8 @@ end_per_testcase(_Case, Config) ->
ok.

all() ->
[write, read, exists, delete, delete_objects, list_objects, create_delete_bucket].
[write, write_special_chars, write_ampersand, read, exists, delete,
delete_objects, list_objects, create_delete_bucket].

%%--------------------------------------------------------------------
%% Test cases
Expand All @@ -45,6 +50,26 @@ write(Config) ->
?assertEqual(ok, aws_s3_util:write(client(), Bucket, Key, <<"data">>, [])),
ok.

write_special_chars(Config) ->
Bucket = ?config(bucket, Config),
Key = <<"$@=;/:+,?">>,
?assertEqual(ok, aws_s3_util:write(client(), Bucket, Key, <<"data">>, [])),
ok.

write_ampersand(Config) ->
Bucket = ?config(bucket, Config),
%% Strong recommendation to avoid it in keys as it can be written but delete_objects may fail
%% in delete_objects. Avoid using them!
KeyEncoded = <<"%26">>,
?assertEqual(ok, aws_s3_util:write(client(), Bucket, KeyEncoded, <<"data">>, [])),
?assertEqual({ok, <<"data">>}, aws_s3_util:read(client(), Bucket, KeyEncoded, [])),
?assertEqual(ok, aws_s3_util:delete(client(), Bucket, KeyEncoded, [])),
Key = <<"&">>,
?assertEqual(ok, aws_s3_util:write(client(), Bucket, Key, <<"data">>, [])),
?assertEqual({ok, <<"data">>}, aws_s3_util:read(client(), Bucket, Key, [])),
?assertEqual(ok, aws_s3_util:delete(client(), Bucket, Key, [])),
ok.

read(Config) ->
Bucket = ?config(bucket, Config),
Key = unique_key(),
Expand Down

0 comments on commit 5905fc1

Please sign in to comment.