From 3a89b1f00b3851b4a2af1bf3c1a89a33495a37e5 Mon Sep 17 00:00:00 2001 From: JianBo He Date: Mon, 31 May 2021 15:08:52 +0800 Subject: [PATCH] chore(action): fix syntax error (#4885) --- .github/workflows/run_test_cases.yaml | 2 +- apps/emqx_coap/test/emqx_coap_SUITE.erl | 12 ++++++------ .../emqx_coap/test/emqx_coap_pubsub_SUITE.erl | 18 +++++++++--------- apps/emqx_exhook/src/emqx_exhook.app.src | 2 +- apps/emqx_exhook/src/emqx_exhook.appup.src | 15 +++++++++++++++ apps/emqx_lwm2m/test/emqx_lwm2m_SUITE.erl | 11 +++++++---- src/emqx.app.src | 2 +- src/emqx.appup.src | 18 +++++++++++++----- src/emqx_http_lib.erl | 19 +++++++++---------- test/emqx_http_lib_tests.erl | 10 ++++++++++ 10 files changed, 72 insertions(+), 37 deletions(-) create mode 100644 apps/emqx_exhook/src/emqx_exhook.appup.src diff --git a/.github/workflows/run_test_cases.yaml b/.github/workflows/run_test_cases.yaml index 07afdcde2..d5a4a021e 100644 --- a/.github/workflows/run_test_cases.yaml +++ b/.github/workflows/run_test_cases.yaml @@ -130,7 +130,7 @@ jobs: docker exec --env-file .env -i erlang bash -c "make coveralls" - name: cat rebar.crashdump if: failure() - run: if [ -f 'rebar3.crashdump' ];then cat 'rebar3.crashdump' fi + run: if [ -f 'rebar3.crashdump' ];then cat 'rebar3.crashdump'; fi - uses: actions/upload-artifact@v1 if: failure() with: diff --git a/apps/emqx_coap/test/emqx_coap_SUITE.erl b/apps/emqx_coap/test/emqx_coap_SUITE.erl index 444bcc064..440b80ebd 100644 --- a/apps/emqx_coap/test/emqx_coap_SUITE.erl +++ b/apps/emqx_coap/test/emqx_coap_SUITE.erl @@ -120,7 +120,7 @@ t_observe_acl_deny(_Config) -> ok = meck:unload(emqx_access_control). t_observe_wildcard(_Config) -> - Topic = <<"+/b">>, TopicStr = http_uri:encode(binary_to_list(Topic)), + Topic = <<"+/b">>, TopicStr = emqx_http_lib:uri_encode(binary_to_list(Topic)), Payload = <<"123">>, Uri = "coap://127.0.0.1/mqtt/"++TopicStr++"?c=client1&u=tom&p=secret", {ok, Pid, N, Code, Content} = er_coap_observer:observe(Uri), @@ -143,7 +143,7 @@ t_observe_wildcard(_Config) -> [] = emqx:subscribers(Topic). t_observe_pub(_Config) -> - Topic = <<"+/b">>, TopicStr = http_uri:encode(binary_to_list(Topic)), + Topic = <<"+/b">>, TopicStr = emqx_http_lib:uri_encode(binary_to_list(Topic)), Uri = "coap://127.0.0.1/mqtt/"++TopicStr++"?c=client1&u=tom&p=secret", {ok, Pid, N, Code, Content} = er_coap_observer:observe(Uri), ?LOGT("observer Pid=~p, N=~p, Code=~p, Content=~p", [Pid, N, Code, Content]), @@ -152,7 +152,7 @@ t_observe_pub(_Config) -> ?assert(is_pid(SubPid)), Topic2 = <<"a/b">>, Payload2 = <<"UFO">>, - TopicStr2 = http_uri:encode(binary_to_list(Topic2)), + TopicStr2 = emqx_http_lib:uri_encode(binary_to_list(Topic2)), URI2 = "coap://127.0.0.1/mqtt/"++TopicStr2++"?c=client1&u=tom&p=secret", Reply2 = er_coap_client:request(put, URI2, #coap_content{format = <<"application/octet-stream">>, payload = Payload2}), @@ -164,7 +164,7 @@ t_observe_pub(_Config) -> ?assertEqual(Payload2, PayloadRecv2), Topic3 = <<"j/b">>, Payload3 = <<"ET629">>, - TopicStr3 = http_uri:encode(binary_to_list(Topic3)), + TopicStr3 = emqx_http_lib:uri_encode(binary_to_list(Topic3)), URI3 = "coap://127.0.0.1/mqtt/"++TopicStr3++"?c=client2&u=mike&p=guess", Reply3 = er_coap_client:request(put, URI3, #coap_content{format = <<"application/octet-stream">>, payload = Payload3}), {ok,changed, _} = Reply3, @@ -186,7 +186,7 @@ t_one_clientid_sub_2_topics(_Config) -> [SubPid] = emqx:subscribers(Topic1), ?assert(is_pid(SubPid)), - Topic2 = <<"x/y">>, TopicStr2 = http_uri:encode(binary_to_list(Topic2)), + Topic2 = <<"x/y">>, TopicStr2 = emqx_http_lib:uri_encode(binary_to_list(Topic2)), Payload2 = <<"456">>, Uri2 = "coap://127.0.0.1/mqtt/"++TopicStr2++"?c=client1&u=tom&p=secret", {ok, Pid2, N2, Code2, Content2} = er_coap_observer:observe(Uri2), @@ -217,7 +217,7 @@ t_invalid_parameter(_Config) -> %% "cid=client2" is invaid %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Topic3 = <<"a/b">>, Payload3 = <<"ET629">>, - TopicStr3 = http_uri:encode(binary_to_list(Topic3)), + TopicStr3 = emqx_http_lib:uri_encode(binary_to_list(Topic3)), URI3 = "coap://127.0.0.1/mqtt/"++TopicStr3++"?cid=client2&u=tom&p=simple", Reply3 = er_coap_client:request(put, URI3, #coap_content{format = <<"application/octet-stream">>, payload = Payload3}), ?assertMatch({error,bad_request}, Reply3), diff --git a/apps/emqx_coap/test/emqx_coap_pubsub_SUITE.erl b/apps/emqx_coap/test/emqx_coap_pubsub_SUITE.erl index 1aaf6cb69..c018b9165 100644 --- a/apps/emqx_coap/test/emqx_coap_pubsub_SUITE.erl +++ b/apps/emqx_coap/test/emqx_coap_pubsub_SUITE.erl @@ -173,7 +173,7 @@ t_case01_publish_post(_Config) -> ?assertEqual(<<"42">>, CT2), %% post to publish message to topic maintopic/topic1 - FullTopicStr = http_uri:encode(binary_to_list(FullTopic)), + FullTopicStr = emqx_http_lib:uri_encode(binary_to_list(FullTopic)), URI2 = "coap://127.0.0.1/ps/"++FullTopicStr++"?c=client1&u=tom&p=secret", PubPayload = <<"PUBLISH">>, @@ -286,7 +286,7 @@ t_case01_publish_put(_Config) -> ?assertEqual(<<"42">>, CT2), %% put to publish message to topic maintopic/topic1 - FullTopicStr = http_uri:encode(binary_to_list(FullTopic)), + FullTopicStr = emqx_http_lib:uri_encode(binary_to_list(FullTopic)), URI2 = "coap://127.0.0.1/ps/"++FullTopicStr++"?c=client1&u=tom&p=secret", PubPayload = <<"PUBLISH">>, @@ -430,7 +430,7 @@ t_case01_subscribe(_Config) -> t_case02_subscribe(_Config) -> Topic = <<"a/b">>, TopicStr = binary_to_list(Topic), - PercentEncodedTopic = http_uri:encode(TopicStr), + PercentEncodedTopic = emqx_http_lib:uri_encode(TopicStr), Payload = <<"payload">>, %% post to publish a new topic "a/b", and the topic is created @@ -477,7 +477,7 @@ t_case03_subscribe(_Config) -> %% Subscribe to the unexisted topic "a/b", got not_found Topic = <<"a/b">>, TopicStr = binary_to_list(Topic), - PercentEncodedTopic = http_uri:encode(TopicStr), + PercentEncodedTopic = emqx_http_lib:uri_encode(TopicStr), Uri = "coap://127.0.0.1/ps/"++PercentEncodedTopic++"?c=client1&u=tom&p=secret", {error, not_found} = er_coap_observer:observe(Uri), @@ -487,7 +487,7 @@ t_case04_subscribe(_Config) -> %% Subscribe to the wildcad topic "+/b", got bad_request Topic = <<"+/b">>, TopicStr = binary_to_list(Topic), - PercentEncodedTopic = http_uri:encode(TopicStr), + PercentEncodedTopic = emqx_http_lib:uri_encode(TopicStr), Uri = "coap://127.0.0.1/ps/"++PercentEncodedTopic++"?c=client1&u=tom&p=secret", {error, bad_request} = er_coap_observer:observe(Uri), @@ -582,7 +582,7 @@ t_case04_read(_Config) -> t_case05_read(_Config) -> Topic = <<"a/b">>, TopicStr = binary_to_list(Topic), - PercentEncodedTopic = http_uri:encode(TopicStr), + PercentEncodedTopic = emqx_http_lib:uri_encode(TopicStr), Payload = <<"payload">>, %% post to publish a new topic "a/b", and the topic is created @@ -609,7 +609,7 @@ t_case05_read(_Config) -> t_case01_delete(_Config) -> TopicInPayload = <<"a/b">>, TopicStr = binary_to_list(TopicInPayload), - PercentEncodedTopic = http_uri:encode(TopicStr), + PercentEncodedTopic = emqx_http_lib:uri_encode(TopicStr), Payload = list_to_binary("<"++PercentEncodedTopic++">;ct=42"), URI = "coap://127.0.0.1/ps/"++"?c=client1&u=tom&p=secret", @@ -621,7 +621,7 @@ t_case01_delete(_Config) -> %% Client post to CREATE topic "a/b/c" TopicInPayload1 = <<"a/b/c">>, - PercentEncodedTopic1 = http_uri:encode(binary_to_list(TopicInPayload1)), + PercentEncodedTopic1 = emqx_http_lib:uri_encode(binary_to_list(TopicInPayload1)), Payload1 = list_to_binary("<"++PercentEncodedTopic1++">;ct=42"), Reply1 = er_coap_client:request(post, URI, #coap_content{format = <<"application/link-format">>, payload = Payload1}), ?LOGT("Reply =~p", [Reply1]), @@ -643,7 +643,7 @@ t_case01_delete(_Config) -> t_case02_delete(_Config) -> TopicInPayload = <<"a/b">>, TopicStr = binary_to_list(TopicInPayload), - PercentEncodedTopic = http_uri:encode(TopicStr), + PercentEncodedTopic = emqx_http_lib:uri_encode(TopicStr), %% DELETE the unexisted topic "a/b" Uri1 = "coap://127.0.0.1/ps/"++PercentEncodedTopic++"?c=client1&u=tom&p=secret", diff --git a/apps/emqx_exhook/src/emqx_exhook.app.src b/apps/emqx_exhook/src/emqx_exhook.app.src index 555243107..452d2a742 100644 --- a/apps/emqx_exhook/src/emqx_exhook.app.src +++ b/apps/emqx_exhook/src/emqx_exhook.app.src @@ -1,6 +1,6 @@ {application, emqx_exhook, [{description, "EMQ X Extension for Hook"}, - {vsn, "4.3.0"}, + {vsn, "4.3.1"}, {modules, []}, {registered, []}, {mod, {emqx_exhook_app, []}}, diff --git a/apps/emqx_exhook/src/emqx_exhook.appup.src b/apps/emqx_exhook/src/emqx_exhook.appup.src new file mode 100644 index 000000000..2811c1554 --- /dev/null +++ b/apps/emqx_exhook/src/emqx_exhook.appup.src @@ -0,0 +1,15 @@ +%% -*-: erlang -*- +{VSN, + [ + {"4.3.0", [ + {load_module, emqx_exhook_pb, brutal_purge, soft_purge, []} + ]}, + {<<".*">>, []} + ], + [ + {"4.3.0", [ + {load_module, emqx_exhook_pb, brutal_purge, soft_purge, []} + ]}, + {<<".*">>, []} + ] +}. diff --git a/apps/emqx_lwm2m/test/emqx_lwm2m_SUITE.erl b/apps/emqx_lwm2m/test/emqx_lwm2m_SUITE.erl index 2cfb745bf..257502f2f 100644 --- a/apps/emqx_lwm2m/test/emqx_lwm2m_SUITE.erl +++ b/apps/emqx_lwm2m/test/emqx_lwm2m_SUITE.erl @@ -1886,8 +1886,11 @@ std_register(UdpSock, Epn, ObjectList, MsgId1, RespTopic) -> timer:sleep(100). resolve_uri(Uri) -> - {ok, {Scheme, _UserInfo, Host, PortNo, Path, Query}} = - http_uri:parse(Uri, [{scheme_defaults, [{coap, ?DEFAULT_COAP_PORT}, {coaps, ?DEFAULT_COAPS_PORT}]}]), + {ok, #{scheme := Scheme, + host := Host, + port := PortNo, + path := Path} = URIMap} = emqx_http_lib:uri_parse(Uri), + Query = maps:get(query, URIMap, ""), {ok, PeerIP} = inet:getaddr(Host, inet), {Scheme, {PeerIP, PortNo}, split_path(Path), split_query(Query)}. @@ -1896,7 +1899,7 @@ split_path([$/]) -> []; split_path([$/ | Path]) -> split_segments(Path, $/, []). split_query([]) -> []; -split_query([$? | Path]) -> split_segments(Path, $&, []). +split_query(Path) -> split_segments(Path, $&, []). split_segments(Path, Char, Acc) -> case string:rchr(Path, Char) of @@ -1908,7 +1911,7 @@ split_segments(Path, Char, Acc) -> end. make_segment(Seg) -> - list_to_binary(http_uri:decode(Seg)). + list_to_binary(emqx_http_lib:uri_decode(Seg)). get_coap_path(Options) -> diff --git a/src/emqx.app.src b/src/emqx.app.src index b195d7a1b..884c511df 100644 --- a/src/emqx.app.src +++ b/src/emqx.app.src @@ -1,7 +1,7 @@ {application, emqx, [{id, "emqx"}, {description, "EMQ X"}, - {vsn, "4.3.2"}, % strict semver, bump manually! + {vsn, "4.3.3"}, % strict semver, bump manually! {modules, []}, {registered, []}, {applications, [kernel,stdlib,gproc,gen_rpc,esockd,cowboy,sasl,os_mon]}, diff --git a/src/emqx.appup.src b/src/emqx.appup.src index 69c6e882c..98fa9ece2 100644 --- a/src/emqx.appup.src +++ b/src/emqx.appup.src @@ -1,6 +1,9 @@ %% -*- mode: erlang -*- {VSN, [ + {"4.3.2", [ + {load_module, emqx_http_lib, brutal_purge, soft_purge, []} + ]}, {"4.3.1", [ {load_module, emqx_ws_connection, brutal_purge, soft_purge, []}, {load_module, emqx_connection, brutal_purge, soft_purge, []}, @@ -11,7 +14,8 @@ {load_module, emqx_channel, brutal_purge, soft_purge, []}, {load_module, emqx_app, brutal_purge, soft_purge, []}, {load_module, emqx_plugins, brutal_purge, soft_purge, []}, - {load_module, emqx_logger_textfmt, brutal_purge, soft_purge, []} + {load_module, emqx_logger_textfmt, brutal_purge, soft_purge, []}, + {load_module, emqx_http_lib, brutal_purge, soft_purge, []} ]}, {"4.3.0", [ {load_module, emqx_logger_jsonfmt, brutal_purge, soft_purge, []}, @@ -26,13 +30,16 @@ {load_module, emqx_app, brutal_purge, soft_purge, []}, {load_module, emqx_plugins, brutal_purge, soft_purge, []}, {load_module, emqx_logger_textfmt, brutal_purge, soft_purge, []}, - %% {load_module, emqx_metrics, brutal_purge, soft_purge, []}, - {apply, {emqx_metrics, upgrade_retained_delayed_counter_type, []}} + {apply, {emqx_metrics, upgrade_retained_delayed_counter_type, []}}, + {load_module, emqx_http_lib, brutal_purge, soft_purge, []} ]}, {<<".*">>, []} ], [ + {"4.3.2", [ + {load_module, emqx_http_lib, brutal_purge, soft_purge, []} + ]}, {"4.3.1", [ {load_module, emqx_ws_connection, brutal_purge, soft_purge, []}, {load_module, emqx_connection, brutal_purge, soft_purge, []}, @@ -43,7 +50,8 @@ {load_module, emqx_channel, brutal_purge, soft_purge, []}, {load_module, emqx_app, brutal_purge, soft_purge, []}, {load_module, emqx_plugins, brutal_purge, soft_purge, []}, - {load_module, emqx_logger_textfmt, brutal_purge, soft_purge, []} + {load_module, emqx_logger_textfmt, brutal_purge, soft_purge, []}, + {load_module, emqx_http_lib, brutal_purge, soft_purge, []} ]}, {"4.3.0", [ {load_module, emqx_logger_jsonfmt, brutal_purge, soft_purge, []}, @@ -61,7 +69,7 @@ %% Just load the module. We don't need to change the 'messages.retained' %% and 'messages.retained' counter type. {load_module, emqx_metrics, brutal_purge, soft_purge, []}, - {apply, {emqx_metrics, upgrade_retained_delayed_counter_type, []}} + {load_module, emqx_http_lib, brutal_purge, soft_purge, []} ]}, {<<".*">>, []} ] diff --git a/src/emqx_http_lib.erl b/src/emqx_http_lib.erl index 60f19e6bb..893c260ee 100644 --- a/src/emqx_http_lib.erl +++ b/src/emqx_http_lib.erl @@ -108,11 +108,7 @@ normalise_headers(Headers0) -> [{K, proplists:get_value(K, Headers)} || K <- Keys]. normalise_parse_result(#{host := Host, scheme := Scheme0} = Map) -> - Scheme = atom_scheme(Scheme0), - DefaultPort = case https =:= Scheme of - true -> 443; - false -> 80 - end, + {Scheme, DefaultPort} = atom_scheme_and_default_port(Scheme0), Port = case maps:get(port, Map, undefined) of N when is_number(N) -> N; _ -> DefaultPort @@ -122,11 +118,14 @@ normalise_parse_result(#{host := Host, scheme := Scheme0} = Map) -> , port => Port }. -%% NOTE: so far we only support http schemes. -atom_scheme(Scheme) when is_list(Scheme) -> atom_scheme(list_to_binary(Scheme)); -atom_scheme(<<"https">>) -> https; -atom_scheme(<<"http">>) -> http; -atom_scheme(Other) -> throw({unsupported_scheme, Other}). +%% NOTE: so far we only support http/coap schemes. +atom_scheme_and_default_port(Scheme) when is_list(Scheme) -> + atom_scheme_and_default_port(list_to_binary(Scheme)); +atom_scheme_and_default_port(<<"http">> ) -> {http, 80}; +atom_scheme_and_default_port(<<"https">>) -> {https, 443}; +atom_scheme_and_default_port(<<"coap">> ) -> {coap, 5683}; +atom_scheme_and_default_port(<<"coaps">>) -> {coaps, 5684}; +atom_scheme_and_default_port(Other) -> throw({unsupported_scheme, Other}). do_uri_encode(Char) -> case reserved(Char) of diff --git a/test/emqx_http_lib_tests.erl b/test/emqx_http_lib_tests.erl index a850da8f5..7bcb7d056 100644 --- a/test/emqx_http_lib_tests.erl +++ b/test/emqx_http_lib_tests.erl @@ -66,6 +66,16 @@ uri_parse_test_() -> emqx_http_lib:uri_parse("HTTPS://127.0.0.1")) end } + , {"coap default port", + fun() -> ?assertMatch({ok, #{scheme := coap, port := 5683}}, + emqx_http_lib:uri_parse("coap://127.0.0.1")) + end + } + , {"coaps default port", + fun() -> ?assertMatch({ok, #{scheme := coaps, port := 5684}}, + emqx_http_lib:uri_parse("coaps://127.0.0.1")) + end + } , {"unsupported_scheme", fun() -> ?assertEqual({error, {unsupported_scheme, <<"wss">>}}, emqx_http_lib:uri_parse("wss://127.0.0.1"))