chore(acl): fix acl test
This commit is contained in:
parent
ff00a6716a
commit
25c32dd2f5
|
@ -3,7 +3,7 @@
|
|||
{id, "emqx"},
|
||||
{description, "EMQX Core"},
|
||||
% strict semver, bump manually!
|
||||
{vsn, "5.0.10"},
|
||||
{vsn, "5.0.11"},
|
||||
{modules, []},
|
||||
{registered, []},
|
||||
{applications, [
|
||||
|
|
|
@ -56,7 +56,7 @@ authorize(ClientInfo, PubSub, <<"$delayed/", Data/binary>> = RawTopic) ->
|
|||
authorize(ClientInfo, PubSub, Topic);
|
||||
_ ->
|
||||
?SLOG(warning, #{
|
||||
msg => "invalid_dealyed_topic_format",
|
||||
msg => "invalid_delayed_topic_format",
|
||||
expected_example => "$delayed/1/t/foo",
|
||||
got => RawTopic
|
||||
}),
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
-compile(nowarn_export_all).
|
||||
|
||||
-include_lib("emqx/include/emqx_mqtt.hrl").
|
||||
-include_lib("emqx/include/emqx_hooks.hrl").
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
all() -> emqx_common_test_helpers:all(?MODULE).
|
||||
|
@ -32,12 +33,12 @@ init_per_suite(Config) ->
|
|||
end_per_suite(_Config) ->
|
||||
emqx_common_test_helpers:stop_apps([]).
|
||||
|
||||
end_per_testcase(t_delayed_authorize, Config) ->
|
||||
meck:unload(emqx_access_control),
|
||||
Config;
|
||||
end_per_testcase(_, Config) ->
|
||||
init_per_testcase(_, Config) ->
|
||||
Config.
|
||||
|
||||
end_per_testcase(_, _Config) ->
|
||||
ok = emqx_hooks:del('client.authorize', {?MODULE, authz_stub}).
|
||||
|
||||
t_authenticate(_) ->
|
||||
?assertMatch({ok, _}, emqx_access_control:authenticate(clientinfo())).
|
||||
|
||||
|
@ -46,31 +47,26 @@ t_authorize(_) ->
|
|||
?assertEqual(allow, emqx_access_control:authorize(clientinfo(), Publish, <<"t">>)).
|
||||
|
||||
t_delayed_authorize(_) ->
|
||||
RawTopic = "$dealyed/1/foo/2",
|
||||
InvalidTopic = "$dealyed/1/foo/3",
|
||||
Topic = "foo/2",
|
||||
RawTopic = <<"$delayed/1/foo/2">>,
|
||||
InvalidTopic = <<"$delayed/1/foo/3">>,
|
||||
Topic = <<"foo/2">>,
|
||||
|
||||
ok = meck:new(emqx_access_control, [passthrough, no_history, no_link]),
|
||||
ok = meck:expect(
|
||||
emqx_access_control,
|
||||
do_authorize,
|
||||
fun
|
||||
(_, _, Topic) -> allow;
|
||||
(_, _, _) -> deny
|
||||
end
|
||||
),
|
||||
ok = emqx_hooks:put('client.authorize', {?MODULE, authz_stub, [Topic]}, ?HP_AUTHZ),
|
||||
|
||||
Publish1 = ?PUBLISH_PACKET(?QOS_0, RawTopic, 1, <<"payload">>),
|
||||
?assertEqual(allow, emqx_access_control:authorize(clientinfo(), Publish1, RawTopic)),
|
||||
|
||||
Publish2 = ?PUBLISH_PACKET(?QOS_0, InvalidTopic, 1, <<"payload">>),
|
||||
?assertEqual(allow, emqx_access_control:authorize(clientinfo(), Publish2, InvalidTopic)),
|
||||
?assertEqual(deny, emqx_access_control:authorize(clientinfo(), Publish2, InvalidTopic)),
|
||||
ok.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Helper functions
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
authz_stub(_Client, _PubSub, ValidTopic, _DefaultResult, ValidTopic) -> {stop, #{result => allow}};
|
||||
authz_stub(_Client, _PubSub, _Topic, _DefaultResult, _ValidTopic) -> {stop, #{result => deny}}.
|
||||
|
||||
clientinfo() -> clientinfo(#{}).
|
||||
clientinfo(InitProps) ->
|
||||
maps:merge(
|
||||
|
|
Loading…
Reference in New Issue