Merge pull request #8346 from thalesmg/fix-sub-filter-hook
fix(hooks): return error on hook-removed subscription rather than deleting it
This commit is contained in:
commit
a3cb718f97
|
@ -171,7 +171,7 @@ on_client_subscribe(#{clientid := ClientId, username := Username}, _Properties,
|
|||
case on_client_subscribe_single(ClientId, Username, TopicFilter, LuaState) of
|
||||
false ->
|
||||
{Topic, Opts} = TopicFilter,
|
||||
[{Topic, Opts#{delete => true}} | Acc];
|
||||
[{Topic, Opts#{deny_subscription => true}} | Acc];
|
||||
NewTopicFilter ->
|
||||
[NewTopicFilter | Acc]
|
||||
end
|
||||
|
|
|
@ -711,7 +711,7 @@ t_stop_sub(_Config) ->
|
|||
OriginalTopicFilters = [{Topic = <<"u">>,
|
||||
Opts = #{nl => 0,qos => 0,rap => 0,rh => 0}}],
|
||||
Props = #{},
|
||||
Expected = [{Topic, Opts#{delete => true}}],
|
||||
Expected = [{Topic, Opts#{deny_subscription => true}}],
|
||||
?assertEqual(Expected, emqx_hooks:run_fold('client.subscribe',
|
||||
[ClientInfo, Props],
|
||||
OriginalTopicFilters)).
|
||||
|
|
|
@ -425,9 +425,9 @@ handle_in(Packet = ?SUBSCRIBE_PACKET(PacketId, Properties, TopicFilters),
|
|||
Channel),
|
||||
TupleTopicFilters2 =
|
||||
lists:foldl(
|
||||
fun({{Topic, Opts = #{delete := true}}, _QoS}, Acc) ->
|
||||
Key = {Topic, maps:without([delete], Opts)},
|
||||
lists:keydelete(Key, 1, Acc);
|
||||
fun({{Topic, Opts = #{deny_subscription := true}}, _ReturnCode}, Acc) ->
|
||||
Key = {Topic, maps:without([deny_subscription], Opts)},
|
||||
lists:keyreplace(Key, 1, Acc, {Key, ?RC_UNSPECIFIED_ERROR});
|
||||
(Tuple = {Key, _Value}, Acc) ->
|
||||
lists:keyreplace(Key, 1, Acc, Tuple)
|
||||
end,
|
||||
|
|
|
@ -315,7 +315,7 @@ t_handle_in_empty_client_subscribe_hook({'end', _Config}) ->
|
|||
ok;
|
||||
t_handle_in_empty_client_subscribe_hook(Config) when is_list(Config) ->
|
||||
Hook = fun(_ClientInfo, _Username, TopicFilter) ->
|
||||
EmptyFilters = [{T, Opts#{delete => true}} || {T, Opts} <- TopicFilter],
|
||||
EmptyFilters = [{T, Opts#{deny_subscription => true}} || {T, Opts} <- TopicFilter],
|
||||
{stop, EmptyFilters}
|
||||
end,
|
||||
ok = emqx:hook('client.subscribe', Hook, []),
|
||||
|
@ -323,7 +323,7 @@ t_handle_in_empty_client_subscribe_hook(Config) when is_list(Config) ->
|
|||
{ok, C} = emqtt:start_link(),
|
||||
{ok, _} = emqtt:connect(C),
|
||||
{ok, _, RCs} = emqtt:subscribe(C, <<"t">>),
|
||||
?assertEqual([], RCs),
|
||||
?assertEqual([?RC_UNSPECIFIED_ERROR], RCs),
|
||||
ok
|
||||
after
|
||||
ok = emqx:unhook('client.subscribe', Hook)
|
||||
|
|
Loading…
Reference in New Issue