Przeglądaj źródła

chore: fix dialyzer error

Signed-off-by: zhanghongtong <rory-z@outlook.com>
Rory Z 4 lat temu
rodzic
commit
7e8dde7e26

+ 2 - 3
apps/emqx_authz/src/emqx_authz.erl

@@ -233,7 +233,6 @@ create_resource(#{type := DB,
         {error, Reason} -> {error, Reason}
         {error, Reason} -> {error, Reason}
     end.
     end.
 
 
--spec(init_provider(rule()) -> rule()).
 init_provider(#{enable := true,
 init_provider(#{enable := true,
                 type := file,
                 type := file,
                 path := Path
                 path := Path
@@ -301,7 +300,7 @@ init_provider(#{enable := false} = Rule) ->Rule.
       -> {stop, allow} | {ok, deny}).
       -> {stop, allow} | {ok, deny}).
 authorize(#{username := Username,
 authorize(#{username := Username,
             peerhost := IpAddress
             peerhost := IpAddress
-           } = Client, PubSub, Topic, _DefaultResult, Rules) ->
+           } = Client, PubSub, Topic, DefaultResult, Rules) ->
     case do_authorize(Client, PubSub, Topic, Rules) of
     case do_authorize(Client, PubSub, Topic, Rules) of
         {matched, allow} ->
         {matched, allow} ->
             ?LOG(info, "Client succeeded authorization: Username: ~p, IP: ~p, Topic: ~p, Permission: allow", [Username, IpAddress, Topic]),
             ?LOG(info, "Client succeeded authorization: Username: ~p, IP: ~p, Topic: ~p, Permission: allow", [Username, IpAddress, Topic]),
