JianBo He 4 лет назад
Родитель
Сommit
d0bdf27e0c

+ 9 - 4
apps/emqx/src/emqx_schema.erl

@@ -75,6 +75,8 @@
 -export([server_ssl_opts_schema/2, client_ssl_opts_schema/1, ciphers_schema/1, default_ciphers/1]).
 -export([sc/2, map/2]).
 
+-elvis([{elvis_style, god_modules, disable}]).
+
 namespace() -> undefined.
 
 roots() ->
@@ -898,7 +900,8 @@ fields("alarm") ->
 Currently supports two actions, 'log' and 'publish'.
 'log' is to write the alarm to log (console or file).
 'publish' is to publish the alarm as an MQTT message to the system topics:
-<code>$SYS/brokers/emqx@xx.xx.xx.x/alarms/activate</code> and <code>$SYS/brokers/emqx@xx.xx.xx.x/alarms/deactivate</code>"""
+<code>$SYS/brokers/emqx@xx.xx.xx.x/alarms/activate</code> and
+<code>$SYS/brokers/emqx@xx.xx.xx.x/alarms/deactivate</code>"""
            })
       }
     , {"size_limit",
@@ -916,8 +919,9 @@ When this limit is exceeded, the oldest deactivated alarms are deleted to cap th
           #{ default => "24h",
              example => "24h",
              desc =>
-             """Retention time of deactivated alarms. Alarms are not deleted immediately when deactivated, but after the retention time.
-             """
+"""Retention time of deactivated alarms. Alarms are not deleted immediately
+when deactivated, but after the retention time.
+"""
            })
       }
     ].
@@ -1181,7 +1185,8 @@ default_tls_vsns(dtls_all_available) ->
 default_tls_vsns(tls_all_available) ->
     emqx_tls_lib:default_versions().
 
--spec ciphers_schema(quic | dtls_all_available | tls_all_available | undefined) -> hocon_schema:field_schema().
+-spec ciphers_schema(quic | dtls_all_available | tls_all_available | undefined)
+    -> hocon_schema:field_schema().
 ciphers_schema(Default) ->
     sc(hoconsc:array(string()),
        #{ default => default_ciphers(Default)

+ 3 - 1
apps/emqx_authz/test/emqx_authz_SUITE.erl

@@ -149,7 +149,9 @@ t_update_source(_) ->
     {ok, _} = emqx_authz:update(?CMD_REPLACE, []).
 
 t_move_source(_) ->
-    {ok, _} = emqx_authz:update(?CMD_REPLACE, [?SOURCE1, ?SOURCE2, ?SOURCE3, ?SOURCE4, ?SOURCE5, ?SOURCE6]),
+    {ok, _} = emqx_authz:update(?CMD_REPLACE,
+                                [?SOURCE1, ?SOURCE2, ?SOURCE3,
+                                 ?SOURCE4, ?SOURCE5, ?SOURCE6]),
     ?assertMatch([ #{type := http}
                  , #{type := mongodb}
                  , #{type := mysql}

+ 3 - 2
apps/emqx_authz/test/emqx_authz_api_mnesia_SUITE.erl

@@ -26,7 +26,6 @@
 -define(API_VERSION, "v5").
 -define(BASE_PATH, "api").
 
-
 all() ->
     emqx_common_test_helpers:all(?MODULE).
 
@@ -82,7 +81,9 @@ t_api(_) ->
                , uri(["authorization", "sources", "built-in-database", "username", "user1"])
                , []),
     #{<<"data">> := [#{<<"username">> := <<"user1">>, <<"rules">> := Rules1}],
-      <<"meta">> := #{<<"count">> := 1,<<"limit">> := 100,<<"page">> := 1}} = jsx:decode(Request1),
+      <<"meta">> := #{<<"count">> := 1,
+                      <<"limit">> := 100,
+                      <<"page">> := 1}} = jsx:decode(Request1),
     #{<<"username">> := <<"user1">>, <<"rules">> := Rules1} = jsx:decode(Request2),
     ?assertEqual(3, length(Rules1)),
 

+ 2 - 2
apps/emqx_authz/test/emqx_authz_api_settings_SUITE.erl

@@ -36,11 +36,11 @@ init_per_suite(Config) ->
     ok = emqx_common_test_helpers:start_apps(
            [emqx_conf, emqx_authz, emqx_dashboard],
            fun set_special_configs/1),
-
     Config.
 
 end_per_suite(_Config) ->
