Merge pull request #8347 from thalesmg/fix-sub-deny-hook-50

fix(hooks): return error on hook-removed subscription rather than deleting it (5.0)
This commit is contained in:
Thales Macedo Garitezi 2022-06-29 15:11:00 -03:00 committed by GitHub
commit 88746c7c11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -527,9 +527,9 @@ handle_in(
TupleTopicFilters2 =
lists:foldl(
fun
({{Topic, Opts = #{delete := true}}, _QoS}, Acc) ->
Key = {Topic, maps:without([delete], Opts)},
lists:keydelete(Key, 1, Acc);
({{Topic, Opts = #{deny_subscription := true}}, _QoS}, 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,

View File

@ -727,7 +727,7 @@ t_handle_in_empty_client_subscribe_hook(Config) when is_list(Config) ->
{ok, _} = emqtt:connect(C),
try
{ok, _, RCs} = emqtt:subscribe(C, <<"t">>),
?assertEqual([], RCs),
?assertEqual([?RC_UNSPECIFIED_ERROR], RCs),
ok
after
emqtt:disconnect(C)
@ -791,5 +791,5 @@ recv_msgs(Count, Msgs) ->
end.
client_subscribe_delete_all_hook(_ClientInfo, _Username, TopicFilter) ->
EmptyFilters = [{T, Opts#{delete => true}} || {T, Opts} <- TopicFilter],
EmptyFilters = [{T, Opts#{deny_subscription => true}} || {T, Opts} <- TopicFilter],
{stop, EmptyFilters}.