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()},
|
{conn_props, properties()},
|
||||||
{connected, boolean()},
|
{connected, boolean()},
|
||||||
{connected_at, timestamp()},
|
{connected_at, timestamp()},
|
||||||
|
{disconnected_at, timestamp()},
|
||||||
{keepalive, range(0, 16#ffff)},
|
{keepalive, range(0, 16#ffff)},
|
||||||
{receive_maximum, non_neg_integer()},
|
{receive_maximum, non_neg_integer()},
|
||||||
{expiry_interval, non_neg_integer()}
|
{expiry_interval, non_neg_integer()}
|
||||||
|
|
|
@ -49,7 +49,8 @@
|
||||||
|
|
||||||
-type default_result() :: allow | deny.
|
-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()].
|
-type sources() :: [source()].
|
||||||
|
|
||||||
|
|
|
@ -120,8 +120,10 @@ t_access_failed_if_no_server_running(Config) ->
|
||||||
),
|
),
|
||||||
|
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{stop, deny},
|
{stop, #{result := deny, from := exhook}},
|
||||||
emqx_exhook_handler:on_client_authorize(ClientInfo, publish, <<"t/1">>, allow)
|
emqx_exhook_handler:on_client_authorize(ClientInfo, publish, <<"t/1">>, #{
|
||||||
|
result => allow, from => exhookk
|
||||||
|
})
|
||||||
),
|
),
|
||||||
|
|
||||||
Message = emqx_message:make(<<"t/1">>, <<"abc">>),
|
Message = emqx_message:make(<<"t/1">>, <<"abc">>),
|
||||||
|
|
|
@ -133,9 +133,16 @@ prop_client_authenticate() ->
|
||||||
).
|
).
|
||||||
|
|
||||||
prop_client_authorize() ->
|
prop_client_authorize() ->
|
||||||
|
MkResult = fun(Result) -> #{result => Result, from => exhook} end,
|
||||||
?ALL(
|
?ALL(
|
||||||
{ClientInfo0, PubSub, Topic, Result, Meta},
|
{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
|
begin
|
||||||
ClientInfo = inject_magic_into(username, ClientInfo0),
|
ClientInfo = inject_magic_into(username, ClientInfo0),
|
||||||
OutResult = emqx_hooks:run_fold(
|
OutResult = emqx_hooks:run_fold(
|
||||||
|
@ -145,9 +152,9 @@ prop_client_authorize() ->
|
||||||
),
|
),
|
||||||
ExpectedOutResult =
|
ExpectedOutResult =
|
||||||
case maps:get(username, ClientInfo) of
|
case maps:get(username, ClientInfo) of
|
||||||
<<"baduser">> -> deny;
|
<<"baduser">> -> MkResult(deny);
|
||||||
<<"gooduser">> -> allow;
|
<<"gooduser">> -> MkResult(allow);
|
||||||
<<"normaluser">> -> allow;
|
<<"normaluser">> -> MkResult(allow);
|
||||||
_ -> Result
|
_ -> Result
|
||||||
end,
|
end,
|
||||||
?assertEqual(ExpectedOutResult, OutResult),
|
?assertEqual(ExpectedOutResult, OutResult),
|
||||||
|
@ -544,7 +551,7 @@ subopts(SubOpts) ->
|
||||||
authresult_to_bool(AuthResult) ->
|
authresult_to_bool(AuthResult) ->
|
||||||
AuthResult == ok.
|
AuthResult == ok.
|
||||||
|
|
||||||
aclresult_to_bool(Result) ->
|
aclresult_to_bool(#{result := Result}) ->
|
||||||
Result == allow.
|
Result == allow.
|
||||||
|
|
||||||
pubsub_to_enum(publish) -> 'PUBLISH';
|
pubsub_to_enum(publish) -> 'PUBLISH';
|
||||||
|
|
Loading…
Reference in New Issue