-    emqx_common_test_helpers:stop_apps([emqx_authz, emqx_dashboard]),
+    {ok, _} = emqx_authz:update(replace, []),
+    emqx_common_test_helpers:stop_apps([emqx_dashboard, emqx_authz, emqx_conf]),
     ok.
 
 set_special_configs(emqx_dashboard) ->

+ 38 - 18
apps/emqx_authz/test/emqx_authz_api_sources_SUITE.erl

@@ -81,7 +81,9 @@
                   }).
 -define(SOURCE6, #{<<"type">> => <<"file">>,
                    <<"enable">> => true,
-                   <<"rules">> => <<"{allow,{username,\"^dashboard?\"},subscribe,[\"$SYS/#\"]}.\n{allow,{ipaddr,\"127.0.0.1\"},all,[\"$SYS/#\",\"#\"]}.">>
+                   <<"rules">> =>
+<<"{allow,{username,\"^dashboard?\"},subscribe,[\"$SYS/#\"]}."
+  "\n{allow,{ipaddr,\"127.0.0.1\"},all,[\"$SYS/#\",\"#\"]}.">>
                   }).
 
 all() ->
@@ -94,9 +96,10 @@ groups() ->
 init_per_suite(Config) ->
     meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
     meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end),
-    meck:expect(emqx_resource, create_dry_run, fun(emqx_connector_mysql, _) -> {ok, meck_data}; 
-                                                  (T, C) -> meck:passthrough([T, C])
-                                               end),
+    meck:expect(emqx_resource, create_dry_run,
+                fun(emqx_connector_mysql, _) -> {ok, meck_data};
+                   (T, C) -> meck:passthrough([T, C])
+                end),
     meck:expect(emqx_resource, update, fun(_, _, _, _) -> {ok, meck_data} end),
     meck:expect(emqx_resource, health_check, fun(_) -> ok end),
     meck:expect(emqx_resource, remove, fun(_) -> ok end ),
@@ -136,10 +139,11 @@ init_per_testcase(t_api, Config) ->
     meck:expect(emqx_misc, gen_id, fun() -> "fake" end),
 
     meck:new(emqx, [non_strict, passthrough, no_history, no_link]),
-    meck:expect(emqx, data_dir, fun() ->
-                                        {data_dir, Data} = lists:keyfind(data_dir, 1, Config),
-                                        Data
-                                end),
+    meck:expect(emqx, data_dir,
+                fun() ->
+                    {data_dir, Data} = lists:keyfind(data_dir, 1, Config),
+                    Data
+                end),
     Config;
 init_per_testcase(_, Config) -> Config.
 
@@ -157,7 +161,8 @@ t_api(_) ->
     {ok, 200, Result1} = request(get, uri(["authorization", "sources"]), []),
     ?assertEqual([], get_sources(Result1)),
 
-    {ok, 204, _} = request(put, uri(["authorization", "sources"]), [?SOURCE2, ?SOURCE3, ?SOURCE4, ?SOURCE5, ?SOURCE6]),
+    {ok, 204, _} = request(put, uri(["authorization", "sources"]),
+                           [?SOURCE2, ?SOURCE3, ?SOURCE4, ?SOURCE5, ?SOURCE6]),
     {ok, 204, _} = request(post, uri(["authorization", "sources"]), ?SOURCE1),
 
     {ok, 200, Result2} = request(get, uri(["authorization", "sources"]), []),
@@ -171,7 +176,8 @@ t_api(_) ->
                  ], Sources),
     ?assert(filelib:is_file(emqx_authz:acl_conf_file())),
 
