Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Waz committed Nov 23, 2022
1 parent f90811b commit efae25f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
3 changes: 3 additions & 0 deletions big_tests/tests/mongooseimctl_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ check_urls(PutURL, GetURL, WithACL, ContentType) ->
check_substring(?S3_DATE_REGEX, PutURL),
check_substring(?S3_EXPIRATION_REGEX, PutURL),
SignedHeadersRegex = signed_headers_regex(WithACL, ContentType),
ct:pal("PutURL ~p~n", [PutURL]),
ct:pal("WithACL ~p~n", [WithACL]),
ct:pal("ContentType ~p~n", [ContentType]),
check_substring(SignedHeadersRegex, PutURL),
check_substring(?S3_SIGNATURE_REGEX, PutURL).

Expand Down
42 changes: 28 additions & 14 deletions src/http_upload/mod_http_upload_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
-spec get_urls_mongooseimctl(Domain :: jid:lserver(), Filename :: binary(), Size :: pos_integer(),
ContentType :: binary() | undefined, Timeout :: pos_integer()) ->
{ok | error, string()}.
get_urls_mongooseimctl(_Domain, _Filename, Size, _ContentType, _Timeout) when Size =< 0 ->
{error, "size must be positive integer"};
get_urls_mongooseimctl(_Domain, _Filename, _Size, _ContentType, Timeout) when Timeout =< 0 ->
{error, "timeout must be positive integer"};
get_urls_mongooseimctl(Domain, Filename, Size, ContentType, Timeout) ->
case get_urls(Domain, Filename, Size, ContentType, Timeout) of
{ok, #{<<"putUrl">> := PutURL, <<"getUrl">> := GetURL, <<"Header">> := _Headers}} ->
{ok, generate_output_message(PutURL, GetURL)};
{ok, #{<<"putUrl">> := PutURL, <<"getUrl">> := GetURL, <<"headers">> := Headers}} ->
{ok, generate_output_message(PutURL, GetURL, Headers)};
{_, Message} ->
{error, Message}
end.
Expand All @@ -34,24 +38,34 @@ content_type(undefined) -> <<>>;
content_type(Binary) -> Binary.

check_module_and_get_urls(HostType, Filename, Size, ContentType, Timeout) ->
case mod_http_upload:get_urls(HostType, Filename, Size, ContentType, Timeout) of
{PutURL, GetURL, Headers} ->
{ok, #{<<"putUrl">> => PutURL, <<"getUrl">> => GetURL,
<<"headers">> => headers_output(Headers)}};
file_too_large_error ->
{file_too_large_error,
"Declared file size exceeds the host's maximum file size."}
case gen_mod:is_loaded(HostType, mod_http_upload) of
true ->
case mod_http_upload:get_urls(HostType, Filename, Size, ContentType, Timeout) of
{PutURL, GetURL, Headers} ->
Headers1 = lists:map(fun({Name, Value}) -> {ok, #{<<"name">> => Name, <<"value">> => Value}} end,
maps:to_list(Headers)),
{ok, #{<<"putUrl">> => PutURL, <<"getUrl">> => GetURL,
<<"headers">> => Headers1}};
file_too_large_error ->
{file_too_large_error,
"Declared file size exceeds the host's maximum file size."}
end;
false ->
{module_not_loaded_error, "mod_http_upload is not loaded for this host"}
end.

-spec generate_output_message(PutURL :: binary(), GetURL :: binary()) -> string().
generate_output_message(PutURL, GetURL) ->
-spec generate_output_message(PutURL :: binary(),
GetURL :: binary(),
Headers :: [{ok, map()}]) -> string().
generate_output_message(PutURL, GetURL, Headers) ->
PutURLOutput = url_output("PutURL:", PutURL),
GetURLOutput = url_output("GetURL:", GetURL),
lists:flatten([PutURLOutput, GetURLOutput]).
HeadersOutput = headers_output(Headers),
lists:flatten([PutURLOutput, GetURLOutput, HeadersOutput]).

url_output(Name, Url) ->
io_lib:format("~s ~s~n", [Name, Url]).

headers_output(Headers) when Headers =:= #{} -> [];
headers_output(Headers) ->
lists:map(fun({Key, Value}) -> {ok, #{<<"name">> => Key, <<"value">> => Value}} end, maps:to_list(Headers)).
List = [{Name, Value} || {ok, #{<<"name">> := Name, <<"value">> := Value}} <- Headers],
io_lib:format("Header: ~p~n", [List]).

0 comments on commit efae25f

Please sign in to comment.