fix(authz): fix dialyzer && test case && proper error
This commit is contained in:
parent
168f44e45b
commit
71aaf5c538
|
@ -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()}
|
||||
|
|
|
@ -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()].
|
||||
|
||||
|
|
|
@ -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">>),
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in New Issue