-    {ok, 204, _} = request(put, uri(["authorization", "sources", "http"]),  ?SOURCE1#{<<"enable">> := false}),
+    {ok, 204, _} = request(put, uri(["authorization", "sources", "http"]),
+                           ?SOURCE1#{<<"enable">> := false}),
     {ok, 200, Result3} = request(get, uri(["authorization", "sources", "http"]), []),
     ?assertMatch(#{<<"type">> := <<"http">>, <<"enable">> := false}, jsx:decode(Result3)),
 
@@ -196,14 +202,28 @@ t_api(_) ->
     ?assert(filelib:is_file(filename:join([data_dir(), "certs", "cert-fake.pem"]))),
     ?assert(filelib:is_file(filename:join([data_dir(), "certs", "key-fake.pem"]))),
 
-    {ok, 204, _} = request(put, uri(["authorization", "sources", "mysql"]),  ?SOURCE3#{<<"server">> := <<"192.168.1.100:3306">>}),
-
-    {ok, 400, _} = request(put, uri(["authorization", "sources", "postgresql"]),  ?SOURCE4#{<<"server">> := <<"fake">>}),
-    {ok, 400, _} = request(put, uri(["authorization", "sources", "redis"]),  ?SOURCE5#{<<"servers">> := [<<"192.168.1.100:6379">>, <<"192.168.1.100:6380">>]}),
-
-    lists:foreach(fun(#{<<"type">> := Type}) ->
-                    {ok, 204, _} = request(delete, uri(["authorization", "sources", binary_to_list(Type)]), [])
-                  end, Sources),
+    {ok, 204, _} = request(
+                     put,
+                     uri(["authorization", "sources", "mysql"]),
+                     ?SOURCE3#{<<"server">> := <<"192.168.1.100:3306">>}),
+
+    {ok, 400, _} = request(
+                     put,
+                     uri(["authorization", "sources", "postgresql"]),
+                     ?SOURCE4#{<<"server">> := <<"fake">>}),
+    {ok, 400, _} = request(
+                     put,
+                     uri(["authorization", "sources", "redis"]),
+                     ?SOURCE5#{<<"servers">> := [<<"192.168.1.100:6379">>,
+                                                 <<"192.168.1.100:6380">>]}),
+
+    lists:foreach(
+      fun(#{<<"type">> := Type}) ->
+        {ok, 204, _} = request(
+                         delete,
+                         uri(["authorization", "sources", binary_to_list(Type)]),
+                         [])
+      end, Sources),
     {ok, 200, Result5} = request(get, uri(["authorization", "sources"]), []),
     ?assertEqual([], get_sources(Result5)),
     ?assertEqual([], emqx:get_config([authorization, sources])),

+ 14 - 8
apps/emqx_authz/test/emqx_authz_mnesia_SUITE.erl

@@ -92,13 +92,19 @@ t_authz(_) ->
                     listener => {tcp, default}
                    },
 
-    ?assertEqual(deny, emqx_access_control:authorize(ClientInfo1, subscribe, <<"#">>)),
-    ?assertEqual(deny, emqx_access_control:authorize(ClientInfo1, publish, <<"#">>)),
-
-    ?assertEqual(allow, emqx_access_control:authorize(ClientInfo2, publish, <<"test/test_username">>)),
-    ?assertEqual(allow, emqx_access_control:authorize(ClientInfo2, subscribe, <<"#">>)),
-
-    ?assertEqual(allow, emqx_access_control:authorize(ClientInfo3, publish, <<"test/test_clientid">>)),
-    ?assertEqual(deny,  emqx_access_control:authorize(ClientInfo3, subscribe, <<"#">>)),
+    ?assertEqual(deny, emqx_access_control:authorize(
+                         ClientInfo1, subscribe, <<"#">>)),
+    ?assertEqual(deny, emqx_access_control:authorize(
+                         ClientInfo1, publish, <<"#">>)),
+
+    ?assertEqual(allow, emqx_access_control:authorize(
+                          ClientInfo2, publish, <<"test/test_username">>)),
+    ?assertEqual(allow, emqx_access_control:authorize(
+                          ClientInfo2, subscribe, <<"#">>)),
+
+    ?assertEqual(allow, emqx_access_control:authorize(
+                          ClientInfo3, publish, <<"test/test_clientid">>)),
+    ?assertEqual(deny,  emqx_access_control:authorize(
+                          ClientInfo3, subscribe, <<"#">>)),
 
     ok.

+ 12 - 6
apps/emqx_authz/test/emqx_authz_mongodb_SUITE.erl

@@ -114,11 +114,17 @@ t_authz(_) ->
     ?assertEqual(deny, emqx_access_control:authorize(ClientInfo1, subscribe, <<"+">>)),
 
     meck:expect(emqx_resource, query, fun(_, _) -> ?SOURCE3 ++ ?SOURCE4 end),
-    ?assertEqual(allow, emqx_access_control:authorize(ClientInfo2, subscribe, <<"test/test_clientid">>)),
-    ?assertEqual(deny,  emqx_access_control:authorize(ClientInfo2, publish,   <<"test/test_clientid">>)),
-    ?assertEqual(deny,  emqx_access_control:authorize(ClientInfo2, subscribe, <<"test/test_username">>)),
-    ?assertEqual(allow, emqx_access_control:authorize(ClientInfo2, publish,   <<"test/test_username">>)),
-    ?assertEqual(deny,  emqx_access_control:authorize(ClientInfo3, subscribe, <<"test">>)), % nomatch
-    ?assertEqual(deny,  emqx_access_control:authorize(ClientInfo3, publish,   <<"test">>)), % nomatch
+    ?assertEqual(allow, emqx_access_control:authorize(
+                          ClientInfo2, subscribe, <<"test/test_clientid">>)),
+    ?assertEqual(deny,  emqx_access_control:authorize(
+                          ClientInfo2, publish,   <<"test/test_clientid">>)),
+    ?assertEqual(deny,  emqx_access_control:authorize(
+                          ClientInfo2, subscribe, <<"test/test_username">>)),
+    ?assertEqual(allow, emqx_access_control:authorize(
+                          ClientInfo2, publish,   <<"test/test_username">>)),
+    ?assertEqual(deny,  emqx_access_control:authorize(
+                          ClientInfo3, subscribe, <<"test">>)), % nomatch
+    ?assertEqual(deny,  emqx_access_control:authorize(
+                          ClientInfo3, publish,   <<"test">>)), % nomatch
     ok.
 

+ 12 - 6
apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl

@@ -112,11 +112,17 @@ t_authz(_) ->
     ?assertEqual(deny, emqx_access_control:authorize(ClientInfo1, subscribe, <<"+">>)),
 
     meck:expect(emqx_resource, query, fun(_, _) -> {ok, ?COLUMNS, ?SOURCE3 ++ ?SOURCE4} end),
-    ?assertEqual(allow, emqx_access_control:authorize(ClientInfo2, subscribe, <<"test/test_clientid">>)),
-    ?assertEqual(deny,  emqx_access_control:authorize(ClientInfo2, publish,   <<"test/test_clientid">>)),
-    ?assertEqual(deny,  emqx_access_control:authorize(ClientInfo2, subscribe, <<"test/test_username">>)),
-    ?assertEqual(allow, emqx_access_control:authorize(ClientInfo2, publish,   <<"test/test_username">>)),
-    ?assertEqual(deny,  emqx_access_control:authorize(ClientInfo3, subscribe, <<"test">>)), % nomatch
-    ?assertEqual(deny,  emqx_access_control:authorize(ClientInfo3, publish,   <<"test">>)), % nomatch
+    ?assertEqual(allow, emqx_access_control:authorize(
+                          ClientInfo2, subscribe, <<"test/test_clientid">>)),
+    ?assertEqual(deny,  emqx_access_control:authorize(
+                          ClientInfo2, publish,   <<"test/test_clientid">>)),
+    ?assertEqual(deny,  emqx_access_control:authorize(
+                          ClientInfo2, subscribe, <<"test/test_username">>)),
+    ?assertEqual(allow, emqx_access_control:authorize(
+                          ClientInfo2, publish,   <<"test/test_username">>)),
+    ?assertEqual(deny,  emqx_access_control:authorize(
+                          ClientInfo3, subscribe, <<"test">>)), % nomatch
+    ?assertEqual(deny,  emqx_access_control:authorize(
+                          ClientInfo3, publish,   <<"test">>)), % nomatch
     ok.
 

+ 12 - 6
apps/emqx_authz/test/emqx_authz_postgresql_SUITE.erl

@@ -110,11 +110,17 @@ t_authz(_) ->
     ?assertEqual(deny, emqx_access_control:authorize(ClientInfo2, subscribe, <<"+">>)),
 
     meck:expect(emqx_resource, query, fun(_, _) -> {ok, ?COLUMNS, ?SOURCE3 ++ ?SOURCE4} end),
-    ?assertEqual(allow, emqx_access_control:authorize(ClientInfo2, subscribe, <<"test/test_clientid">>)),
-    ?assertEqual(deny,  emqx_access_control:authorize(ClientInfo2, publish,   <<"test/test_clientid">>)),
-    ?assertEqual(deny,  emqx_access_control:authorize(ClientInfo2, subscribe, <<"test/test_username">>)),
-    ?assertEqual(allow, emqx_access_control:authorize(ClientInfo2, publish,   <<"test/test_username">>)),
-    ?assertEqual(deny,  emqx_access_control:authorize(ClientInfo3, subscribe, <<"test">>)), % nomatch
-    ?assertEqual(deny,  emqx_access_control:authorize(ClientInfo3, publish,   <<"test">>)), % nomatch
+    ?assertEqual(allow, emqx_access_control:authorize(
+                          ClientInfo2, subscribe, <<"test/test_clientid">>)),
+    ?assertEqual(deny,  emqx_access_control:authorize(
+                          ClientInfo2, publish,   <<"test/test_clientid">>)),
+    ?assertEqual(deny,  emqx_access_control:authorize(
+                          ClientInfo2, subscribe, <<"test/test_username">>)),
+    ?assertEqual(allow, emqx_access_control:authorize(
+                          ClientInfo2, publish,   <<"test/test_username">>)),
+    ?assertEqual(deny,  emqx_access_control:authorize(
+                          ClientInfo3, subscribe, <<"test">>)), % nomatch
+    ?assertEqual(deny,  emqx_access_control:authorize(
+                          ClientInfo3, publish,   <<"test">>)), % nomatch
     ok.
 

+ 47 - 26
apps/emqx_authz/test/emqx_authz_rule_SUITE.erl

@@ -26,7 +26,10 @@
 -define(SOURCE2, {allow, {ipaddr,  "127.0.0.1"}, all, [{eq, "#"}, {eq, "+"}]}).
 -define(SOURCE3, {allow, {ipaddrs, ["127.0.0.1", "192.168.1.0/24"]}, subscribe, ["%c"]}).
 -define(SOURCE4, {allow, {'and', [{client, "test"}, {user, "test"}]}, publish, ["topic/test"]}).
--define(SOURCE5, {allow, {'or',  [{username, {re, "^test"}},  {clientid, {re, "test?"}}]},  publish, ["%u", "%c"]}).
+-define(SOURCE5, {allow, {'or',
+                          [{username, {re, "^test"}},
+                           {clientid, {re, "test?"}}]},
+                  publish, ["%u", "%c"]}).
 
 all() ->
     emqx_common_test_helpers:all(?MODULE).
@@ -53,7 +56,8 @@ set_special_configs(_App) ->
 t_compile(_) ->
     ?assertEqual({deny, all, all, [['#']]}, emqx_authz_rule:compile(?SOURCE1)),
 
-    ?assertEqual({allow, {ipaddr, {{127,0,0,1}, {127,0,0,1}, 32}}, all, [{eq, ['#']}, {eq, ['+']}]}, emqx_authz_rule:compile(?SOURCE2)),
+    ?assertEqual({allow, {ipaddr, {{127,0,0,1}, {127,0,0,1}, 32}},
+                  all, [{eq, ['#']}, {eq, ['+']}]}, emqx_authz_rule:compile(?SOURCE2)),
 
     ?assertEqual({allow,
                   {ipaddrs,[{{127,0,0,1},{127,0,0,1},32},
@@ -69,9 +73,9 @@ t_compile(_) ->
                  }, emqx_authz_rule:compile(?SOURCE4)),
 
     ?assertMatch({allow,
-                  {'or', [{username, {re_pattern, _, _, _, _}}, {clientid, {re_pattern, _, _, _, _}}]},
-                  publish,
-                  [{pattern, [<<"%u">>]},  {pattern, [<<"%c">>]}]
+                  {'or', [{username, {re_pattern, _, _, _, _}},
+                          {clientid, {re_pattern, _, _, _, _}}]},
+                  publish, [{pattern, [<<"%u">>]},  {pattern, [<<"%c">>]}]
                  }, emqx_authz_rule:compile(?SOURCE5)),
     ok.
 
@@ -103,47 +107,64 @@ t_match(_) ->
                    },
 
     ?assertEqual({matched, deny},
-                emqx_authz_rule:match(ClientInfo1, subscribe, <<"#">>, emqx_authz_rule:compile(?SOURCE1))),
+                emqx_authz_rule:match(ClientInfo1, subscribe, <<"#">>,
+                                      emqx_authz_rule:compile(?SOURCE1))),
     ?assertEqual({matched, deny},
-                emqx_authz_rule:match(ClientInfo2, subscribe, <<"+">>, emqx_authz_rule:compile(?SOURCE1))),
+                emqx_authz_rule:match(ClientInfo2, subscribe, <<"+">>,
+                                      emqx_authz_rule:compile(?SOURCE1))),
     ?assertEqual({matched, deny},
-                emqx_authz_rule:match(ClientInfo3, subscribe, <<"topic/test">>, emqx_authz_rule:compile(?SOURCE1))),
+                emqx_authz_rule:match(ClientInfo3, subscribe, <<"topic/test">>,
+                                      emqx_authz_rule:compile(?SOURCE1))),
 
     ?assertEqual({matched, allow},
-                emqx_authz_rule:match(ClientInfo1, subscribe, <<"#">>, emqx_authz_rule:compile(?SOURCE2))),
+                emqx_authz_rule:match(ClientInfo1, subscribe, <<"#">>,
+                                      emqx_authz_rule:compile(?SOURCE2))),
     ?assertEqual(nomatch,
-                emqx_authz_rule:match(ClientInfo1, subscribe, <<"topic/test">>, emqx_authz_rule:compile(?SOURCE2))),
+                emqx_authz_rule:match(ClientInfo1, subscribe, <<"topic/test">>,
+                                      emqx_authz_rule:compile(?SOURCE2))),
     ?assertEqual(nomatch,
-                emqx_authz_rule:match(ClientInfo2, subscribe, <<"#">>, emqx_authz_rule:compile(?SOURCE2))),
+                emqx_authz_rule:match(ClientInfo2, subscribe, <<"#">>,
+                                      emqx_authz_rule:compile(?SOURCE2))),
 
     ?assertEqual({matched, allow},
-                emqx_authz_rule:match(ClientInfo1, subscribe, <<"test">>, emqx_authz_rule:compile(?SOURCE3))),
+                emqx_authz_rule:match(ClientInfo1, subscribe, <<"test">>,
+                                      emqx_authz_rule:compile(?SOURCE3))),
     ?assertEqual({matched, allow},
-                emqx_authz_rule:match(ClientInfo2, subscribe, <<"test">>, emqx_authz_rule:compile(?SOURCE3))),
+                emqx_authz_rule:match(ClientInfo2, subscribe, <<"test">>,
+                                      emqx_authz_rule:compile(?SOURCE3))),
     ?assertEqual(nomatch,
-                emqx_authz_rule:match(ClientInfo2, subscribe, <<"topic/test">>, emqx_authz_rule:compile(?SOURCE3))),
+                emqx_authz_rule:match(ClientInfo2, subscribe, <<"topic/test">>,
+                                      emqx_authz_rule:compile(?SOURCE3))),
 
     ?assertEqual({matched, allow},
-                emqx_authz_rule:match(ClientInfo1, publish, <<"topic/test">>, emqx_authz_rule:compile(?SOURCE4))),
+                emqx_authz_rule:match(ClientInfo1, publish, <<"topic/test">>,
+                                      emqx_authz_rule:compile(?SOURCE4))),
     ?assertEqual({matched, allow},
-                emqx_authz_rule:match(ClientInfo2, publish, <<"topic/test">>, emqx_authz_rule:compile(?SOURCE4))),
+                emqx_authz_rule:match(ClientInfo2, publish, <<"topic/test">>,
+                                      emqx_authz_rule:compile(?SOURCE4))),
     ?assertEqual(nomatch,
-                emqx_authz_rule:match(ClientInfo3, publish, <<"topic/test">>, emqx_authz_rule:compile(?SOURCE4))),
+                emqx_authz_rule:match(ClientInfo3, publish, <<"topic/test">>,
+                                      emqx_authz_rule:compile(?SOURCE4))),
     ?assertEqual(nomatch,
-                emqx_authz_rule:match(ClientInfo4, publish, <<"topic/test">>, emqx_authz_rule:compile(?SOURCE4))),
+                emqx_authz_rule:match(ClientInfo4, publish, <<"topic/test">>,
+                                      emqx_authz_rule:compile(?SOURCE4))),
 
     ?assertEqual({matched, allow},
-                emqx_authz_rule:match(ClientInfo1, publish, <<"test">>, emqx_authz_rule:compile(?SOURCE5))),
+                emqx_authz_rule:match(ClientInfo1, publish, <<"test">>,
+                                      emqx_authz_rule:compile(?SOURCE5))),
     ?assertEqual({matched, allow},
-                emqx_authz_rule:match(ClientInfo2, publish, <<"test">>, emqx_authz_rule:compile(?SOURCE5))),
+                emqx_authz_rule:match(ClientInfo2, publish, <<"test">>,
+                                      emqx_authz_rule:compile(?SOURCE5))),
     ?assertEqual({matched, allow},
-                emqx_authz_rule:match(ClientInfo3, publish, <<"test">>, emqx_authz_rule:compile(?SOURCE5))),
+                emqx_authz_rule:match(ClientInfo3, publish, <<"test">>,
+                                      emqx_authz_rule:compile(?SOURCE5))),
     ?assertEqual({matched, allow},
-                emqx_authz_rule:match(ClientInfo3, publish, <<"fake">>, emqx_authz_rule:compile(?SOURCE5))),
+                emqx_authz_rule:match(ClientInfo3, publish, <<"fake">>,
+                                      emqx_authz_rule:compile(?SOURCE5))),
     ?assertEqual({matched, allow},
-                emqx_authz_rule:match(ClientInfo4, publish, <<"test">>, emqx_authz_rule:compile(?SOURCE5))),
+                emqx_authz_rule:match(ClientInfo4, publish, <<"test">>,
+                                      emqx_authz_rule:compile(?SOURCE5))),
     ?assertEqual({matched, allow},
-                emqx_authz_rule:match(ClientInfo4, publish, <<"fake">>, emqx_authz_rule:compile(?SOURCE5))),
-
+                emqx_authz_rule:match(ClientInfo4, publish, <<"fake">>,
+                                      emqx_authz_rule:compile(?SOURCE5))),
     ok.
