Merge pull request #6980 from thalesmg/bugfix-find-alias-clause-50
fix(channel): wrong case clause when alias is inexistent (5.0)
This commit is contained in:
commit
372f628c9e
|
@ -1437,7 +1437,7 @@ process_alias(Packet = #mqtt_packet{
|
|||
{ok, Topic} ->
|
||||
NPublish = Publish#mqtt_packet_publish{topic_name = Topic},
|
||||
{ok, Packet#mqtt_packet{variable = NPublish}, Channel};
|
||||
false -> {error, ?RC_PROTOCOL_ERROR}
|
||||
error -> {error, ?RC_PROTOCOL_ERROR}
|
||||
end;
|
||||
|
||||
process_alias(#mqtt_packet{
|
||||
|
@ -1778,7 +1778,7 @@ run_hooks(Name, Args, Acc) ->
|
|||
|
||||
-compile({inline, [find_alias/3, save_alias/4]}).
|
||||
|
||||
find_alias(_, _, undefined) -> false;
|
||||
find_alias(_, _, undefined) -> error;
|
||||
find_alias(inbound, AliasId, _TopicAliases = #{inbound := Aliases}) ->
|
||||
maps:find(AliasId, Aliases);
|
||||
find_alias(outbound, Topic, _TopicAliases = #{outbound := Aliases}) ->
|
||||
|
|
|
@ -883,6 +883,13 @@ t_process_alias(_) ->
|
|||
{ok, #mqtt_packet{variable = #mqtt_packet_publish{topic_name = <<"t">>}}, _Chan} =
|
||||
emqx_channel:process_alias(#mqtt_packet{variable = Publish}, Channel).
|
||||
|
||||
t_process_alias_inexistent_alias(_) ->
|
||||
Publish = #mqtt_packet_publish{topic_name = <<>>, properties = #{'Topic-Alias' => 1}},
|
||||
Channel = channel(),
|
||||
?assertEqual(
|
||||
{error, ?RC_PROTOCOL_ERROR},
|
||||
emqx_channel:process_alias(#mqtt_packet{variable = Publish}, Channel)).
|
||||
|
||||
t_packing_alias(_) ->
|
||||
Packet1 = #mqtt_packet{variable = #mqtt_packet_publish{
|
||||
topic_name = <<"x">>,
|
||||
|
@ -919,6 +926,20 @@ t_packing_alias(_) ->
|
|||
#mqtt_packet{variable = #mqtt_packet_publish{topic_name = <<"z">>}},
|
||||
channel())).
|
||||
|
||||
t_packing_alias_inexistent_alias(_) ->
|
||||
Publish = #mqtt_packet_publish{topic_name = <<>>, properties = #{'Topic-Alias' => 1}},
|
||||
Channel = channel(),
|
||||
Packet = #mqtt_packet{variable = Publish},
|
||||
ExpectedChannel = emqx_channel:set_field(
|
||||
topic_aliases,
|
||||
#{ inbound => #{}
|
||||
, outbound => #{<<>> => 1}
|
||||
},
|
||||
Channel),
|
||||
?assertEqual(
|
||||
{Packet, ExpectedChannel},
|
||||
emqx_channel:packing_alias(Packet, Channel)).
|
||||
|
||||
t_check_pub_authz(_) ->
|
||||
emqx_config:put_zone_conf(default, [authorization, enable], true),
|
||||
Publish = ?PUBLISH_PACKET(?QOS_0, <<"t">>, 1, <<"payload">>),
|
||||
|
|
Loading…
Reference in New Issue