fix: authz clean-cache clientid always return not_found
This commit is contained in:
parent
c04f770118
commit
4245a4d8c6
|
@ -1,6 +1,6 @@
|
||||||
{application, emqx_ctl, [
|
{application, emqx_ctl, [
|
||||||
{description, "Backend for emqx_ctl script"},
|
{description, "Backend for emqx_ctl script"},
|
||||||
{vsn, "0.1.2"},
|
{vsn, "0.1.3"},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{mod, {emqx_ctl_app, []}},
|
{mod, {emqx_ctl_app, []}},
|
||||||
{applications, [
|
{applications, [
|
||||||
|
|
|
@ -119,8 +119,7 @@ run_command(Cmd, Args) when is_atom(Cmd) ->
|
||||||
case lookup_command(Cmd) of
|
case lookup_command(Cmd) of
|
||||||
[{Mod, Fun}] ->
|
[{Mod, Fun}] ->
|
||||||
try
|
try
|
||||||
_ = apply(Mod, Fun, [Args]),
|
apply(Mod, Fun, [Args])
|
||||||
ok
|
|
||||||
catch
|
catch
|
||||||
_:Reason:Stacktrace ->
|
_:Reason:Stacktrace ->
|
||||||
?LOG_ERROR(#{
|
?LOG_ERROR(#{
|
||||||
|
|
|
@ -707,7 +707,7 @@ authz(["cache-clean", "all"]) ->
|
||||||
with_log(fun emqx_mgmt:clean_authz_cache_all/0, Msg);
|
with_log(fun emqx_mgmt:clean_authz_cache_all/0, Msg);
|
||||||
authz(["cache-clean", ClientId]) ->
|
authz(["cache-clean", ClientId]) ->
|
||||||
Msg = io_lib:format("Drain ~ts authz cache", [ClientId]),
|
Msg = io_lib:format("Drain ~ts authz cache", [ClientId]),
|
||||||
with_log(fun() -> emqx_mgmt:clean_authz_cache(ClientId) end, Msg);
|
with_log(fun() -> emqx_mgmt:clean_authz_cache(list_to_binary(ClientId)) end, Msg);
|
||||||
authz(_) ->
|
authz(_) ->
|
||||||
emqx_ctl:usage(
|
emqx_ctl:usage(
|
||||||
[
|
[
|
||||||
|
@ -921,12 +921,14 @@ for_node(Fun, Node) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
with_log(Fun, Msg) ->
|
with_log(Fun, Msg) ->
|
||||||
case Fun() of
|
Res = Fun(),
|
||||||
|
case Res of
|
||||||
ok ->
|
ok ->
|
||||||
emqx_ctl:print("~s OK~n", [Msg]);
|
emqx_ctl:print("~s OK~n", [Msg]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
emqx_ctl:print("~s FAILED~n~p~n", [Msg, Reason])
|
emqx_ctl:print("~s FAILED~n~p~n", [Msg, Reason])
|
||||||
end.
|
end,
|
||||||
|
Res.
|
||||||
|
|
||||||
cluster_info() ->
|
cluster_info() ->
|
||||||
RunningNodes = safe_call_mria(running_nodes, [], []),
|
RunningNodes = safe_call_mria(running_nodes, [], []),
|
||||||
|
|
|
@ -25,6 +25,7 @@ all() ->
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
emqx_mgmt_api_test_util:init_suite([emqx_conf, emqx_management]),
|
emqx_mgmt_api_test_util:init_suite([emqx_conf, emqx_management]),
|
||||||
|
ok = emqx_mgmt_cli:load(),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_) ->
|
end_per_suite(_) ->
|
||||||
|
@ -183,9 +184,25 @@ t_listeners(_Config) ->
|
||||||
|
|
||||||
t_authz(_Config) ->
|
t_authz(_Config) ->
|
||||||
%% authz cache-clean all # Clears authorization cache on all nodes
|
%% authz cache-clean all # Clears authorization cache on all nodes
|
||||||
emqx_ctl:run_command(["authz", "cache-clean", "all"]),
|
?assertMatch(ok, emqx_ctl:run_command(["authz", "cache-clean", "all"])),
|
||||||
%% authz cache-clean node <Node> # Clears authorization cache on given node
|
ClientId = "authz_clean_test",
|
||||||
|
ClientIdBin = list_to_binary(ClientId),
|
||||||
%% authz cache-clean <ClientId> # Clears authorization cache for given client
|
%% authz cache-clean <ClientId> # Clears authorization cache for given client
|
||||||
|
?assertMatch({error, not_found}, emqx_ctl:run_command(["authz", "cache-clean", ClientId])),
|
||||||
|
{ok, C} = emqtt:start_link([{clean_start, true}, {clientid, ClientId}]),
|
||||||
|
{ok, _} = emqtt:connect(C),
|
||||||
|
{ok, _, _} = emqtt:subscribe(C, <<"topic/1">>, 1),
|
||||||
|
[Pid] = emqx_cm:lookup_channels(ClientIdBin),
|
||||||
|
?assertMatch([_], gen_server:call(Pid, list_authz_cache)),
|
||||||
|
|
||||||
|
?assertMatch(ok, emqx_ctl:run_command(["authz", "cache-clean", ClientId])),
|
||||||
|
?assertMatch([], gen_server:call(Pid, list_authz_cache)),
|
||||||
|
%% authz cache-clean node <Node> # Clears authorization cache on given node
|
||||||
|
{ok, _, _} = emqtt:subscribe(C, <<"topic/2">>, 1),
|
||||||
|
?assertMatch([_], gen_server:call(Pid, list_authz_cache)),
|
||||||
|
?assertMatch(ok, emqx_ctl:run_command(["authz", "cache-clean", "node", atom_to_list(node())])),
|
||||||
|
?assertMatch([], gen_server:call(Pid, list_authz_cache)),
|
||||||
|
ok = emqtt:disconnect(C),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_olp(_Config) ->
|
t_olp(_Config) ->
|
||||||
|
|
Loading…
Reference in New Issue