-

+ 5 - 4
apps/emqx_conf/src/emqx_conf_schema.erl

@@ -341,8 +341,9 @@ fields("cluster_call") ->
            })}
     , {"cleanup_interval",
        sc(emqx_schema:duration(),
-          #{  desc => "Time interval to clear completed but stale transactions.
-                         Ensure that the number of completed transactions is less than the max_history."
+          #{  desc =>
+"Time interval to clear completed but stale transactions.
+Ensure that the number of completed transactions is less than the max_history."
            ,  default => "5m"
            })}
     ];
@@ -505,7 +506,7 @@ fields("authorization") ->
 translations() -> ["ekka", "kernel", "emqx"].
 
 translation("ekka") ->
-    [ {"cluster_discovery", fun tr_cluster__discovery/1}];
+    [ {"cluster_discovery", fun tr_cluster_discovery/1}];
 translation("kernel") ->
     [ {"logger_level", fun tr_logger_level/1}
     , {"logger", fun tr_logger/1}];
@@ -540,7 +541,7 @@ tr_override_conf_file(Conf, Filename) ->
     [_ | _] = DataDir,
     filename:join([DataDir, "configs", Filename]).
 
-tr_cluster__discovery(Conf) ->
+tr_cluster_discovery(Conf) ->
     Strategy = conf_get("cluster.discovery_strategy", Conf),
     {Strategy, filter(options(Strategy, Conf))}.
 

