fix(authz): fix dialyzer && test case && proper error

This commit is contained in:
firest 2022-08-31 16:49:27 +08:00
parent 168f44e45b
commit 71aaf5c538
4 changed files with 19 additions and 8 deletions

View File

@ -69,6 +69,7 @@ conninfo() ->
{conn_props, properties()},
{connected, boolean()},
{connected_at, timestamp()},
{disconnected_at, timestamp()},
{keepalive, range(0, 16#ffff)},
{receive_maximum, non_neg_integer()},
{expiry_interval, non_neg_integer()}

View File

@ -49,7 +49,8 @@
-type default_result() :: allow | deny.
-type authz_result() :: {stop, allow} | {ok, deny}.
-type authz_result_value() :: #{result := allow | deny, from => _}.
-type authz_result() :: {stop, authz_result_value()} | {ok, authz_result_value()} | ignore.
-type sources() :: [source()].

View File

@ -120,8 +120,10 @@ t_access_failed_if_no_server_running(Config) ->
),
?assertMatch(
{stop, deny},
emqx_exhook_handler:on_client_authorize(ClientInfo, publish, <<"t/1">>, allow)
{stop, #{result := deny, from := exhook}},
emqx_exhook_handler:on_client_authorize(ClientInfo, publish, <<"t/1">>, #{
result => allow, from => exhookk
})
),
Message = emqx_message:make(<<"t/1">>, <<"abc">>),

View File

@ -133,9 +133,16 @@ prop_client_authenticate() ->
).
prop_client_authorize() ->
MkResult = fun(Result) -> #{result => Result, from => exhook} end,
?ALL(
{ClientInfo0, PubSub, Topic, Result, Meta},
{clientinfo(), oneof([publish, subscribe]), topic(), oneof([allow, deny]), request_meta()},
{
clientinfo(),
oneof([publish, subscribe]),
topic(),
oneof([MkResult(allow), MkResult(deny)]),
request_meta()
},
begin
ClientInfo = inject_magic_into(username, ClientInfo0),
OutResult = emqx_hooks:run_fold(
@ -145,9 +152,9 @@ prop_client_authorize() ->
),
ExpectedOutResult =
case maps:get(username, ClientInfo) of
<<"baduser">> -> deny;
<<"gooduser">> -> allow;
<<"normaluser">> -> allow;
<<"baduser">> -> MkResult(deny);
<<"gooduser">> -> MkResult(allow);
<<"normaluser">> -> MkResult(allow);
_ -> Result
end,
?assertEqual(ExpectedOutResult, OutResult),
@ -544,7 +551,7 @@ subopts(SubOpts) ->
authresult_to_bool(AuthResult) ->
AuthResult == ok.
aclresult_to_bool(Result) ->
aclresult_to_bool(#{result := Result}) ->
Result == allow.
pubsub_to_enum(publish) -> 'PUBLISH';