@@ -313,7 +312,7 @@ authorize(#{username := Username,
             {stop, deny};
             {stop, deny};
         nomatch ->
         nomatch ->
             ?LOG(info, "Client failed authorization: Username: ~p, IP: ~p, Topic: ~p, Reasion: ~p", [Username, IpAddress, Topic, "no-match rule"]),
             ?LOG(info, "Client failed authorization: Username: ~p, IP: ~p, Topic: ~p, Reasion: ~p", [Username, IpAddress, Topic, "no-match rule"]),
-            {stop, deny}
+            {stop, DefaultResult}
     end.
     end.
 
 
 do_authorize(Client, PubSub, Topic,
 do_authorize(Client, PubSub, Topic,

+ 1 - 6
apps/emqx_authz/src/emqx_authz_rule.erl

@@ -70,11 +70,6 @@ atom(B) when is_binary(B) ->
     catch
     catch
         _ -> binary_to_atom(B)
         _ -> binary_to_atom(B)
     end;
     end;
-atom(L) when is_list(L) ->
-    try list_to_existing_atom(L)
-    catch
-        _ -> list_to_atom(L)
-    end;
 atom(A) when is_atom(A) -> A.
 atom(A) when is_atom(A) -> A.
 
 
 bin(L) when is_list(L) ->
 bin(L) when is_list(L) ->
@@ -84,7 +79,7 @@ bin(B) when is_binary(B) ->
 
 
 -spec(matches(emqx_types:clientinfo(), emqx_types:pubsub(), emqx_types:topic(), [rule()])
 -spec(matches(emqx_types:clientinfo(), emqx_types:pubsub(), emqx_types:topic(), [rule()])
       -> {matched, allow} | {matched, deny} | nomatch).
       -> {matched, allow} | {matched, deny} | nomatch).
-matches(Client, PubSub, Topic, []) -> nomatch;
+matches(_Client, _PubSub, _Topic, []) -> nomatch;
 matches(Client, PubSub, Topic, [{Permission, Who, Action, TopicFilters} | Tail]) ->
 matches(Client, PubSub, Topic, [{Permission, Who, Action, TopicFilters} | Tail]) ->
     case match(Client, PubSub, Topic, {Permission, Who, Action, TopicFilters}) of
     case match(Client, PubSub, Topic, {Permission, Who, Action, TopicFilters}) of
         nomatch -> matches(Client, PubSub, Topic, Tail);
         nomatch -> matches(Client, PubSub, Topic, Tail);

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

@@ -33,6 +33,7 @@ groups() ->
 init_per_suite(Config) ->
 init_per_suite(Config) ->
     meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
     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, fun(_, _, _) -> {ok, meck_data} end),
+    meck:expect(emqx_resource, update, fun(_, _, _, _) -> {ok, meck_data} end),
     meck:expect(emqx_resource, remove, fun(_) -> ok end ),
     meck:expect(emqx_resource, remove, fun(_) -> ok end ),
 
 
     ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
     ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
@@ -110,10 +111,7 @@ t_update_rule(_) ->
     {ok, _} = emqx_authz:update(head, [?RULE1]),
     {ok, _} = emqx_authz:update(head, [?RULE1]),
     {ok, _} = emqx_authz:update(tail, [?RULE3]),
     {ok, _} = emqx_authz:update(tail, [?RULE3]),
 
 
-    dbg:tracer(),dbg:p(all,c),
-    dbg:tpl(hocon_schema, check, cx),
-    Lists1 = emqx_authz:check_rules([?RULE1, ?RULE2, ?RULE3]),
-    ?assertMatch(Lists1, emqx:get_config([authorization_rules, rules], [])),
+    ?assertMatch([#{type := http}, #{type := mongo}, #{type := mysql}], emqx:get_config([authorization_rules, rules], [])),
 
 
     [#{annotations := #{id := Id1}, type := http},
     [#{annotations := #{id := Id1}, type := http},
      #{annotations := #{id := Id2}, type := mongo},
      #{annotations := #{id := Id2}, type := mongo},
@@ -122,8 +120,7 @@ t_update_rule(_) ->
 
 
     {ok, _} = emqx_authz:update({replace_once, Id1}, ?RULE5),
     {ok, _} = emqx_authz:update({replace_once, Id1}, ?RULE5),
     {ok, _} = emqx_authz:update({replace_once, Id3}, ?RULE4),
     {ok, _} = emqx_authz:update({replace_once, Id3}, ?RULE4),
-    Lists2 = emqx_authz:check_rules([?RULE1, ?RULE2, ?RULE4]),
-    ?assertMatch(Lists2, emqx:get_config([authorization_rules, rules], [])),
+    ?assertMatch([#{type := redis}, #{type := mongo}, #{type := pgsql}], emqx:get_config([authorization_rules, rules], [])),
 
 
     [#{annotations := #{id := Id1}, type := redis},
     [#{annotations := #{id := Id1}, type := redis},
      #{annotations := #{id := Id2}, type := mongo},
      #{annotations := #{id := Id2}, type := mongo},

+ 2 - 33
apps/emqx_authz/test/emqx_authz_api_SUITE.erl

@@ -37,37 +37,6 @@
 -define(API_VERSION, "v5").
 -define(API_VERSION, "v5").
 -define(BASE_PATH, "api").
 -define(BASE_PATH, "api").
 
 
-% -define(RULE1, #{<<"principal">> => <<"all">>,
-%                  <<"topics">> => [<<"#">>],
-%                  <<"action">> => <<"all">>,
-%                  <<"permission">> => <<"deny">>}
-%        ).
-% -define(RULE2, #{<<"principal">> =>
-%                     #{<<"ipaddress">> => <<"127.0.0.1">>},
-%                  <<"topics">> =>
-%                         [#{<<"eq">> => <<"#">>},
-%                          #{<<"eq">> => <<"+">>}
-%                         ] ,
-%                  <<"action">> => <<"all">>,
-%                  <<"permission">> => <<"allow">>}
-%        ).
-% -define(RULE3,#{<<"principal">> =>
-%                     #{<<"and">> => [#{<<"username">> => <<"^test?">>},
-%                                     #{<<"clientid">> => <<"^test?">>}
-%                                    ]},
-%                 <<"topics">> => [<<"test">>],
-%                 <<"action">> => <<"publish">>,
-%                 <<"permission">> => <<"allow">>}
-%        ).
-% -define(RULE4,#{<<"principal">> =>
-%                     #{<<"or">> => [#{<<"username">> => <<"^test">>},
-%                                    #{<<"clientid">> => <<"test?">>}
-%                                   ]},
-%                 <<"topics">> => [<<"%u">>,<<"%c">>],
-%                 <<"action">> => <<"publish">>,
-%                 <<"permission">> => <<"deny">>}
-%        ).
-
 -define(RULE1, #{<<"type">> => <<"http">>,
 -define(RULE1, #{<<"type">> => <<"http">>,
                  <<"config">> => #{
                  <<"config">> => #{
                     <<"url">> => <<"https://fake.com:443/">>,
                     <<"url">> => <<"https://fake.com:443/">>,
@@ -119,8 +88,7 @@
                 }).
                 }).
 
 
 all() ->
 all() ->