+ 3 - 1
apps/emqx_gateway/src/emqx_gateway_schema.erl

@@ -45,6 +45,7 @@
               , comma_separated_list/0
               , ip_port/0
               ]).
+-elvis([{elvis_style, dont_repeat_yourself, disable}]).
 
 -export([namespace/0, roots/0 , fields/1]).
 
@@ -324,7 +325,8 @@ the LwM2M client"
        sc(ref(translator),
           #{ desc =>
 "The topic for gateway to publish the notify events from LwM2M client.<br>
-After succeed observe a resource of LwM2M client, Gateway will send the notifyevents via this topic, if the client reports any resource changes"
+After succeed observe a resource of LwM2M client, Gateway will send the
+notifyevents via this topic, if the client reports any resource changes"
            })}
     , {register,
        sc(ref(translator),

Разница между файлами не показана из-за своего большого размера
+ 818 - 660
apps/emqx_gateway/test/emqx_lwm2m_SUITE.erl


+ 21 - 10
apps/emqx_gateway/test/emqx_lwm2m_api_SUITE.erl

@@ -110,8 +110,11 @@ t_lookup_cmd_read(Config) ->
     test_send_coap_request( UdpSock,
                             post,
                             sprintf("coap://127.0.0.1:~b/rd?ep=~ts&lt=600&lwm2m=1", [?PORT, Epn]),
-                            #coap_content{content_format = <<"text/plain">>,
-                                          payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
+                            #coap_content{
+                               content_format = <<"text/plain">>,
+                               payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,"
+                                           "</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>
+                              },
                             [],
                             MsgId1),
     #coap_message{method = Method1} = test_recv_coap_response(UdpSock),
@@ -141,7 +144,14 @@ t_lookup_cmd_read(Config) ->
     ?LOGT("LwM2M client got ~p", [Request2]),
     timer:sleep(50),
 
-    test_send_coap_response(UdpSock, "127.0.0.1", ?PORT, {ok, content}, #coap_content{content_format = <<"text/plain">>, payload = <<"EMQ">>}, Request2, true),
+    test_send_coap_response(
+      UdpSock,
+      "127.0.0.1",
+      ?PORT,
+      {ok, content},
+      #coap_content{content_format = <<"text/plain">>, payload = <<"EMQ">>},
+      Request2,
+      true),
 
     timer:sleep(200),
     normal_received_request(Epn, <<"/3/0/0">>, <<"read">>).
@@ -177,13 +187,14 @@ t_lookup_cmd_discover(Config) ->
     timer:sleep(50),
 
     PayloadDiscover = <<"</3/0/7>;dim=8;pmin=10;pmax=60;gt=50;lt=42.2,</3/0/8>">>,
-    test_send_coap_response(UdpSock,
-                            "127.0.0.1",
-                            ?PORT,
-                            {ok, content},
-                            #coap_content{content_format = <<"application/link-format">>, payload = PayloadDiscover},
-                            Request2,
-                            true),
+    test_send_coap_response(
+      UdpSock,
+      "127.0.0.1",
+      ?PORT,
+      {ok, content},
+      #coap_content{content_format = <<"application/link-format">>, payload = PayloadDiscover},
+      Request2,
+      true),
     timer:sleep(200),
     discover_received_request(Epn, <<"/3/0/7">>, <<"discover">>).
 

+ 27 - 26
apps/emqx_gateway/test/emqx_stomp_SUITE.erl

@@ -87,35 +87,36 @@ t_connect(_) ->
 
     %% Connect will be failed, because of bad login or passcode
     %% FIXME: Waiting for authentication works
-    %with_connection(fun(Sock) ->
-    %                    gen_tcp:send(Sock, serialize(<<"CONNECT">>,
-    %                                                 [{<<"accept-version">>, ?STOMP_VER},
-    %                                                  {<<"host">>, <<"127.0.0.1:61613">>},
-    %                                                  {<<"login">>, <<"admin">>},
-    %                                                  {<<"passcode">>, <<"admin">>},
-    %                                                  {<<"heart-beat">>, <<"1000,2000">>}])),
-    %                    {ok, Data} = gen_tcp:recv(Sock, 0),
-    %                    {ok, #stomp_frame{command = <<"ERROR">>,
-    %                                      headers = _,
-    %                                      body    = <<"Login or passcode error!">>}, _, _} =
-    %                                                   parse(Data)
-    %                end),
+    %with_connection(
+    %    fun(Sock) ->
+    %        gen_tcp:send(Sock, serialize(<<"CONNECT">>,
+    %                                     [{<<"accept-version">>, ?STOMP_VER},
+    %                                      {<<"host">>, <<"127.0.0.1:61613">>},
+    %                                      {<<"login">>, <<"admin">>},
+    %                                      {<<"passcode">>, <<"admin">>},
+    %                                      {<<"heart-beat">>, <<"1000,2000">>}])),
+    %          {ok, Data} = gen_tcp:recv(Sock, 0),
+    %          {ok, Frame, _, _} = parse(Data),
+    %          #stomp_frame{command = <<"ERROR">>,
+    %                       headers = _,
+    %                       body    = <<"Login or passcode error!">>} = Frame
+    %      end),
 
     %% Connect will be failed, because of bad version
     with_connection(fun(Sock) ->
-        gen_tcp:send(Sock, serialize(<<"CONNECT">>,
-                                     [{<<"accept-version">>, <<"2.0,2.1">>},
-                                      {<<"host">>, <<"127.0.0.1:61613">>},
-                                      {<<"login">>, <<"guest">>},
-                                      {<<"passcode">>, <<"guest">>},
-                                      {<<"heart-beat">>, <<"1000,2000">>}])),
+        gen_tcp:send(Sock,
+                     serialize(<<"CONNECT">>,
+                               [{<<"accept-version">>, <<"2.0,2.1">>},
+                                {<<"host">>, <<"127.0.0.1:61613">>},
+                                {<<"login">>, <<"guest">>},
+                                {<<"passcode">>, <<"guest">>},
+                                {<<"heart-beat">>, <<"1000,2000">>}])),
         {ok, Data} = gen_tcp:recv(Sock, 0),
-        {ok,
-         #stomp_frame{command = <<"ERROR">>,
-                      headers = _,
-                      body    = <<"Login Failed: Supported protocol versions < 1.2">>},
-         _,
-         _ } = parse(Data)
+        {ok, Frame, _, _} = parse(Data),
+        #stomp_frame{
+           command = <<"ERROR">>,
+           headers = _,
+           body    = <<"Login Failed: Supported protocol versions < 1.2">>} = Frame
     end).
 
 t_heartbeat(_) ->
@@ -407,7 +408,7 @@ t_rest_clienit_info(_) ->
 
         %% kickout
         {204, _} = request(delete, ClientPath),
-        ignored = gen_server:call(?CM, ignore, infinity). % sync
+        ignored = gen_server:call(emqx_cm, ignore, infinity), % sync
         ok = emqx_pool:flush_async_tasks(),
         {200, Clients2} = request(get, "/gateway/stomp/clients"),
         ?assertEqual(0, length(maps:get(data, Clients2)))

+ 2 - 1
elvis.config

@@ -17,7 +17,8 @@
             {elvis_style, operator_spaces, #{rules => [{right, "|"},
                                                        {left, "|"},
                                                        {right, "||"},
-                                                       {left, "||"}]}}
+                                                       {left, "||"}]}},
+            {elvis_style, dont_repeat_yourself, #{ min_complexity => 20 }}
            ]
         },
       #{dirs => ["test", "apps/**/test"],