From a24c1ad00128501132b2c87bdb32afff67b33e60 Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Tue, 25 May 2021 10:05:23 +0200 Subject: [PATCH] [RTI-9513] Adjust for OTP23 (#18) * [RTI-9513] Adjust for OTP23 * [RTI-9513] Temporarily preserve http_uri functions until we move out of OTP22 * [RTI-9513] Fix pattern * [RTI-9513] Fix it with macros * [RTI-9513] Also remove http_uri:encode * [RTI-9513] normalize is required before percent_decoding --- Makefile | 2 +- rebar.config | 12 ++- rebar.lock | 18 ++-- src/erlcloud_athena.erl | 2 +- src/erlcloud_aws.erl | 8 +- src/erlcloud_cloudsearch.erl | 4 +- src/erlcloud_cloudtrail.erl | 28 ++--- src/erlcloud_cloudwatch_logs.erl | 2 +- src/erlcloud_config.erl | 2 +- src/erlcloud_cur.erl | 4 +- src/erlcloud_ddb_impl.erl | 4 +- src/erlcloud_ddb_streams.erl | 4 +- src/erlcloud_directconnect.erl | 2 +- src/erlcloud_ecs.erl | 2 +- src/erlcloud_emr.erl | 4 +- src/erlcloud_glue.erl | 2 +- src/erlcloud_guardduty.erl | 2 +- src/erlcloud_iam.erl | 8 +- src/erlcloud_inspector.erl | 2 +- src/erlcloud_kinesis_impl.erl | 4 +- src/erlcloud_kms.erl | 2 +- src/erlcloud_lambda.erl | 2 +- src/erlcloud_mes.erl | 2 +- src/erlcloud_mms.erl | 2 +- src/erlcloud_s3.erl | 6 +- src/erlcloud_sns.erl | 4 +- src/erlcloud_states.erl | 2 +- src/erlcloud_util.erl | 4 +- src/erlcloud_waf.erl | 2 +- test/erlcloud_aws_tests.erl | 26 +++-- test/erlcloud_cloudtrail_tests.erl | 52 +++++----- test/erlcloud_cloudwatch_logs_tests.erl | 2 +- test/erlcloud_ddb2_tests.erl | 4 +- test/erlcloud_ddb_streams_tests.erl | 4 +- test/erlcloud_ddb_tests.erl | 124 +++++++++++----------- test/erlcloud_directconnect_tests.erl | 4 +- test/erlcloud_ecs_tests.erl | 4 +- test/erlcloud_emr_tests.erl | 2 +- test/erlcloud_iam_tests.erl | 132 ++++++++++++------------ test/erlcloud_inspector_tests.erl | 6 +- test/erlcloud_kinesis_tests.erl | 14 +-- test/erlcloud_kms_tests.erl | 4 +- test/erlcloud_mes_tests.erl | 8 +- test/erlcloud_mms_tests.erl | 10 +- test/erlcloud_sdb_tests.erl | 17 ++- test/erlcloud_waf_tests.erl | 20 ++-- 46 files changed, 297 insertions(+), 278 deletions(-) diff --git a/Makefile b/Makefile index 4b9564b9e..762bd071a 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ ifeq ($(REBAR_VSN),2) @$(REBAR) compile @$(REBAR) eunit skip_deps=true else - @$(REBAR) eunit + @$(REBAR) do eunit, cover endif check: diff --git a/rebar.config b/rebar.config index dab8bea58..c35dba02d 100644 --- a/rebar.config +++ b/rebar.config @@ -3,6 +3,7 @@ {erl_opts, [debug_info, {platform_define, "^19.|^2", 'ERLANG_OTP_VERSION_19'}, + {platform_define, "^22.|^2", 'ERLANG_OTP_VERSION_22'}, strict_validation, warn_bif_clash, warn_deprecated_function, @@ -17,9 +18,9 @@ warn_unused_vars]}. {deps, [ - {jsx, "2.10.0"}, - {eini, "1.2.7"}, - {base16, "1.0.0"} + {jsx, "3.1.0"}, + {eini, "1.2.9"}, + {base16, "2.0.0"} ]}. {overrides, @@ -31,6 +32,9 @@ {profiles, [ - {test, [{deps, [{meck, "0.9.1"}]}]} + {test, [{deps, [{meck, "0.9.2"}]}]} ,{warnings, [{erl_opts, [warnings_as_errors]}]} ]}. + +{cover_enabled, true}. +{cover_opts, [verbose]}. diff --git a/rebar.lock b/rebar.lock index dcb5db2be..a03846dfa 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,14 +1,14 @@ {"1.2.0", -[{<<"base16">>,{pkg,<<"base16">>,<<"1.0.0">>},0}, - {<<"eini">>,{pkg,<<"eini">>,<<"1.2.7">>},0}, - {<<"jsx">>,{pkg,<<"jsx">>,<<"2.10.0">>},0}]}. +[{<<"base16">>,{pkg,<<"base16">>,<<"2.0.0">>},0}, + {<<"eini">>,{pkg,<<"eini">>,<<"1.2.9">>},0}, + {<<"jsx">>,{pkg,<<"jsx">>,<<"3.1.0">>},0}]}. [ {pkg_hash,[ - {<<"base16">>, <<"283644E2B21BD5915ACB7178BED7851FB07C6E5749B8FAD68A53C501092176D9">>}, - {<<"eini">>, <<"EFC9D836E88591A47550BD34CE964E21CA1369F8716B24F73CFEA513FA99F666">>}, - {<<"jsx">>, <<"77760560D6AC2B8C51FD4C980E9E19B784016AA70BE354CE746472C33BEB0B1C">>}]}, + {<<"base16">>, <<"9DA694FA0778DF31522A1B9EB349BA4AC9063B497234DC49509C1F5C37F336A2">>}, + {<<"eini">>, <<"FCC3CBD49BBDD9A1D9735C7365DAFFCD84481CCE81E6CB80537883AA44AC4895">>}, + {<<"jsx">>, <<"D12516BAA0BB23A59BB35DCCAF02A1BD08243FCBB9EFE24F2D9D056CCFF71268">>}]}, {pkg_hash_ext,[ - {<<"base16">>, <<"02AFD0827E61A7B07093873E063575CA3A2B07520567C7F8CEC7C5D42F052D76">>}, - {<<"eini">>, <<"CD604597DCDB8AD76CCBAAF8C303EF94136729BA4AD6ABC88A4AB800E6D8E99A">>}, - {<<"jsx">>, <<"9A83E3704807298016968DB506F9FAD0F027DE37546EB838B3AE1064C3A0AD62">>}]} + {<<"base16">>, <<"63067A9F73D2422F15344A1EAF7033C3B339DC64DA0229DE3DF26F0F6F1E4F82">>}, + {<<"eini">>, <<"DA64AE8DB7C2F502E6F20CDF44CD3D9BE364412B87FF49FEBF282540F673DFCB">>}, + {<<"jsx">>, <<"0C5CC8FDC11B53CC25CF65AC6705AD39E54ECC56D1C22E4ADB8F5A53FB9427F3">>}]} ]. diff --git a/src/erlcloud_athena.erl b/src/erlcloud_athena.erl index c04e081be..4ee62570e 100644 --- a/src/erlcloud_athena.erl +++ b/src/erlcloud_athena.erl @@ -403,7 +403,7 @@ request(Config, Request) -> Result = erlcloud_retry:request(Config, Request, fun handle_result/1), case erlcloud_aws:request_to_return(Result) of {ok, {_, <<>>}} -> {ok, #{}}; - {ok, {_, RespBody}} -> {ok, jsx:decode(RespBody, [return_maps])}; + {ok, {_, RespBody}} -> {ok, jsx:decode(RespBody)}; {error, _} = Error -> Error end. diff --git a/src/erlcloud_aws.erl b/src/erlcloud_aws.erl index 8897c6c68..e5b93b83e 100644 --- a/src/erlcloud_aws.erl +++ b/src/erlcloud_aws.erl @@ -831,7 +831,7 @@ region(Config) -> {error, Reason} -> {error, Reason}; {ok, Json} -> - Doc = jsx:decode(Json), + Doc = jsx:decode(Json, [{return_maps, false}]), {ok, prop_to_list_defined(<<"region">>, Doc)} end. @@ -850,7 +850,7 @@ get_credentials_from_metadata(Config) -> {error, Reason} -> {error, Reason}; {ok, Json} -> - Creds = jsx:decode(Json), + Creds = jsx:decode(Json, [{return_maps, false}]), get_credentials_from_metadata_xform( Creds ) end end. @@ -863,7 +863,7 @@ get_credentials_from_task_metadata(Config) -> {error, Reason} -> {error, Reason}; {ok, Json} -> - Creds = jsx:decode(Json), + Creds = jsx:decode(Json, [{return_maps, false}]), get_credentials_from_metadata_xform( Creds ) end. @@ -1114,7 +1114,7 @@ get_service_status(ServiceNames) when is_list(ServiceNames) -> "/data.json", "", [], default_config()), case get_filtered_statuses(ServiceNames, - proplists:get_value(<<"current">>, jsx:decode(Json))) + proplists:get_value(<<"current">>, jsx:decode(Json, [{return_maps, false}]))) of [] -> ok; ReturnStatuses -> ReturnStatuses diff --git a/src/erlcloud_cloudsearch.erl b/src/erlcloud_cloudsearch.erl index 9ed597885..a01b8aba9 100644 --- a/src/erlcloud_cloudsearch.erl +++ b/src/erlcloud_cloudsearch.erl @@ -721,7 +721,7 @@ cloudsearch_query(Config, Action, Params, ApiVersion) -> [{"Accept", "application/json"}], Config) of {ok, Response} -> - {ok, jsx:decode(Response)}; + {ok, jsx:decode(Response, [{return_maps, false}])}; {error, Reason} -> {error, Reason} end. @@ -736,7 +736,7 @@ cloudsearch_post_json(Host, Path, Body, [{"content-type", "application/json"} | Headers], Config) of {ok, RespBody} -> - {ok, jsx:decode(RespBody)}; + {ok, jsx:decode(RespBody, [{return_maps, false}])}; {error, Reason} -> {error, Reason} end. diff --git a/src/erlcloud_cloudtrail.erl b/src/erlcloud_cloudtrail.erl index 6f4327b7a..a9b40b940 100644 --- a/src/erlcloud_cloudtrail.erl +++ b/src/erlcloud_cloudtrail.erl @@ -52,14 +52,14 @@ configure(AccessKeyID, SecretAccessKey, Host) -> %% -spec create_trail(string(), string(), aws_config()) -> ct_return(). create_trail(Trail, S3BucketName, Config) -> - Json = [{<<"Name">>, list_to_binary(Trail)}, + Json = [{<<"Name">>, list_to_binary(Trail)}, {<<"S3BucketName">>, list_to_binary(S3BucketName)} ], ct_request("CreateTrail", Json, Config). -spec create_trail(string(), string(), string(), aws_config()) -> ct_return(). create_trail(Trail, S3BucketName, SnsTopicName, Config) -> - Json = [{<<"Name">>, list_to_binary(Trail)}, + Json = [{<<"Name">>, list_to_binary(Trail)}, {<<"S3BucketName">>, list_to_binary(S3BucketName)}, {<<"SnsTopicName">>, list_to_binary(SnsTopicName)} ], @@ -67,7 +67,7 @@ create_trail(Trail, S3BucketName, SnsTopicName, Config) -> -spec create_trail(string(), string(), string(), boolean(), aws_config()) -> ct_return(). create_trail(Trail, S3BucketName, SnsTopicName, IncludeGlobalServiceEvents, Config) -> - Json = [{<<"Name">>, list_to_binary(Trail)}, + Json = [{<<"Name">>, list_to_binary(Trail)}, {<<"S3BucketName">>, list_to_binary(S3BucketName)}, {<<"SnsTopicName">>, list_to_binary(SnsTopicName)}, {<<"IncludeGlobalServiceEvents">>, list_to_binary(atom_to_list(IncludeGlobalServiceEvents))} @@ -76,7 +76,7 @@ create_trail(Trail, S3BucketName, SnsTopicName, IncludeGlobalServiceEvents, Conf -spec create_trail(string(), string(), string(), string(), boolean(), aws_config()) -> ct_return(). create_trail(Trail, S3BucketName, S3KeyPrefix, SnsTopicName, IncludeGlobalServiceEvents, Config) -> - Json = [{<<"Name">>, list_to_binary(Trail)}, + Json = [{<<"Name">>, list_to_binary(Trail)}, {<<"S3BucketName">>, list_to_binary(S3BucketName)}, {<<"S3KeyPrefix">>, list_to_binary(S3KeyPrefix)}, {<<"SnsTopicName">>, list_to_binary(SnsTopicName)}, @@ -156,7 +156,7 @@ stop_logging(Trail, Config) -> -spec update_trail(string(), string(), string(), aws_config()) -> ct_return(). update_trail(Trail, S3BucketName, SnsTopicName, Config) -> - Json = [{<<"Name">>, list_to_binary(Trail)}, + Json = [{<<"Name">>, list_to_binary(Trail)}, {<<"S3BucketName">>, list_to_binary(S3BucketName)}, {<<"SnsTopicName">>, list_to_binary(SnsTopicName)} ], @@ -164,7 +164,7 @@ update_trail(Trail, S3BucketName, SnsTopicName, Config) -> -spec update_trail(string(), string(), string(), boolean(), aws_config()) -> ct_return(). update_trail(Trail, S3BucketName, SnsTopicName, IncludeGlobalServiceEvents, Config) -> - Json = [{<<"Name">>, list_to_binary(Trail)}, + Json = [{<<"Name">>, list_to_binary(Trail)}, {<<"S3BucketName">>, list_to_binary(S3BucketName)}, {<<"SnsTopicName">>, list_to_binary(SnsTopicName)}, {<<"IncludeGlobalServiceEvents">>, list_to_binary(atom_to_list(IncludeGlobalServiceEvents))} @@ -174,7 +174,7 @@ update_trail(Trail, S3BucketName, SnsTopicName, IncludeGlobalServiceEvents, Conf -spec update_trail(string(), string(), string(), string(), boolean(), aws_config()) -> ct_return(). update_trail(Trail, S3BucketName, S3KeyPrefix, SnsTopicName, IncludeGlobalServiceEvents, Config) -> - Json = [{<<"Name">>, list_to_binary(Trail)}, + Json = [{<<"Name">>, list_to_binary(Trail)}, {<<"S3BucketName">>, list_to_binary(S3BucketName)}, {<<"S3KeyPrefix">>, list_to_binary(S3KeyPrefix)}, {<<"SnsTopicName">>, list_to_binary(SnsTopicName)}, @@ -184,28 +184,28 @@ update_trail(Trail, S3BucketName, S3KeyPrefix, SnsTopicName, IncludeGlobalServic % Json parameter must be a list of binary key/value tuples. ct_request(Operation, [], Config) -> - #aws_config{cloudtrail_scheme = Scheme, + #aws_config{cloudtrail_scheme = Scheme, cloudtrail_host = Host} = Config, request_impl(post, Scheme, Host, port_spec(Config), "/", Operation, [], "{}", Config); ct_request(Operation, Body, Config) -> - #aws_config{cloudtrail_scheme = Scheme, + #aws_config{cloudtrail_scheme = Scheme, cloudtrail_host = Host} = Config, request_impl(post, Scheme, Host, port_spec(Config), "/", Operation, [], jsx:encode(Body), Config). - + request_impl(Method, Scheme, Host, Port, Path, Operation, Params, Body, #aws_config{} = Config) -> %% TODO: Make api prefix a part of aws_config Api_Operation = lists:flatten(?CLOUD_TRAIL_API_PREFIX, Operation), Headers = headers(Config, Api_Operation, Params, Body, ?SERVICE_NAME), - + case erlcloud_aws:aws_request_form_raw( - Method, Scheme, Host, Port, Path, Body, - [{"content-type", "application/x-amz-json-1.1"} | Headers], + Method, Scheme, Host, Port, Path, Body, + [{"content-type", "application/x-amz-json-1.1"} | Headers], Config) of {ok, RespBody} -> case Config#aws_config.cloudtrail_raw_result of true -> {ok, RespBody}; - _ -> {ok, jsx:decode(RespBody)} + _ -> {ok, jsx:decode(RespBody, [{return_maps, false}])} end; {error, Reason} -> {error, Reason} diff --git a/src/erlcloud_cloudwatch_logs.erl b/src/erlcloud_cloudwatch_logs.erl index c8a03d1b3..3cf4c391c 100644 --- a/src/erlcloud_cloudwatch_logs.erl +++ b/src/erlcloud_cloudwatch_logs.erl @@ -534,7 +534,7 @@ maybe_cw_request({error, _} = Error, _Action, _Params) -> maybe_json({ok, <<>>}) -> {ok, []}; maybe_json({ok, Response}) -> - {ok, jsx:decode(Response)}; + {ok, jsx:decode(Response, [{return_maps, false}])}; maybe_json({error, _} = Error) -> Error. diff --git a/src/erlcloud_config.erl b/src/erlcloud_config.erl index 887aa3adc..43fb88369 100644 --- a/src/erlcloud_config.erl +++ b/src/erlcloud_config.erl @@ -367,7 +367,7 @@ request(Config, Request) -> Result = erlcloud_retry:request(Config, Request, fun handle_result/1), case erlcloud_aws:request_to_return(Result) of {ok, {_, <<>>}} -> {ok, #{}}; - {ok, {_, RespBody}} -> {ok, jsx:decode(RespBody, [return_maps])}; + {ok, {_, RespBody}} -> {ok, jsx:decode(RespBody)}; {error, _} = Error -> Error end. diff --git a/src/erlcloud_cur.erl b/src/erlcloud_cur.erl index 2a3cca7f3..587736c26 100644 --- a/src/erlcloud_cur.erl +++ b/src/erlcloud_cur.erl @@ -102,7 +102,7 @@ request(Config, Request) -> case erlcloud_aws:request_to_return(Result) of {ok, {_, <<>>}} -> {ok, #{}}; {ok, {_, RespBody}} -> - {ok, jsx:decode(RespBody, [return_maps])}; + {ok, jsx:decode(RespBody)}; {error, _} = Error -> Error end. @@ -130,4 +130,4 @@ get_url(#aws_config{cur_scheme = Scheme, Scheme ++ Host ++ ":" ++ integer_to_list(Port). make_amz_target(Operation) -> - "AWSOrigamiServiceGatewayService." ++ binary_to_list(Operation). \ No newline at end of file + "AWSOrigamiServiceGatewayService." ++ binary_to_list(Operation). diff --git a/src/erlcloud_ddb_impl.erl b/src/erlcloud_ddb_impl.erl index 7ba4c03f1..de360b45b 100644 --- a/src/erlcloud_ddb_impl.erl +++ b/src/erlcloud_ddb_impl.erl @@ -193,7 +193,7 @@ request_and_retry(Config, Headers, Body, {attempt, Attempt}) -> {ok, {{200, _}, _, RespBody}} -> %% TODO check crc - {ok, jsx:decode(RespBody)}; + {ok, jsx:decode(RespBody, [{return_maps, false}])}; Error -> DDBError = #ddb2_error{attempt = Attempt, @@ -230,7 +230,7 @@ client_error(Body, DDBError) -> false -> DDBError#ddb2_error{error_type = http, should_retry = false}; true -> - Json = jsx:decode(Body), + Json = jsx:decode(Body, [{return_maps, false}]), case proplists:get_value(<<"__type">>, Json) of undefined -> DDBError#ddb2_error{error_type = http, should_retry = false}; diff --git a/src/erlcloud_ddb_streams.erl b/src/erlcloud_ddb_streams.erl index aa17fc371..e8c640d86 100644 --- a/src/erlcloud_ddb_streams.erl +++ b/src/erlcloud_ddb_streams.erl @@ -824,7 +824,7 @@ request2(Config, Operation, Json) -> request_to_return(#aws_request{response_type = ok, response_body = Body}) -> %% TODO check crc - {ok, jsx:decode(Body)}; + {ok, jsx:decode(Body, [{return_maps, false}])}; request_to_return(#aws_request{response_type = error, error_type = aws, httpc_error_reason = undefined, @@ -868,7 +868,7 @@ client_error(#aws_request{response_body = Body} = Request) -> false -> Request#aws_request{should_retry = false}; true -> - Json = jsx:decode(Body), + Json = jsx:decode(Body, [{return_maps, false}]), case proplists:get_value(<<"__type">>, Json) of undefined -> Request#aws_request{should_retry = false}; diff --git a/src/erlcloud_directconnect.erl b/src/erlcloud_directconnect.erl index eb3beaf8f..149df41e1 100644 --- a/src/erlcloud_directconnect.erl +++ b/src/erlcloud_directconnect.erl @@ -416,7 +416,7 @@ dc_query(Operation, Params, Config) -> [{<<"content-type">>, <<"application/x-amz-json-1.1">>} | Headers], Body, 1000, Config)) of {ok, {_RespHeader, RespBody}} -> - {ok, jsx:decode(RespBody)}; + {ok, jsx:decode(RespBody, [{return_maps, false}])}; {error, Reason} -> {error, Reason} end. diff --git a/src/erlcloud_ecs.erl b/src/erlcloud_ecs.erl index f8b048234..a46dbf798 100644 --- a/src/erlcloud_ecs.erl +++ b/src/erlcloud_ecs.erl @@ -2466,7 +2466,7 @@ ecs_request_no_update(Config, Operation, Body) -> request_body = Payload}, case erlcloud_aws:request_to_return(erlcloud_retry:request(Config, Request, fun ecs_result_fun/1)) of {ok, {_RespHeaders, <<>>}} -> {ok, []}; - {ok, {_RespHeaders, RespBody}} -> {ok, jsx:decode(RespBody)}; + {ok, {_RespHeaders, RespBody}} -> {ok, jsx:decode(RespBody, [{return_maps, false}])}; {error, _} = Error-> Error end. diff --git a/src/erlcloud_emr.erl b/src/erlcloud_emr.erl index f874e714a..936d8ffbe 100644 --- a/src/erlcloud_emr.erl +++ b/src/erlcloud_emr.erl @@ -207,11 +207,11 @@ request_no_update(Action, Json, Scheme, Host, Port, Service, Opts, Cfg) -> raw -> {ok, Body}; _ -> case Body of <<>> -> {ok, <<>>}; - _ -> {ok, jsx:decode(Body)} + _ -> {ok, jsx:decode(Body, [{return_maps, false}])} end end; {error, {http_error, _Code, _StatusLine, ErrBody}} -> - {error, {aws_error, jsx:decode(ErrBody)}}; + {error, {aws_error, jsx:decode(ErrBody, [{return_maps, false}])}}; {error, {socket_error, Reason}} -> {error, {socket_error, Reason}} end. diff --git a/src/erlcloud_glue.erl b/src/erlcloud_glue.erl index 1551bfa80..d22c50cc6 100644 --- a/src/erlcloud_glue.erl +++ b/src/erlcloud_glue.erl @@ -826,7 +826,7 @@ request(Config, Request) -> Result = erlcloud_retry:request(Config, Request, fun handle_result/1), case erlcloud_aws:request_to_return(Result) of {ok, {_, <<>>}} -> {ok, #{}}; - {ok, {_, RespBody}} -> {ok, jsx:decode(RespBody, [return_maps])}; + {ok, {_, RespBody}} -> {ok, jsx:decode(RespBody)}; {error, _} = Error -> Error end. diff --git a/src/erlcloud_guardduty.erl b/src/erlcloud_guardduty.erl index 6da2a4026..58a1b0b05 100644 --- a/src/erlcloud_guardduty.erl +++ b/src/erlcloud_guardduty.erl @@ -113,7 +113,7 @@ guardduty_request_no_update(Config, Method, Path, QParam) -> Method, Config#aws_config.guardduty_scheme, Config#aws_config.guardduty_host, Config#aws_config.guardduty_port, Path, <<>>, Headers, Config) of {ok, Data} -> - {ok, jsx:decode(Data)}; + {ok, jsx:decode(Data, [{return_maps, false}])}; E -> E end. diff --git a/src/erlcloud_iam.erl b/src/erlcloud_iam.erl index 25289d073..c16ab0421 100644 --- a/src/erlcloud_iam.erl +++ b/src/erlcloud_iam.erl @@ -5,7 +5,6 @@ -include("erlcloud.hrl"). -include("erlcloud_aws.hrl"). -include("erlcloud_iam.hrl"). --include_lib("xmerl/include/xmerl.hrl"). %% Library initialization. -export([configure/2, configure/3, new/2, new/3, iam_query/5]). @@ -1054,8 +1053,15 @@ data_fun("Integer") -> {erlcloud_xml, get_integer}; data_fun("Boolean") -> {erlcloud_xml, get_bool}; data_fun("Uri") -> {?MODULE, get_uri}. +-ifdef(ERLANG_OTP_VERSION_22). get_uri(Key, Item) -> http_uri:decode(erlcloud_xml:get_text(Key, Item)). +-else. +get_uri(Key, Item) -> + uri_string:percent_decode( + uri_string:normalize( + erlcloud_xml:get_text(Key, Item))). +-endif. make_list_virtual_mfa_devices_params(undefined, undefined, undefined) -> []; diff --git a/src/erlcloud_inspector.erl b/src/erlcloud_inspector.erl index abd47e9b2..956d8e983 100644 --- a/src/erlcloud_inspector.erl +++ b/src/erlcloud_inspector.erl @@ -1109,7 +1109,7 @@ inspector_request_no_update(Config, Operation, Body) -> request_body = Payload}, case erlcloud_aws:request_to_return(erlcloud_retry:request(Config, Request, fun inspector_result_fun/1)) of {ok, {_RespHeaders, <<>>}} -> {ok, []}; - {ok, {_RespHeaders, RespBody}} -> {ok, jsx:decode(RespBody)}; + {ok, {_RespHeaders, RespBody}} -> {ok, jsx:decode(RespBody, [{return_maps, false}])}; {error, _} = Error-> Error end. diff --git a/src/erlcloud_kinesis_impl.erl b/src/erlcloud_kinesis_impl.erl index 9cdd2fcd8..e9af4bd1c 100644 --- a/src/erlcloud_kinesis_impl.erl +++ b/src/erlcloud_kinesis_impl.erl @@ -141,7 +141,7 @@ request_and_retry(Config, Headers, Body, ShouldDecode, {attempt, Attempt}) -> -spec client_error(pos_integer(), string(), binary()) -> {retry, term()} | {error, term()}. client_error(Status, StatusLine, Body) -> - try jsx:decode(Body) of + try jsx:decode(Body, [{return_maps, false}]) of Json -> Message = proplists:get_value(<<"message">>, Json, <<>>), case proplists:get_value(<<"__type">>, Json) of @@ -176,4 +176,4 @@ port_spec(#aws_config{kinesis_port=Port}) -> [":", erlang:integer_to_list(Port)]. decode(<<>>) -> []; -decode(JSON) -> jsx:decode(JSON). +decode(JSON) -> jsx:decode(JSON, [{return_maps, false}]). diff --git a/src/erlcloud_kms.erl b/src/erlcloud_kms.erl index a3141b932..6523b45bb 100644 --- a/src/erlcloud_kms.erl +++ b/src/erlcloud_kms.erl @@ -1011,7 +1011,7 @@ kms_request_no_update(Config, Operation, Body) -> request_body = Payload}, case erlcloud_aws:request_to_return(erlcloud_retry:request(Config, Request, fun kms_result_fun/1)) of {ok, {_RespHeaders, <<>>}} -> {ok, []}; - {ok, {_RespHeaders, RespBody}} -> {ok, jsx:decode(RespBody)}; + {ok, {_RespHeaders, RespBody}} -> {ok, jsx:decode(RespBody, [{return_maps, false}])}; {error, _} = Error-> Error end. diff --git a/src/erlcloud_lambda.erl b/src/erlcloud_lambda.erl index 0a76fd943..ec7d1cdf7 100644 --- a/src/erlcloud_lambda.erl +++ b/src/erlcloud_lambda.erl @@ -760,7 +760,7 @@ decode_body(Body, true) -> decode_body(<<>>, _RawBody) -> []; decode_body(BinData, _RawBody) -> - jsx:decode(BinData). + jsx:decode(BinData, [{return_maps, false}]). encode_body(Bin) when is_binary(Bin) -> Bin; diff --git a/src/erlcloud_mes.erl b/src/erlcloud_mes.erl index f9d031d1e..a2e8fe4b8 100644 --- a/src/erlcloud_mes.erl +++ b/src/erlcloud_mes.erl @@ -171,7 +171,7 @@ mes_request_no_update(#aws_config{mes_scheme = Scheme, mes_host = Host, mes_port Headers = headers(Config, Operation, Body), case erlcloud_aws:aws_request_form_raw(post, Scheme, Host, Port, "/", Body, Headers, Config) of {ok, Response} -> - {ok, jsx:decode(Response)}; + {ok, jsx:decode(Response, [{return_maps, false}])}; {error, Reason} -> {error, Reason} end. diff --git a/src/erlcloud_mms.erl b/src/erlcloud_mms.erl index 9b087b29f..adc937baf 100644 --- a/src/erlcloud_mms.erl +++ b/src/erlcloud_mms.erl @@ -170,7 +170,7 @@ mms_request_no_update(#aws_config{mms_scheme = Scheme, mms_host = Host, mms_port Headers = headers(Config, Operation, Body), case erlcloud_aws:aws_request_form_raw(post, Scheme, Host, Port, "/", Body, Headers, Config) of {ok, Response} -> - {ok, jsx:decode(Response)}; + {ok, jsx:decode(Response, [{return_maps, false}])}; {error, Reason} -> {error, Reason} end. diff --git a/src/erlcloud_s3.erl b/src/erlcloud_s3.erl index 8a18c876a..9b5da7d06 100755 --- a/src/erlcloud_s3.erl +++ b/src/erlcloud_s3.erl @@ -1636,13 +1636,9 @@ create_notification_param_xml({cloud_function, CF}, Acc) -> [{'CloudFunction', [ -spec get_bucket_and_key(string()) -> {string(), string()}. get_bucket_and_key(Uri) -> - {ok, Parsed} = http_uri:parse(Uri), - {Host, Path} = extract_host_and_path(Parsed), + #{host := Host, path := Path} = uri_string:parse(Uri), extract_location_fields(Host, Path). -extract_host_and_path({_Scheme, _UserInfo, Host, _Port, Path, _Query}) -> - {Host, Path}. - extract_location_fields(Host, Path) -> HostTokens = string:tokens(Host, "."), extract_bucket_and_key(HostTokens, Path). diff --git a/src/erlcloud_sns.erl b/src/erlcloud_sns.erl index 1a6f27211..4c7040ccc 100644 --- a/src/erlcloud_sns.erl +++ b/src/erlcloud_sns.erl @@ -526,7 +526,7 @@ publish(Type, RecipientArn, Message, Subject, Attributes, Config) -> -spec parse_event(iodata()) -> sns_event(). parse_event(EventSource) -> - jsx:decode(EventSource). + jsx:decode(EventSource, [{return_maps, false}]). -spec get_event_type(sns_event()) -> sns_event_type(). get_event_type(Event) -> @@ -540,7 +540,7 @@ parse_event_message(Event) -> Message = proplists:get_value(<<"Message">>, Event, <<>>), case get_event_type(Event) of subscription_confirmation -> Message; - notification -> jsx:decode(Message) + notification -> jsx:decode(Message, [{return_maps, false}]) end. -spec get_notification_attribute(binary(), sns_notification()) -> sns_application_attribute() | binary(). diff --git a/src/erlcloud_states.erl b/src/erlcloud_states.erl index a321067fb..314756ecc 100644 --- a/src/erlcloud_states.erl +++ b/src/erlcloud_states.erl @@ -651,7 +651,7 @@ request(Config, Request) -> {ok, {_, <<"{}">>}} -> ok; {ok, {_, RespBody}} -> - {ok, jsx:decode(RespBody, [return_maps])}; + {ok, jsx:decode(RespBody)}; {error, _} = Error -> Error end. diff --git a/src/erlcloud_util.erl b/src/erlcloud_util.erl index 9d08c7f6c..5c5b466ee 100644 --- a/src/erlcloud_util.erl +++ b/src/erlcloud_util.erl @@ -8,11 +8,11 @@ -define(MAX_ITEMS, 1000). sha_mac(K, S) -> - crypto:hmac(sha, K, S). + crypto:mac(hmac, sha, K, S). sha256_mac(K, S) -> - crypto:hmac(sha256, K, S). + crypto:mac(hmac, sha256, K, S). sha256(V) -> crypto:hash(sha256, V). diff --git a/src/erlcloud_waf.erl b/src/erlcloud_waf.erl index a52e1cb07..cd5c25094 100644 --- a/src/erlcloud_waf.erl +++ b/src/erlcloud_waf.erl @@ -1186,7 +1186,7 @@ waf_request_no_update(Config, Operation, Body) -> request_body = Payload}, case erlcloud_aws:request_to_return(erlcloud_retry:request(Config, Request, fun waf_result_fun/1)) of {ok, {_RespHeaders, <<>>}} -> {ok, []}; - {ok, {_RespHeaders, RespBody}} -> {ok, jsx:decode(RespBody)}; + {ok, {_RespHeaders, RespBody}} -> {ok, jsx:decode(RespBody, [{return_maps, false}])}; {error, _} = Error-> Error end. diff --git a/test/erlcloud_aws_tests.erl b/test/erlcloud_aws_tests.erl index 59668263c..b0f461ff1 100644 --- a/test/erlcloud_aws_tests.erl +++ b/test/erlcloud_aws_tests.erl @@ -1,6 +1,5 @@ -module(erlcloud_aws_tests). -include_lib("eunit/include/eunit.hrl"). --include("erlcloud.hrl"). -include("erlcloud_aws.hrl"). request_test_() -> @@ -31,7 +30,7 @@ config() -> request_default_test(_) -> ok = erlcloud_aws:aws_request(get, "host", "/", [], "id", "key"), Url = get_url_from_history(meck:history(erlcloud_httpc)), - test_url(https, "host", 443, "/", Url). + test_url("https", "host", 443, "/", Url). request_retry_test(_) -> Response400 = {ok, {{400, "Bad Request"}, [], @@ -79,12 +78,12 @@ request_retry_test(_) -> request_prot_host_port_str_test(_) -> ok = erlcloud_aws:aws_request(get, "http", "host1", "9999", "/path1", [], "id", "key"), Url = get_url_from_history(meck:history(erlcloud_httpc)), - test_url(http, "host1", 9999, "/path1", Url). + test_url("http", "host1", 9999, "/path1", Url). request_prot_host_port_int_test(_) -> ok = erlcloud_aws:aws_request(get, "http", "host1", 9999, "/path1", [], "id", "key"), Url = get_url_from_history(meck:history(erlcloud_httpc)), - test_url(http, "host1", 9999, "/path1", Url). + test_url("http", "host1", 9999, "/path1", Url). get_service_status_test(_) -> StatusJsonS3 = jsx:encode( @@ -147,7 +146,7 @@ get_service_status_test(_) -> OKStatusEmpty = erlcloud_aws:get_service_status(["sqs", "sns"]), meck:expect(erlcloud_httpc, request, fun(_,_,_,_,_,_) -> {ok, {{200, "OK"}, [], StatusJsonS3}} end), OKStatus = erlcloud_aws:get_service_status(["cloudformation", "sns", "vpc"]), - + [?_assertEqual(proplists:get_value(<<"status">>, S3Status), 0), ?_assertEqual(proplists:get_value(<<"service">>, S3Status), <<"s3-eu-central-1">>), ?_assertEqual(proplists:get_value(<<"status">>, EC2Status), 2), @@ -189,12 +188,11 @@ get_url_from_history([{_, {erlcloud_httpc, request, [Url, _, _, _, _, _]}, _}]) Url. test_url(ExpScheme, ExpHost, ExpPort, ExpPath, Url) -> - {ok, {Scheme, _UserInfo, Host, Port, Path, _Query}} = http_uri:parse(Url), - [?_assertEqual(ExpScheme, Scheme), - ?_assertEqual(ExpHost, Host), - ?_assertEqual(ExpPort, Port), - ?_assertEqual(ExpPath, Path)]. - + Result = uri_string:parse(Url), + [?_assertEqual(ExpScheme, maps:get(scheme, Result, undefined)), + ?_assertEqual(ExpHost, maps:get(host, Result, undefined)), + ?_assertEqual(ExpPort, maps:get(port, Result, 443)), + ?_assertEqual(ExpPath, maps:get(path, Result, undefined))]. -define(DEFAULT_ACCESS_ID, "XXXXXXXXXXXXXXXXXXX2"). -define(DEFAULT_ACCESS_KEY, "yyyyyyyyyyyyyyyyyyyyyyyyyy+yyyy/yyyyyyyy2"). @@ -237,7 +235,7 @@ profile_indirect_test_() -> erlcloud_aws:profile( blah ) ) ) }. - + profile_indirect_role_test_() -> {setup, fun profiles_assume_setup/0, fun profiles_assume_cleanup/1, ?_test( @@ -309,14 +307,14 @@ profile_undefined_profile_test_() -> ?assertMatch( {error, _}, erlcloud_aws:profile( what ) ) ) }. - + profile_undefined_indirect_profile_test_() -> {setup, fun profiles_test_setup/0, fun profiles_test_cleanup/1, ?_test( ?assertMatch( {error, _}, erlcloud_aws:profile( whoa ) ) ) }. - + profiles_test_setup() -> Profile = <<" diff --git a/test/erlcloud_cloudtrail_tests.erl b/test/erlcloud_cloudtrail_tests.erl index bf5284377..258a9e35c 100644 --- a/test/erlcloud_cloudtrail_tests.erl +++ b/test/erlcloud_cloudtrail_tests.erl @@ -5,7 +5,7 @@ -include("erlcloud_aws.hrl"). %% Unit tests for cloudtrail. -%% These tests work by using meck to mock erlcloud_httpc. +%% These tests work by using meck to mock erlcloud_httpc. %% There are two classes of test: input and output. %% %% Input tests verify that different function args produce the desired JSON request. @@ -71,8 +71,8 @@ sort_json(V) -> %% verifies that the parameters in the body match the expected parameters -spec validate_body(binary(), expected_body()) -> ok. validate_body(Body, Expected) -> - Want = sort_json(jsx:decode(list_to_binary(Expected))), - Actual = sort_json(jsx:decode(Body)), + Want = sort_json(jsx:decode(list_to_binary(Expected), [{return_maps, false}])), + Actual = sort_json(jsx:decode(Body, [{return_maps, false}])), case Want =:= Actual of true -> ok; false -> @@ -103,7 +103,7 @@ input_test(Response, {Line, {Description, Fun, Expected}}) when secret_access_key=string:copies("a", 40) }, put(aws_config, AwsConfig), - + Fun() end}}. @@ -160,7 +160,7 @@ output_tests(Fun, Tests) -> %% CreateTrail test based on the API examples: %% http://docs.aws.amazon.com/awscloudtrail/latest/APIReference/API_CreateTrail.html create_trail_input_tests(_) -> - Tests = + Tests = [?_cloudtrail_test( {"CreateTrail example request", ?_f(erlcloud_cloudtrail:create_trail("test", "test_bucket", "test_prefix", "test_topic", true, erlcloud_aws:default_config())), " @@ -186,10 +186,10 @@ create_trail_output_tests(_) -> \"SnsTopicName\": \"test_topic\", \"IncludeGlobalServiceEvents\": \"true\" }">>, - Tests = + Tests = [?_cloudtrail_test( {"CreateTrail example response", Response, - {ok, jsx:decode(Response)}}) + {ok, jsx:decode(Response, [{return_maps, false}])}}) ], output_tests(?_f(erlcloud_cloudtrail:create_trail("test", "test_bucket", "test_prefix", "test_topic", true, erlcloud_aws:default_config())), Tests). @@ -197,7 +197,7 @@ create_trail_output_tests(_) -> %% DeleteTrail test based on the API examples: %% http://docs.aws.amazon.com/awscloudtrail/latest/APIReference/API_DeleteTrail.html delete_trail_input_tests(_) -> - Tests = + Tests = [?_cloudtrail_test( {"DeleteTrail example request", ?_f(erlcloud_cloudtrail:delete_trail("test", erlcloud_aws:default_config())), " @@ -213,17 +213,17 @@ delete_trail_input_tests(_) -> delete_trail_output_tests(_) -> Response = <<"{}">>, - Tests = + Tests = [?_cloudtrail_test( {"DeleteTrail example response", Response, - {ok, jsx:decode(Response)}}) + {ok, jsx:decode(Response, [{return_maps, false}])}}) ], output_tests(?_f(erlcloud_cloudtrail:delete_trail("test", erlcloud_aws:default_config())), Tests). %% StartLogging test based on the API examples: %% http://docs.aws.amazon.com/awscloudtrail/latest/APIReference/API_StartLogging.html start_logging_input_tests(_) -> - Tests = + Tests = [?_cloudtrail_test( {"StartLogging example request", ?_f(erlcloud_cloudtrail:start_logging("test", erlcloud_aws:default_config())), " @@ -239,17 +239,17 @@ start_logging_input_tests(_) -> start_logging_output_tests(_) -> Response = <<"{}">>, - Tests = + Tests = [?_cloudtrail_test( {"StartLogging example response", Response, - {ok, jsx:decode(Response)}}) + {ok, jsx:decode(Response, [{return_maps, false}])}}) ], output_tests(?_f(erlcloud_cloudtrail:start_logging("test", erlcloud_aws:default_config())), Tests). %% StopLogging test based on the API examples: %% http://docs.aws.amazon.com/awscloudtrail/latest/APIReference/API_StopLogging.html stop_logging_input_tests(_) -> - Tests = + Tests = [?_cloudtrail_test( {"StopLogging example request", ?_f(erlcloud_cloudtrail:stop_logging("test", erlcloud_aws:default_config())), " @@ -265,17 +265,17 @@ stop_logging_input_tests(_) -> stop_logging_output_tests(_) -> Response = <<"{}">>, - Tests = + Tests = [?_cloudtrail_test( {"StopLogging example response", Response, - {ok, jsx:decode(Response)}}) + {ok, jsx:decode(Response, [{return_maps, false}])}}) ], output_tests(?_f(erlcloud_cloudtrail:stop_logging("test", erlcloud_aws:default_config())), Tests). %% DescribeTrails test based on the API examples: %% http://docs.aws.amazon.com/awscloudtrail/latest/APIReference/API_DescribeTrails.html describe_trails_input_tests(_) -> - Tests = + Tests = [?_cloudtrail_test( {"DescribeTrails example request", ?_f(erlcloud_cloudtrail:describe_trails(["test"], erlcloud_aws:default_config())), " @@ -300,10 +300,10 @@ describe_trails_output_tests(_) -> } ] }">>, - Tests = + Tests = [?_cloudtrail_test( {"DescribeTrails example response", Response, - {ok, jsx:decode(Response)}}) + {ok, jsx:decode(Response, [{return_maps, false}])}}) ], output_tests(?_f(erlcloud_cloudtrail:describe_trails(["test"], erlcloud_aws:default_config())), Tests). @@ -341,14 +341,14 @@ get_event_selectors_output_tests(_) -> Tests = [?_cloudtrail_test( {"GetEventSelectors example response", Response, - {ok, jsx:decode(Response)}}) + {ok, jsx:decode(Response, [{return_maps, false}])}}) ], output_tests(?_f(erlcloud_cloudtrail:get_event_selectors("test", erlcloud_aws:default_config())), Tests). %% GetTrailStatus test based on the API examples: %% http://docs.aws.amazon.com/awscloudtrail/latest/APIReference/API_GetTrailStatus.html get_trail_status_input_tests(_) -> - Tests = + Tests = [?_cloudtrail_test( {"GetTrailStatus example request", ?_f(erlcloud_cloudtrail:get_trail_status("test", erlcloud_aws:default_config())), " @@ -373,17 +373,17 @@ get_trail_status_output_tests(_) -> \"StopLoggingTime\": \"12345\" }">>, - Tests = + Tests = [?_cloudtrail_test( {"GetTrailStatus example response", Response, - {ok, jsx:decode(Response)}}) + {ok, jsx:decode(Response, [{return_maps, false}])}}) ], output_tests(?_f(erlcloud_cloudtrail:get_trail_status("test", erlcloud_aws:default_config())), Tests). %% UpdateTrail test based on the API examples: %% http://docs.aws.amazon.com/awscloudtrail/latest/APIReference/API_UpdateTrail.html update_trail_input_tests(_) -> - Tests = + Tests = [?_cloudtrail_test( {"UpdateTrail example request", ?_f(erlcloud_cloudtrail:update_trail("test", "test_bucket", "test_prefix", "test_topic", true, erlcloud_aws:default_config())), " @@ -409,10 +409,10 @@ update_trail_output_tests(_) -> \"SnsTopicName\": \"test_topic\", \"IncludeGlobalServiceEvents\": \"true\" }">>, - Tests = + Tests = [?_cloudtrail_test( {"UpdateTrail example response", Response, - {ok, jsx:decode(Response)}}) + {ok, jsx:decode(Response, [{return_maps, false}])}}) ], output_tests(?_f(erlcloud_cloudtrail:update_trail("test", "test_bucket", "test_prefix", "test_topic", true, erlcloud_aws:default_config())), Tests). diff --git a/test/erlcloud_cloudwatch_logs_tests.erl b/test/erlcloud_cloudwatch_logs_tests.erl index f017c5ee9..5d18c1140 100644 --- a/test/erlcloud_cloudwatch_logs_tests.erl +++ b/test/erlcloud_cloudwatch_logs_tests.erl @@ -457,7 +457,7 @@ input_test(ResponseBody, {Line, {Description, Fun, ExpectedParams}}) -> erlcloud_httpc, request, fun(_Url, post, _Headers, RequestBody, _Timeout, _Config) -> - ActualParams = jsx:decode(RequestBody), + ActualParams = jsx:decode(RequestBody, [{return_maps, false}]), ?assertEqual(sort_json(ExpectedParams), sort_json(ActualParams)), {ok, {{200, "OK"}, [], ResponseBody}} end diff --git a/test/erlcloud_ddb2_tests.erl b/test/erlcloud_ddb2_tests.erl index a22352aeb..2df12e8ba 100644 --- a/test/erlcloud_ddb2_tests.erl +++ b/test/erlcloud_ddb2_tests.erl @@ -124,8 +124,8 @@ validate_body(<<>> = Actual, Want) -> ?debugFmt("~nEXPECTED~n~p~nACTUAL~n~p~n", [Want, Actual]), ?assertEqual(Want, Actual); validate_body(Body, Expected) -> - Want = sort_json(jsx:decode(list_to_binary(Expected))), - Actual = sort_json(jsx:decode(Body)), + Want = sort_json(jsx:decode(list_to_binary(Expected), [{return_maps, false}])), + Actual = sort_json(jsx:decode(Body, [{return_maps, false}])), case Want =:= Actual of true -> ok; false -> diff --git a/test/erlcloud_ddb_streams_tests.erl b/test/erlcloud_ddb_streams_tests.erl index 6b86cb040..98150d2e3 100644 --- a/test/erlcloud_ddb_streams_tests.erl +++ b/test/erlcloud_ddb_streams_tests.erl @@ -56,8 +56,8 @@ sort_json(V) -> %% verifies that the parameters in the body match the expected parameters -spec validate_body(binary(), expected_body()) -> ok. validate_body(Body, Expected) -> - Want = sort_json(jsx:decode(list_to_binary(Expected))), - Actual = sort_json(jsx:decode(Body)), + Want = sort_json(jsx:decode(list_to_binary(Expected), [{return_maps, false}])), + Actual = sort_json(jsx:decode(Body, [{return_maps, false}])), case Want =:= Actual of true -> ok; false -> diff --git a/test/erlcloud_ddb_tests.erl b/test/erlcloud_ddb_tests.erl index 15fd70a5a..bbd87732b 100644 --- a/test/erlcloud_ddb_tests.erl +++ b/test/erlcloud_ddb_tests.erl @@ -19,7 +19,7 @@ -define(_f(F), fun() -> F end). -export([validate_body/2]). - + %%%=================================================================== %%% Test entry points %%%=================================================================== @@ -73,7 +73,7 @@ stop(_) -> %% verifies that the parameters in the body match the expected parameters -spec validate_body(binary(), expected_body()) -> ok. validate_body(Body, Expected) -> - Want = jsx:decode(list_to_binary(Expected)), + Want = jsx:decode(list_to_binary(Expected)), Actual = jsx:decode(Body), case Want =:= Actual of true -> ok; @@ -86,9 +86,9 @@ validate_body(Body, Expected) -> %% Validates the request body and responds with the provided response. -spec input_expect(string(), expected_body()) -> fun(). input_expect(Response, Expected) -> - fun(_Url, post, _Headers, Body, _Timeout, _Config) -> + fun(_Url, post, _Headers, Body, _Timeout, _Config) -> validate_body(Body, Expected), - {ok, {{200, "OK"}, [], list_to_binary(Response)}} + {ok, {{200, "OK"}, [], list_to_binary(Response)}} end. %% input_test converts an input_test specifier into an eunit test generator @@ -96,7 +96,7 @@ input_expect(Response, Expected) -> -spec input_test(string(), input_test_spec()) -> tuple(). input_test(Response, {Line, {Description, Fun, Expected}}) when is_list(Description) -> - {Description, + {Description, {Line, fun() -> meck:expect(erlcloud_httpc, request, input_expect(Response, Expected)), @@ -118,8 +118,8 @@ input_tests(Response, Tests) -> %% returns the mock of the erlcloud_httpc function output tests expect to be called. -spec output_expect(string()) -> fun(). output_expect(Response) -> - fun(_Url, post, _Headers, _Body, _Timeout, _Config) -> - {ok, {{200, "OK"}, [], list_to_binary(Response)}} + fun(_Url, post, _Headers, _Body, _Timeout, _Config) -> + {ok, {{200, "OK"}, [], list_to_binary(Response)}} end. %% output_test converts an output_test specifier into an eunit test generator @@ -141,9 +141,9 @@ output_test(Fun, {Line, {Description, Response, Result}}) -> end}}. %% output_test(Fun, {Line, {Response, Result}}) -> %% output_test(Fun, {Line, {"", Response, Result}}). - + %% output_tests converts a list of output_test specifiers into an eunit test generator --spec output_tests(fun(), [output_test_spec()]) -> [term()]. +-spec output_tests(fun(), [output_test_spec()]) -> [term()]. output_tests(Fun, Tests) -> [output_test(Fun, Test) || Test <- Tests]. @@ -155,7 +155,7 @@ output_tests(Fun, Tests) -> -spec httpc_response(pos_integer(), string()) -> tuple(). httpc_response(Code, Body) -> {ok, {{Code, ""}, [], list_to_binary(Body)}}. - + -type error_test_spec() :: {pos_integer(), {string(), list(), term()}}. -spec error_test(fun(), error_test_spec()) -> tuple(). error_test(Fun, {Line, {Description, Responses, Result}}) -> @@ -169,7 +169,7 @@ error_test(Fun, {Line, {Description, Responses, Result}}) -> Actual = Fun(), ?assertEqual(Result, Actual) end}}. - + -spec error_tests(fun(), [error_test_spec()]) -> [term()]. error_tests(Fun, Tests) -> [error_test(Fun, Test) || Test <- Tests]. @@ -197,12 +197,12 @@ error_handling_tests(_) -> \"status\":{\"S\":\"online\"} }, \"ConsumedCapacityUnits\": 1 -}" +}" ), OkResult = {ok, [{<<"friends">>, [<<"Lynda">>, <<"Aaron">>]}, {<<"status">>, <<"online">>}]}, - Tests = + Tests = [?_ddb_test( {"Test retry after ProvisionedThroughputExceededException", [httpc_response(400, " @@ -224,7 +224,7 @@ error_handling_tests(_) -> OkResponse], OkResult}) ], - + error_tests(?_f(erlcloud_ddb:get_item(<<"table">>, <<"key">>)), Tests). @@ -235,8 +235,8 @@ batch_get_item_input_tests(_) -> [?_ddb_test( {"BatchGetItem example request", ?_f(erlcloud_ddb:batch_get_item( - [{<<"comp2">>, [<<"Julie">>, - <<"Mingus">>], + [{<<"comp2">>, [<<"Julie">>, + <<"Mingus">>], [{attributes_to_get, [<<"user">>, <<"friends">>]}]}, {<<"comp1">>, [{<<"Casey">>, 1319509152}, {<<"Dave">>, 1319509155}, @@ -277,7 +277,7 @@ batch_get_item_input_tests(_) -> input_tests(Response, Tests). batch_get_item_output_tests(_) -> - Tests = + Tests = [?_ddb_test( {"BatchGetItem example response", " {\"Responses\": @@ -296,7 +296,7 @@ batch_get_item_output_tests(_) -> \"UnprocessedKeys\":{} }", {ok, #ddb_batch_get_item - {responses = + {responses = [#ddb_batch_get_item_response {table = <<"comp1">>, items = [[{<<"status">>, <<"online">>}, @@ -331,17 +331,17 @@ batch_get_item_output_tests(_) -> } }", {ok, #ddb_batch_get_item - {responses = [], - unprocessed_keys = - [{<<"comp2">>, [{s, <<"Julie">>}, - {s, <<"Mingus">>}], + {responses = [], + unprocessed_keys = + [{<<"comp2">>, [{s, <<"Julie">>}, + {s, <<"Mingus">>}], [{attributes_to_get, [<<"user">>, <<"friends">>]}]}, {<<"comp1">>, [{{s, <<"Casey">>}, {n, 1319509152}}, {{s, <<"Dave">>}, {n, 1319509155}}, {{s, <<"Riley">>}, {n, 1319509158}}], [{attributes_to_get, [<<"user">>, <<"status">>]}]}]}}}) ], - + output_tests(?_f(erlcloud_ddb:batch_get_item([{<<"table">>, [<<"key">>]}], [{out, record}])), Tests). %% BatchWriteItem test based on the API examples: @@ -434,7 +434,7 @@ batch_write_item_input_tests(_) -> input_tests(Response, Tests). batch_write_item_output_tests(_) -> - Tests = + Tests = [?_ddb_test( {"BatchWriteItem example response", " { @@ -464,7 +464,7 @@ batch_write_item_output_tests(_) -> } }", {ok, #ddb_batch_write_item - {responses = + {responses = [#ddb_batch_write_item_response {table = <<"Thread">>, consumed_capacity_units = 1.0}, @@ -530,7 +530,7 @@ batch_write_item_output_tests(_) -> {<<"Thread">>, [{put, [{<<"ForumName">>, {s, <<"Amazon DynamoDB">>}}, {<<"Subject">>, {s, <<"DynamoDB Thread 5">>}}]}]}]}}}) ], - + output_tests(?_f(erlcloud_ddb:batch_write_item([], [{out, record}])), Tests). %% CreateTable test based on the API examples: @@ -563,7 +563,7 @@ create_table_input_tests(_) -> input_tests(Response, Tests). create_table_output_tests(_) -> - Tests = + Tests = [?_ddb_test( {"CreateTable example response", " {\"TableDescription\": @@ -587,7 +587,7 @@ create_table_output_tests(_) -> table_name = <<"comp-table">>, table_status = <<"CREATING">>}}}) ], - + output_tests(?_f(erlcloud_ddb:create_table(<<"name">>, {<<"key">>, s}, 5, 10)), Tests). %% DeleteItem test based on the API examples: @@ -621,7 +621,7 @@ delete_item_input_tests(_) -> input_tests(Response, Tests). delete_item_output_tests(_) -> - Tests = + Tests = [?_ddb_test( {"DeleteItem example response", " {\"Attributes\": @@ -637,7 +637,7 @@ delete_item_output_tests(_) -> {<<"time">>, 200}, {<<"user">>, <<"Mingus">>}]}}) ], - + output_tests(?_f(erlcloud_ddb:delete_item(<<"table">>, <<"key">>)), Tests). %% DeleteTable test based on the API examples: @@ -646,7 +646,7 @@ delete_table_input_tests(_) -> Tests = [?_ddb_test( {"DeleteTable example request", - ?_f(erlcloud_ddb:delete_table(<<"Table1">>)), + ?_f(erlcloud_ddb:delete_table(<<"Table1">>)), "{\"TableName\":\"Table1\"}" }) ], @@ -665,7 +665,7 @@ delete_table_input_tests(_) -> input_tests(Response, Tests). delete_table_output_tests(_) -> - Tests = + Tests = [?_ddb_test( {"DeleteTable example response", " {\"TableDescription\": @@ -689,7 +689,7 @@ delete_table_output_tests(_) -> table_name = <<"Table1">>, table_status = <<"DELETING">>}}}) ], - + output_tests(?_f(erlcloud_ddb:delete_table(<<"name">>)), Tests). %% DescribeTable test based on the API examples: @@ -698,7 +698,7 @@ describe_table_input_tests(_) -> Tests = [?_ddb_test( {"DescribeTable example request", - ?_f(erlcloud_ddb:describe_table(<<"Table1">>)), + ?_f(erlcloud_ddb:describe_table(<<"Table1">>)), "{\"TableName\":\"Table1\"}" }) ], @@ -719,7 +719,7 @@ describe_table_input_tests(_) -> input_tests(Response, Tests). describe_table_output_tests(_) -> - Tests = + Tests = [?_ddb_test( {"DescribeTable example response", " {\"Table\": @@ -747,7 +747,7 @@ describe_table_output_tests(_) -> table_size_bytes = 949, table_status = <<"ACTIVE">>}}}) ], - + output_tests(?_f(erlcloud_ddb:describe_table(<<"name">>)), Tests). %% GetItem test based on the API examples: @@ -765,14 +765,14 @@ get_item_input_tests(_) -> Tests = [?_ddb_test( {"GetItem example request, with fully specified keys", - ?_f(erlcloud_ddb:get_item(<<"comptable">>, {{s, <<"Julie">>}, {n, 1307654345}}, + ?_f(erlcloud_ddb:get_item(<<"comptable">>, {{s, <<"Julie">>}, {n, 1307654345}}, [consistent_read, {attributes_to_get, [<<"status">>, <<"friends">>]}])), Example1Response}), ?_ddb_test( {"GetItem example request, with inferred key types", - ?_f(erlcloud_ddb:get_item(<<"comptable">>, {"Julie", 1307654345}, - [consistent_read, + ?_f(erlcloud_ddb:get_item(<<"comptable">>, {"Julie", 1307654345}, + [consistent_read, {attributes_to_get, [<<"status">>, <<"friends">>]}])), Example1Response}), ?_ddb_test( @@ -795,7 +795,7 @@ get_item_input_tests(_) -> input_tests(Response, Tests). get_item_output_tests(_) -> - Tests = + Tests = [?_ddb_test( {"GetItem example response", " {\"Item\": @@ -831,15 +831,15 @@ get_item_output_tests(_) -> {<<"b">>, <<5,182>>}, {<<"empty">>, <<>>}]}}), ?_ddb_test( - {"GetItem item not found", + {"GetItem item not found", "{\"ConsumedCapacityUnits\": 0.5}", {ok, []}}), ?_ddb_test( - {"GetItem no attributes returned", + {"GetItem no attributes returned", "{\"ConsumedCapacityUnits\":0.5,\"Item\":{}}", {ok, []}}) ], - + output_tests(?_f(erlcloud_ddb:get_item(<<"table">>, <<"key">>)), Tests). %% ListTables test based on the API examples: @@ -848,12 +848,12 @@ list_tables_input_tests(_) -> Tests = [?_ddb_test( {"ListTables example request", - ?_f(erlcloud_ddb:list_tables([{limit, 3}, {exclusive_start_table_name, <<"comp2">>}])), + ?_f(erlcloud_ddb:list_tables([{limit, 3}, {exclusive_start_table_name, <<"comp2">>}])), "{\"ExclusiveStartTableName\":\"comp2\",\"Limit\":3}" }), ?_ddb_test( {"ListTables empty request", - ?_f(erlcloud_ddb:list_tables()), + ?_f(erlcloud_ddb:list_tables()), "{}" }) @@ -863,7 +863,7 @@ list_tables_input_tests(_) -> input_tests(Response, Tests). list_tables_output_tests(_) -> - Tests = + Tests = [?_ddb_test( {"ListTables example response", "{\"LastEvaluatedTableName\":\"comp5\",\"TableNames\":[\"comp3\",\"comp4\",\"comp5\"]}", @@ -871,7 +871,7 @@ list_tables_output_tests(_) -> {last_evaluated_table_name = <<"comp5">>, table_names = [<<"comp3">>, <<"comp4">>, <<"comp5">>]}}}) ], - + output_tests(?_f(erlcloud_ddb:list_tables([{out, record}])), Tests). %% PutItem test based on the API examples: @@ -880,8 +880,8 @@ put_item_input_tests(_) -> Tests = [?_ddb_test( {"PutItem example request", - ?_f(erlcloud_ddb:put_item(<<"comp5">>, - [{<<"time">>, 300}, + ?_f(erlcloud_ddb:put_item(<<"comp5">>, + [{<<"time">>, 300}, {<<"feeling">>, <<"not surprised">>}, {<<"user">>, <<"Riley">>}], [{return_values, all_old}, @@ -899,8 +899,8 @@ put_item_input_tests(_) -> }), ?_ddb_test( {"PutItem float inputs", - ?_f(erlcloud_ddb:put_item(<<"comp5">>, - [{<<"time">>, 300}, + ?_f(erlcloud_ddb:put_item(<<"comp5">>, + [{<<"time">>, 300}, {<<"typed float">>, {n, 1.2}}, {<<"untyped float">>, 3.456}, {<<"mixed set">>, {ns, [7.8, 9.0, 10]}}], @@ -926,7 +926,7 @@ put_item_input_tests(_) -> input_tests(Response, Tests). put_item_output_tests(_) -> - Tests = + Tests = [?_ddb_test( {"PutItem example response", " {\"Attributes\": @@ -939,7 +939,7 @@ put_item_output_tests(_) -> {<<"time">>, 300}, {<<"user">>, <<"Riley">>}]}}) ], - + output_tests(?_f(erlcloud_ddb:put_item(<<"table">>, [])), Tests). %% Query test based on the API examples: @@ -998,7 +998,7 @@ q_input_tests(_) -> input_tests(Response, Tests). q_output_tests(_) -> - Tests = + Tests = [?_ddb_test( {"Query example 1 response", " {\"Count\":2,\"Items\":[{ @@ -1044,7 +1044,7 @@ q_output_tests(_) -> last_evaluated_key = undefined, consumed_capacity_units = 1}}}) ], - + output_tests(?_f(erlcloud_ddb:q(<<"table">>, <<"key">>, [{out, record}])), Tests). %% Scan test based on the API examples: @@ -1053,7 +1053,7 @@ scan_input_tests(_) -> Tests = [?_ddb_test( {"Scan example 1 request", - ?_f(erlcloud_ddb:scan(<<"1-hash-rangetable">>)), + ?_f(erlcloud_ddb:scan(<<"1-hash-rangetable">>)), "{\"TableName\":\"1-hash-rangetable\"}" }), ?_ddb_test( @@ -1100,7 +1100,7 @@ scan_input_tests(_) -> input_tests(Response, Tests). scan_output_tests(_) -> - Tests = + Tests = [?_ddb_test( {"Scan example 1 response", " {\"Count\":4,\"Items\":[{ @@ -1198,7 +1198,7 @@ scan_output_tests(_) -> scanned_count = 2, consumed_capacity_units = 0.5}}}) ], - + output_tests(?_f(erlcloud_ddb:scan(<<"name">>, [{out, record}])), Tests). %% UpdateItem test based on the API examples: @@ -1254,7 +1254,7 @@ update_item_input_tests(_) -> input_tests(Response, Tests). update_item_output_tests(_) -> - Tests = + Tests = [?_ddb_test( {"UpdateItem example response", " {\"Attributes\": @@ -1269,7 +1269,7 @@ update_item_output_tests(_) -> {<<"time">>, 1307654350}, {<<"user">>, <<"Julie">>}]}}) ], - + output_tests(?_f(erlcloud_ddb:update_item(<<"table">>, <<"key">>, [])), Tests). %% UpdateTable test based on the API examples: @@ -1302,7 +1302,7 @@ update_table_input_tests(_) -> input_tests(Response, Tests). update_table_output_tests(_) -> - Tests = + Tests = [?_ddb_test( {"UpdateTable example response", " {\"TableDescription\": @@ -1329,6 +1329,6 @@ update_table_output_tests(_) -> table_name = <<"comp1">>, table_status = <<"UPDATING">>}}}) ], - + output_tests(?_f(erlcloud_ddb:update_table(<<"name">>, 5, 15)), Tests). diff --git a/test/erlcloud_directconnect_tests.erl b/test/erlcloud_directconnect_tests.erl index 1ee4fcb8d..a57c4d9a3 100644 --- a/test/erlcloud_directconnect_tests.erl +++ b/test/erlcloud_directconnect_tests.erl @@ -59,8 +59,8 @@ sort_json(V) -> %% verifies that the parameters in the body match the expected parameters -spec validate_body(binary(), expected_body()) -> ok. validate_body(Body, Expected) -> - Want = sort_json(jsx:decode(list_to_binary(Expected))), - Actual = sort_json(jsx:decode(Body)), + Want = sort_json(jsx:decode(list_to_binary(Expected), [{return_maps, false}])), + Actual = sort_json(jsx:decode(Body, [{return_maps, false}])), case Want =:= Actual of true -> ok; false -> diff --git a/test/erlcloud_ecs_tests.erl b/test/erlcloud_ecs_tests.erl index 93a06538e..ef03b7c18 100644 --- a/test/erlcloud_ecs_tests.erl +++ b/test/erlcloud_ecs_tests.erl @@ -3240,8 +3240,8 @@ sort_json(V) -> %% verifies that the parameters in the body match the expected parameters -spec validate_body(binary(), expected_body()) -> ok. validate_body(Body, Expected) -> - Want = sort_json(jsx:decode(list_to_binary(Expected))), - Actual = sort_json(jsx:decode(Body)), + Want = sort_json(jsx:decode(list_to_binary(Expected), [{return_maps, false}])), + Actual = sort_json(jsx:decode(Body, [{return_maps, false}])), case Want =:= Actual of true -> ok; false -> diff --git a/test/erlcloud_emr_tests.erl b/test/erlcloud_emr_tests.erl index 30f76d0d7..3354158e3 100644 --- a/test/erlcloud_emr_tests.erl +++ b/test/erlcloud_emr_tests.erl @@ -189,7 +189,7 @@ input_test(ResponseBody, {Line, {Description, Fun, ExpectedParams}}) -> erlcloud_httpc, request, fun(_Url, post, _Headers, RequestBody, _Timeout, _Config) -> - ActualParams = jsx:decode(RequestBody), + ActualParams = jsx:decode(RequestBody, [{return_maps, false}]), ?assertEqual(sort_json(ExpectedParams), sort_json(ActualParams)), {ok, {{200, "OK"}, [], ResponseBody}} end diff --git a/test/erlcloud_iam_tests.erl b/test/erlcloud_iam_tests.erl index cc5fc005f..696664291 100644 --- a/test/erlcloud_iam_tests.erl +++ b/test/erlcloud_iam_tests.erl @@ -147,7 +147,7 @@ validate_param(Param, Expected) -> Expected1 = lists:delete({Key, Value}, Expected), case length(Expected) - 1 =:= length(Expected1) of true -> ok; - false -> + false -> ?debugFmt("Parameter not expected: ~p", [{Key, Value}]) end, ?assertEqual(length(Expected) - 1, length(Expected1)), @@ -166,9 +166,9 @@ validate_params(Body, Expected) -> %% Validates the query body and responds with the provided response. -spec input_expect(string(), [expected_param()]) -> fun(). input_expect(Response, Expected) -> - fun(_Url, post, _Headers, Body, _Timeout, _Config) -> + fun(_Url, post, _Headers, Body, _Timeout, _Config) -> validate_params(Body, Expected), - {ok, {{200, "OK"}, [], list_to_binary(Response)}} + {ok, {{200, "OK"}, [], list_to_binary(Response)}} end. %% input_test converts an input_test specifier into an eunit test generator @@ -176,7 +176,7 @@ input_expect(Response, Expected) -> -spec input_test(string(), input_test_spec()) -> tuple(). input_test(Response, {Line, {Description, Fun, Params}}) when is_list(Description) -> - {Description, + {Description, {Line, fun() -> meck:expect(erlcloud_httpc, request, input_expect(Response, Params)), @@ -220,19 +220,19 @@ output_test(Fun, {Line, {Description, Response, Result}}, OutputFun) -> io:format("Result: ~p~n", [Result]), ?assertEqual(Result, Actual) end}}. - + %% output_tests converts a list of output_test specifiers into an eunit test generator --spec output_tests(fun(), [output_test_spec()]) -> [term()]. +-spec output_tests(fun(), [output_test_spec()]) -> [term()]. output_tests(Fun, Tests) -> [output_test(Fun, Test, fun output_expect/1) || Test <- Tests]. %% output_tests converts a list of output_test specifiers into an eunit test generator --spec output_tests_seq(fun(), [output_test_spec()]) -> [term()]. +-spec output_tests_seq(fun(), [output_test_spec()]) -> [term()]. output_tests_seq(Fun, Tests) -> [output_test(Fun, Test, fun output_expect_seq/1) || Test <- Tests]. get_account_summary_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning account summary.", ?_f(erlcloud_iam:get_account_summary()), @@ -535,7 +535,7 @@ list_virtual_mfa_devices_output_test(_) -> "). get_account_password_policy_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning account password policy.", ?_f(erlcloud_iam:get_account_password_policy()), @@ -582,7 +582,7 @@ get_account_password_policy_output_tests(_) -> "). get_user_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning User.", ?_f(erlcloud_iam:get_user()), @@ -622,7 +622,7 @@ get_user_output_tests(_) -> "). get_group_policy_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning group policy.", ?_f(erlcloud_iam:get_group_policy("Admins", "AdminRoot")), @@ -660,7 +660,7 @@ get_group_policy_output_tests(_) -> "). get_login_profile_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning login profile.", ?_f(erlcloud_iam:get_login_profile("Bob")), @@ -695,7 +695,7 @@ get_login_profile_output_tests(_) -> "). get_role_policy_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning role policy.", ?_f(erlcloud_iam:get_role_policy("S3Access", "S3AccessPolicy")), @@ -732,7 +732,7 @@ get_role_policy_output_tests(_) -> "). get_user_policy_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning user policy.", ?_f(erlcloud_iam:get_user_policy("Bob", "AllAccessPolicy")), @@ -755,9 +755,9 @@ get_user_policy_output_tests(_) -> }) ], output_tests(?_f(erlcloud_iam:get_user_policy("Bob", "AllAccessPolicy")), Tests). - + list_access_keys_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning all users in an account.", ?_f(erlcloud_iam:list_access_keys("test")), @@ -812,7 +812,7 @@ list_access_keys_output_tests(_) -> {status, "Inactive"}] ]}}) ], - output_tests(?_f(erlcloud_iam:list_access_keys("test")), Tests). + output_tests(?_f(erlcloud_iam:list_access_keys("test")), Tests). list_access_keys_all_output_tests(_) -> Tests = [?_iam_test( @@ -883,7 +883,7 @@ list_access_keys_all_output_tests(_) -> {status, "Inactive"}] ]}}) ], - output_tests_seq(?_f(erlcloud_iam:list_access_keys_all("test")), Tests). + output_tests_seq(?_f(erlcloud_iam:list_access_keys_all("test")), Tests). get_access_key_last_used_output() -> " @@ -928,7 +928,7 @@ get_access_key_last_used_output_tests() -> %% ListUsers test based on the API examples: %% http://docs.aws.amazon.com/IAM/latest/APIReference/API_ListUsers.html list_users_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning all users in an account.", ?_f(erlcloud_iam:list_users("test")), @@ -945,7 +945,7 @@ list_users_input_tests(_) -> ", input_tests(Response, Tests). - + list_users_output_tests(_) -> Tests = [?_iam_test( {"This lists all users in your account", @@ -989,7 +989,7 @@ list_users_output_tests(_) -> {password_last_used,{{2014,9,24},{16,18,7}}}]]} }) ], - output_tests(?_f(erlcloud_iam:list_users("test")), Tests). + output_tests(?_f(erlcloud_iam:list_users("test")), Tests). list_users_all_output_tests(_) -> @@ -1074,13 +1074,13 @@ list_users_all_output_tests(_) -> {password_last_used,{{2014,9,24},{16,18,7}}}]]} }) ], - output_tests_seq(?_f(erlcloud_iam:list_users_all("test")), Tests). + output_tests_seq(?_f(erlcloud_iam:list_users_all("test")), Tests). %% ListGroups test based on the API examples: %% http://docs.aws.amazon.com/IAM/latest/APIReference/API_ListGroups.html list_groups_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning all groups in an account.", ?_f(erlcloud_iam:list_groups("test")), @@ -1097,7 +1097,7 @@ list_groups_input_tests(_) -> ", input_tests(Response, Tests). - + list_groups_output_tests(_) -> Tests = [?_iam_test( {"This lists all groups in your account", @@ -1108,7 +1108,7 @@ list_groups_output_tests(_) -> /division_abc/ Admins AGPACKCEVSQ6C2EXAMPLE - arn:aws:iam::123456789012:group/Admins + arn:aws:iam::123456789012:group/Admins 2012-05-08T23:34:01Z @@ -1161,7 +1161,7 @@ list_groups_all_output_tests(_) -> /division_abc/ Admins AGPACKCEVSQ6C2EXAMPLE - arn:aws:iam::123456789012:group/Admins + arn:aws:iam::123456789012:group/Admins 2012-05-08T23:34:01Z @@ -1193,7 +1193,7 @@ list_groups_all_output_tests(_) -> /division_abc/ Admins AGPACKCEVSQ6C2EXAMPLE - arn:aws:iam::123456789012:group/Admins + arn:aws:iam::123456789012:group/Admins 2012-05-08T23:34:01Z @@ -1253,7 +1253,7 @@ list_groups_all_output_tests(_) -> %% ListRoles test based on the API examples: %% http://docs.aws.amazon.com/IAM/latest/APIReference/API_ListRoles.html list_roles_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning all roles in an account.", ?_f(erlcloud_iam:list_roles("test")), @@ -1270,7 +1270,7 @@ list_roles_input_tests(_) -> ", input_tests(Response, Tests). - + list_roles_output_tests(_) -> Tests = [?_iam_test( {"This lists all roles in your account", @@ -1315,7 +1315,7 @@ list_roles_output_tests(_) -> {arn, "arn:aws:iam::123456789012:role/application_abc/component_xyz/SDBAccess"}] ]}}) ], - output_tests(?_f(erlcloud_iam:list_roles("test")), Tests). + output_tests(?_f(erlcloud_iam:list_roles("test")), Tests). list_roles_all_output_tests(_) -> Tests = [?_iam_test( @@ -1400,7 +1400,7 @@ list_roles_all_output_tests(_) -> {arn, "arn:aws:iam::123456789012:role/application_abc/component_xyz/SDBAccess"}] ]}}) ], - output_tests_seq(?_f(erlcloud_iam:list_roles_all("test")), Tests). + output_tests_seq(?_f(erlcloud_iam:list_roles_all("test")), Tests). -define(LIST_GROUPS_FOR_USER_RESP, " @@ -1421,7 +1421,7 @@ list_roles_all_output_tests(_) -> "). list_groups_for_user_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning groups for a user.", ?_f(erlcloud_iam:list_groups_for_user("Bob")), @@ -1496,7 +1496,7 @@ list_groups_for_user_all_output_tests(_) -> "). list_user_policies_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning policies for a user.", ?_f(erlcloud_iam:list_user_policies("Bob")), @@ -1558,7 +1558,7 @@ list_user_policies_all_output_tests(_) -> "). list_group_policies_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning policies for a group.", ?_f(erlcloud_iam:list_group_policies("Admins")), @@ -1620,7 +1620,7 @@ list_group_policies_all_output_tests(_) -> "). list_role_policies_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning policies for a role.", ?_f(erlcloud_iam:list_role_policies("S3Access")), @@ -1696,7 +1696,7 @@ list_role_policies_all_output_tests(_) -> "). list_instance_profiles_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning instance profiles.", ?_f(erlcloud_iam:list_instance_profiles()), @@ -1814,7 +1814,7 @@ list_instance_profiles_all_output_tests(_) -> "). get_instance_profile_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning instance profile.", ?_f(erlcloud_iam:get_instance_profile("Webserver")), @@ -1993,7 +1993,7 @@ get_instance_profile_output_tests(_) -> "). get_account_authorization_details_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning the authorization details.", ?_f(erlcloud_iam:get_account_authorization_details()), @@ -2117,7 +2117,7 @@ get_account_authorization_details_output_tests(_) -> "). generate_credential_report_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test generating credential report.", ?_f(erlcloud_iam:generate_credential_report()), @@ -2125,7 +2125,7 @@ generate_credential_report_input_tests(_) -> {"Action", "GenerateCredentialReport"} ]}) ], - + input_tests(?GENERATE_CREDENTIAL_REPORT_RESP, Tests). generate_credential_report_output_tests(_) -> @@ -2151,7 +2151,7 @@ generate_credential_report_output_tests(_) -> "). get_credential_report_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test get credential report.", ?_f(erlcloud_iam:get_credential_report()), @@ -2159,7 +2159,7 @@ get_credential_report_input_tests(_) -> {"Action", "GetCredentialReport"} ]}) ], - + input_tests(?GET_CREDENTIAL_REPORT_RESP, Tests). get_credential_report_output_tests(_) -> @@ -2190,21 +2190,21 @@ get_credential_report_output_tests(_) -> "). list_attached_user_policies_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning the list of user attached policies.", ?_f(erlcloud_iam:list_attached_user_policies("Alice", "/")), [ {"Action", "ListAttachedUserPolicies"}, {"UserName", "Alice"}, - {"PathPrefix", http_uri:encode("/")} + {"PathPrefix", "%2F"} ]}) ], input_tests(?LIST_ATTACHED_USER_POLICIES_RESP, Tests). list_attached_user_policies_output_tests(_) -> - Tests = + Tests = [?_iam_test( {"This returns the list of user attached policies.", ?LIST_ATTACHED_USER_POLICIES_RESP, @@ -2215,7 +2215,7 @@ list_attached_user_policies_output_tests(_) -> output_tests(?_f(erlcloud_iam:list_attached_user_policies("Alice", "/")), Tests). list_attached_user_policies_all_output_tests(_) -> - Tests = + Tests = [?_iam_test( {"This returns the list of user attached policies.", [" @@ -2259,21 +2259,21 @@ list_attached_user_policies_all_output_tests(_) -> "). list_attached_group_policies_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning the list of group attached policies.", ?_f(erlcloud_iam:list_attached_group_policies("ReadOnlyUsers", "/")), [ {"Action", "ListAttachedGroupPolicies"}, {"GroupName", "ReadOnlyUsers"}, - {"PathPrefix", http_uri:encode("/")} + {"PathPrefix", "%2F"} ]}) ], input_tests(?LIST_ATTACHED_GROUP_POLICIES_RESP, Tests). list_attached_group_policies_output_tests(_) -> - Tests = + Tests = [?_iam_test( {"This returns the list of group attached policies.", ?LIST_ATTACHED_GROUP_POLICIES_RESP, @@ -2284,7 +2284,7 @@ list_attached_group_policies_output_tests(_) -> output_tests(?_f(erlcloud_iam:list_attached_group_policies("ReadOnlyUsers", "/")), Tests). list_attached_group_policies_all_output_tests(_) -> - Tests = + Tests = [?_iam_test( {"This returns the list of group attached policies.", [" @@ -2328,21 +2328,21 @@ list_attached_group_policies_all_output_tests(_) -> "). list_attached_role_policies_input_tests(_) -> - Tests = + Tests = [?_iam_test( {"Test returning the list of role attached policies.", ?_f(erlcloud_iam:list_attached_role_policies("ReadOnlyRole", "/")), [ {"Action", "ListAttachedRolePolicies"}, {"RoleName", "ReadOnlyRole"}, - {"PathPrefix", http_uri:encode("/")} + {"PathPrefix", "%2F"} ]}) ], input_tests(?LIST_ATTACHED_ROLE_POLICIES_RESP, Tests). list_attached_role_policies_output_tests(_) -> - Tests = + Tests = [?_iam_test( {"This returns the list of role attached policies.", ?LIST_ATTACHED_ROLE_POLICIES_RESP, @@ -2353,7 +2353,7 @@ list_attached_role_policies_output_tests(_) -> output_tests(?_f(erlcloud_iam:list_attached_role_policies("ReadOnlyRole", "/")), Tests). list_attached_role_policies_all_output_tests(_) -> - Tests = + Tests = [?_iam_test( {"This returns the list of role attached policies.", [" @@ -2380,7 +2380,7 @@ list_attached_role_policies_all_output_tests(_) -> ], output_tests_seq(?_f(erlcloud_iam:list_attached_role_policies_all("ReadOnlyRole", "/")), Tests). --define(GET_POLICY_RESP, +-define(GET_POLICY_RESP, " @@ -2534,7 +2534,7 @@ list_entities_for_policy_input_tests(_) -> ?_f(erlcloud_iam:list_entities_for_policy("test")), [ {"Action", "ListEntitiesForPolicy"}, - {"PathPrefix", http_uri:encode("/")}, + {"PathPrefix", "%2F"}, {"PolicyArn", "test"} ]}) ], @@ -2658,14 +2658,14 @@ get_policy_input_tests(_) -> ?_f(erlcloud_iam:get_policy("arn:aws:iam::123456789012:policy/S3-read-only-example-bucket")), [ {"Action", "GetPolicy"}, - {"PolicyArn", http_uri:encode("arn:aws:iam::123456789012:policy/S3-read-only-example-bucket")} + {"PolicyArn", "arn%3Aaws%3Aiam%3A%3A123456789012%3Apolicy%2FS3-read-only-example-bucket"} ]}) ], input_tests(?GET_POLICY_RESP, Tests). get_policy_output_tests(_) -> - Tests = + Tests = [?_iam_test( {"This returns a policy.", ?GET_POLICY_RESP, @@ -2706,7 +2706,7 @@ get_policy_version_input_tests(_) -> ?_f(erlcloud_iam:get_policy_version("arn:aws:iam::123456789012:policy/S3-read-only-example-bucket", "v1")), [ {"Action", "GetPolicyVersion"}, - {"PolicyArn", http_uri:encode("arn:aws:iam::123456789012:policy/S3-read-only-example-bucket")}, + {"PolicyArn", "arn%3Aaws%3Aiam%3A%3A123456789012%3Apolicy%2FS3-read-only-example-bucket"}, {"VersionId", "v1"} ]}) ], @@ -2714,14 +2714,14 @@ get_policy_version_input_tests(_) -> input_tests(?GET_POLICY_VERSION_RESP, Tests). get_policy_version_output_tests(_) -> - Tests = + Tests = [?_iam_test( {"This returns a policy version.", ?GET_POLICY_VERSION_RESP, {ok, [[{create_date, {{2014,9,15},{20,31,47}}}, {version_id, "v1"}, {is_default_version, true}, - {policy_document, + {policy_document, "\n {\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:Get*\",\"s3:List*\"],\n \"Resource\":[\"arn:aws:s3:::EXAMPLE-BUCKET\",\"arn:aws:s3:::EXAMPLE-BUCKET/*\"]}]}\n "} ]]} }) @@ -2805,7 +2805,7 @@ simulate_custom_policy_input_test(_) -> PolicyDoc2])), [ {"Action", "SimulateCustomPolicy"}, - {"ActionNames.member.1", http_uri:encode(Action)}, + {"ActionNames.member.1", "s3%3AListBucket"}, {"PolicyInputList.member.1", PolicyDoc1}, {"PolicyInputList.member.2", PolicyDoc2}, {"MaxItems", "1000"} @@ -2816,9 +2816,9 @@ simulate_custom_policy_input_test(_) -> [PolicyDoc1], ContextEntries)), [{"Action","SimulateCustomPolicy"}, - {"ActionNames.member.1", http_uri:encode(Action)}, + {"ActionNames.member.1", "s3%3AListBucket"}, {"PolicyInputList.member.1","policy_doc1"}, - {"ContextEntries.member.1.ContextKeyName",http_uri:encode("aws:MultiFactorAuthPresent")}, + {"ContextEntries.member.1.ContextKeyName","aws%3AMultiFactorAuthPresent"}, {"ContextEntries.member.1.ContextKeyType","boolean"}, {"ContextEntries.member.1.ContextKeyValues.member.1","true"}, {"MaxItems","1000"}]}) @@ -2863,8 +2863,8 @@ simulate_principal_policy_input_test(_) -> [Action])), [ {"Action", "SimulatePrincipalPolicy"}, - {"ActionNames.member.1", http_uri:encode(Action)}, - {"PolicySourceArn", http_uri:encode(Principal)}, + {"ActionNames.member.1", "s3%3APutObject"}, + {"PolicySourceArn", "arn%3Aaws%3Aiam%3A%3A%3Auser%2FJill"}, {"MaxItems", "1000"} ]}) ], diff --git a/test/erlcloud_inspector_tests.erl b/test/erlcloud_inspector_tests.erl index 653ded4b8..e438d6949 100644 --- a/test/erlcloud_inspector_tests.erl +++ b/test/erlcloud_inspector_tests.erl @@ -514,8 +514,8 @@ sort_json(V) -> %% verifies that the parameters in the body match the expected parameters -spec validate_body(binary(), expected_body()) -> ok. validate_body(Body, Expected) -> - Want = sort_json(jsx:decode(Expected)), - Actual = sort_json(jsx:decode(Body)), + Want = sort_json(jsx:decode(Expected, [{return_maps, false}])), + Actual = sort_json(jsx:decode(Body, [{return_maps, false}])), case Want =:= Actual of true -> ok; false -> @@ -602,4 +602,4 @@ all_tests(Action, Function, PostData, Response) -> )], input_tests(<<>>, InputTests) ++ - output_tests(Function, OutputTests). \ No newline at end of file + output_tests(Function, OutputTests). diff --git a/test/erlcloud_kinesis_tests.erl b/test/erlcloud_kinesis_tests.erl index 3e45dd14e..a354b1f40 100644 --- a/test/erlcloud_kinesis_tests.erl +++ b/test/erlcloud_kinesis_tests.erl @@ -97,8 +97,8 @@ sort_json(V) -> %% verifies that the parameters in the body match the expected parameters -spec validate_body(binary(), expected_body()) -> ok. validate_body(Body, Expected) -> - Want = sort_json(jsx:decode(list_to_binary(Expected))), - Actual = sort_json(jsx:decode(Body)), + Want = sort_json(jsx:decode(list_to_binary(Expected), [{return_maps, false}])), + Actual = sort_json(jsx:decode(Body, [{return_maps, false}])), case Want =:= Actual of true -> ok; false -> @@ -193,7 +193,7 @@ create_stream_output_tests(_) -> Tests = [?_kinesis_test( {"CreateStream example response", "{}", - {ok, jsx:decode(<<"{}">>)}}) + {ok, jsx:decode(<<"{}">>, [{return_maps, false}])}}) ], output_tests(?_f(erlcloud_kinesis:create_stream(<<"streamName">>, 2)), Tests). @@ -218,7 +218,7 @@ delete_stream_output_tests(_) -> Tests = [?_kinesis_test( {"DeleteStream example response", "{}", - {ok, jsx:decode(<<"{}">>)}}) + {ok, jsx:decode(<<"{}">>, [{return_maps, false}])}}) ], output_tests(?_f(erlcloud_kinesis:delete_stream(<<"streamName">>)), Tests). @@ -826,7 +826,7 @@ merge_shards_output_tests(_) -> Tests = [?_kinesis_test( {"MergeShards example response", "{}", - {ok, jsx:decode(<<"{}">>)}}) + {ok, jsx:decode(<<"{}">>, [{return_maps, false}])}}) ], output_tests(?_f(erlcloud_kinesis:merge_shards(<<"test">>, <<"shardId-000000000001">>, <<"shardId-000000000003">>)), Tests). @@ -853,7 +853,7 @@ split_shards_output_tests(_) -> Tests = [?_kinesis_test( {"SplitShard example response", "{}", - {ok, jsx:decode(<<"{}">>)}}) + {ok, jsx:decode(<<"{}">>, [{return_maps, false}])}}) ], output_tests(?_f(erlcloud_kinesis:split_shards(<<"test">>, <<"shardId-000000000000">>, <<"10">>)), Tests). @@ -900,7 +900,7 @@ list_tags_for_stream_output_tests(_) -> \"Tags\": [{\"Key\":\"key1\",\"Value\":\"val1\"}]}", Tests = [?_kinesis_test({"List tags response test", Response, - {ok, jsx:decode(list_to_binary(Response))}})], + {ok, jsx:decode(list_to_binary(Response), [{return_maps, false}])}})], output_tests( ?_f(erlcloud_kinesis:list_tags_for_stream(<<"stream">>, <<"key1">>, 1)), Tests diff --git a/test/erlcloud_kms_tests.erl b/test/erlcloud_kms_tests.erl index abbe41ee4..76fce69f7 100644 --- a/test/erlcloud_kms_tests.erl +++ b/test/erlcloud_kms_tests.erl @@ -116,8 +116,8 @@ sort_json(V) -> %% verifies that the parameters in the body match the expected parameters -spec validate_body(binary(), expected_body()) -> ok. validate_body(Body, Expected) -> - Want = sort_json(jsx:decode(Expected)), - Actual = sort_json(jsx:decode(Body)), + Want = sort_json(jsx:decode(Expected, [{return_maps, false}])), + Actual = sort_json(jsx:decode(Body, [{return_maps, false}])), case Want =:= Actual of true -> ok; false -> diff --git a/test/erlcloud_mes_tests.erl b/test/erlcloud_mes_tests.erl index 73863ecaa..af43d1464 100644 --- a/test/erlcloud_mes_tests.erl +++ b/test/erlcloud_mes_tests.erl @@ -57,8 +57,8 @@ sort_json(V) -> %% verifies that the parameters in the body match the expected parameters -spec validate_body(binary(), expected_body()) -> ok. validate_body(Body, Expected) -> - Want = sort_json(jsx:decode(list_to_binary(Expected))), - Actual = sort_json(jsx:decode(Body)), + Want = sort_json(jsx:decode(list_to_binary(Expected), [{return_maps, false}])), + Actual = sort_json(jsx:decode(Body, [{return_maps, false}])), case Want =:= Actual of true -> ok; false -> @@ -264,7 +264,7 @@ get_entitlement_output_tests(_) -> \"ExpirationDate\": 1485477404000 } ] -}">>)}} +}">>, [{return_maps, false}])}} ), ?_mes_test( {"GetEntitlements example response with NextToken"," @@ -298,7 +298,7 @@ get_entitlement_output_tests(_) -> \"ExpirationDate\": 1485477404000 } ] -}">>)}} +}">>, [{return_maps, false}])}} )], output_tests(?_f(erlcloud_mes:get_entitlement( diff --git a/test/erlcloud_mms_tests.erl b/test/erlcloud_mms_tests.erl index e1ead2941..9fdd5fe65 100644 --- a/test/erlcloud_mms_tests.erl +++ b/test/erlcloud_mms_tests.erl @@ -61,8 +61,8 @@ sort_json(V) -> %% verifies that the parameters in the body match the expected parameters -spec validate_body(binary(), expected_body()) -> ok. validate_body(Body, Expected) -> - Want = sort_json(jsx:decode(list_to_binary(Expected))), - Actual = sort_json(jsx:decode(Body)), + Want = sort_json(jsx:decode(list_to_binary(Expected), [{return_maps, false}])), + Actual = sort_json(jsx:decode(Body, [{return_maps, false}])), case Want =:= Actual of true -> ok; false -> @@ -234,7 +234,7 @@ batch_meter_usage_output_tests(_) -> \"Quantity\": 20, \"Timestamp\": 1471959107 } ] -}">>)}} +}">>, [{return_maps, false}])}} )], output_tests(?_f(erlcloud_mms:batch_meter_usage( @@ -281,7 +281,7 @@ meter_usage_output_tests(_) -> Tests = [?_mms_test( {"MeterUsage example response", "{\"MeteringRecordId\": \"string\"}", - {ok, jsx:decode(<<"{\"MeteringRecordId\": \"string\"}">>)}}) + {ok, jsx:decode(<<"{\"MeteringRecordId\": \"string\"}">>, [{return_maps, false}])}}) ], output_tests(?_f(erlcloud_mms:meter_usage( @@ -319,7 +319,7 @@ resolve_customer_output_tests(_) -> \"CustomerIdentifier\": \"string\", \"ProductCode\": \"string\" }", - {ok,jsx:decode(<<"{\"CustomerIdentifier\": \"string\",\"ProductCode\": \"string\"}">>)}}) + {ok,jsx:decode(<<"{\"CustomerIdentifier\": \"string\",\"ProductCode\": \"string\"}">>, [{return_maps, false}])}}) ], output_tests(?_f(erlcloud_mms:resolve_customer(<<"string">>)), Tests). diff --git a/test/erlcloud_sdb_tests.erl b/test/erlcloud_sdb_tests.erl index feb24d162..721c65eff 100644 --- a/test/erlcloud_sdb_tests.erl +++ b/test/erlcloud_sdb_tests.erl @@ -1,7 +1,22 @@ -module(erlcloud_sdb_tests). -ifdef(TEST). --compile(export_all). + +-export([ + expect_chain/1, + single_result_response/0, + single_result_response/1, + only_token_response/0, + single_result_and_token_response/0, + unavailable_response/0, + select_single_response/0, + select_next_token/0, + select_all_single_response/0, + select_all_failure/0, + select_all_503/0, + select_all_next_token/0, + select_all_next_and_failure/0, + select_all_two_results/0]). -include_lib("eunit/include/eunit.hrl"). diff --git a/test/erlcloud_waf_tests.erl b/test/erlcloud_waf_tests.erl index 533096566..2d4f206ef 100644 --- a/test/erlcloud_waf_tests.erl +++ b/test/erlcloud_waf_tests.erl @@ -42,14 +42,14 @@ field_to_match = #waf_field_to_match{type = query_string}, positional_constraint = contains, target_string = "foobar", - text_transformation = none}}). + text_transformation = none}}). -define(UPDATE_IP_SET, #waf_ip_set_update{ action = insert, ip_set_descriptor = #waf_ip_set_descriptor{ type = ip_v4, - value = "10.0.4.0/24"}}). + value = "10.0.4.0/24"}}). -define(UPDATE_RULE, #waf_rule_update{ @@ -57,7 +57,7 @@ predicate = #waf_rule_predicate{ data_id = ?CREATE_ID, negated = true, - type = ip_match}}). + type = ip_match}}). -define(UPDATE_SIZE_CONSTRAINT_SET, #waf_size_constraint_update{ @@ -86,7 +86,7 @@ action = block, priority = 1, rule_id = ?RULE_ID}}]}]). - + -define(UPDATE_XSS_MATCH_SET, #waf_xss_match_set_update{ action = insert, @@ -126,7 +126,7 @@ operation_test_() -> fun get_web_acl_tests/1, fun get_sampled_requests_tests/1, fun get_xss_match_set_tests/1, - + fun list_byte_match_sets_tests/1, fun list_ip_sets_tests/1, fun list_rules_tests/1, @@ -311,7 +311,7 @@ get_change_token_status_tests(_) -> PostData = jsx:encode([{<<"ChangeToken">>, ?CHANGE_TOKEN}]), Response = [{<<"ChangeTokenStatus">>, <<"INSYNC">>}], all_tests(Action, Function, PostData, Response). - + get_byte_match_set_tests(_) -> Action = "GetByteMatchSet", Function = ?_f(erlcloud_waf:get_byte_match_set(?CREATE_ID)), @@ -567,7 +567,7 @@ update_web_acl_tests(_) -> {<<"RuleId">>, ?RULE_ID}]}]]}]), Response = [{<<"ChangeToken">>, ?CHANGE_TOKEN}], all_tests(Action, Function, PostData, Response). - + update_xss_match_set_tests(_) -> Action = "UpdateXssMatchSet", Function = ?_f(erlcloud_waf:update_xss_match_set(?CHANGE_TOKEN, ?CREATE_ID, [?UPDATE_XSS_MATCH_SET])), @@ -608,8 +608,8 @@ sort_json(V) -> %% verifies that the parameters in the body match the expected parameters -spec validate_body(binary(), expected_body()) -> ok. validate_body(Body, Expected) -> - Want = sort_json(jsx:decode(Expected)), - Actual = sort_json(jsx:decode(Body)), + Want = sort_json(jsx:decode(Expected, [{return_maps, false}])), + Actual = sort_json(jsx:decode(Body, [{return_maps, false}])), case Want =:= Actual of true -> ok; false -> @@ -694,6 +694,6 @@ all_tests(Action, Function, PostData, Response) -> jsx:encode(Response), {ok, Response}} )], - + input_tests(<<>>, InputTests) ++ output_tests(Function, OutputTests).