-    % emqx_ct:all(?MODULE).
-    [].
+    emqx_ct:all(?MODULE).
 
 
 groups() ->
 groups() ->
     [].
     [].
@@ -129,6 +97,7 @@ init_per_suite(Config) ->
     meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
     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, fun(_, _, _) -> {ok, meck_data} end),
     meck:expect(emqx_resource, update, fun(_, _, _, _) -> {ok, meck_data} 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 ),
     meck:expect(emqx_resource, remove, fun(_) -> ok end ),
 
 
     ekka_mnesia:start(),
     ekka_mnesia:start(),

+ 0 - 2
apps/emqx_authz/test/emqx_authz_http_SUITE.erl

@@ -21,8 +21,6 @@
 -include("emqx_authz.hrl").
 -include("emqx_authz.hrl").
 -include_lib("eunit/include/eunit.hrl").
 -include_lib("eunit/include/eunit.hrl").
 -include_lib("common_test/include/ct.hrl").
 -include_lib("common_test/include/ct.hrl").
--define(CONF_DEFAULT, <<"authorization: {rules: []}">>).
-
 -define(CONF_DEFAULT, <<"authorization_rules: {rules: []}">>).
 -define(CONF_DEFAULT, <<"authorization_rules: {rules: []}">>).
 
 
 all() ->
 all() ->

+ 0 - 2
apps/emqx_authz/test/emqx_authz_redis_SUITE.erl

@@ -21,8 +21,6 @@
 -include("emqx_authz.hrl").
 -include("emqx_authz.hrl").
 -include_lib("eunit/include/eunit.hrl").
 -include_lib("eunit/include/eunit.hrl").
 -include_lib("common_test/include/ct.hrl").
 -include_lib("common_test/include/ct.hrl").
--define(CONF_DEFAULT, <<"authorization: {rules: []}">>).
-
 -define(CONF_DEFAULT, <<"authorization_rules: {rules: []}">>).
 -define(CONF_DEFAULT, <<"authorization_rules: {rules: []}">>).
 
 
 all() ->
 all() ->

+ 3 - 1
apps/emqx_connector/src/emqx_connector_mongo.erl

@@ -84,7 +84,9 @@ mongo_fields() ->
                       nullable => true}}
                       nullable => true}}
     , {database, fun emqx_connector_schema_lib:database/1}
     , {database, fun emqx_connector_schema_lib:database/1}
     , {topology, #{type => hoconsc:ref(?MODULE, topology),
     , {topology, #{type => hoconsc:ref(?MODULE, topology),
-                   nullable => true}}
+                   default => #{}}}
+                   %% TODO: Does the ref type support nullable=ture ?
+                   % nullable => true}}
     ] ++
     ] ++
     emqx_connector_schema_lib:ssl_fields().
     emqx_connector_schema_lib:ssl_fields().