Merge pull request #11074 from JimMoen/fix-share-sub-nl-protocol-error

fix: shared-sub with nl sub-option should cause protocol error
This commit is contained in:
JimMoen 2023-06-19 10:39:08 +08:00 committed by GitHub
commit 30ac6c4e48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 0 deletions

View File

@ -270,6 +270,9 @@ check(#mqtt_packet_subscribe{topic_filters = TopicFilters}) ->
try try
validate_topic_filters(TopicFilters) validate_topic_filters(TopicFilters)
catch catch
%% Known Specificed Reason Code
error:{error, RC} ->
{error, RC};
error:_Error -> error:_Error ->
{error, ?RC_TOPIC_FILTER_INVALID} {error, ?RC_TOPIC_FILTER_INVALID}
end; end;
@ -413,6 +416,10 @@ run_checks([Check | More], Packet, Options) ->
validate_topic_filters(TopicFilters) -> validate_topic_filters(TopicFilters) ->
lists:foreach( lists:foreach(
fun fun
%% Protocol Error and Should Disconnect
%% MQTT-5.0 [MQTT-3.8.3-4] and [MQTT-4.13.1-1]
({<<?SHARE, "/", _Rest/binary>>, #{nl := 1}}) ->
error({error, ?RC_PROTOCOL_ERROR});
({TopicFilter, _SubOpts}) -> ({TopicFilter, _SubOpts}) ->
emqx_topic:validate(TopicFilter); emqx_topic:validate(TopicFilter);
(TopicFilter) -> (TopicFilter) ->

View File

@ -985,3 +985,18 @@ t_shared_subscriptions_client_terminates_when_qos_eq_2(Config) ->
?assertEqual(1, counters:get(CRef, 1)), ?assertEqual(1, counters:get(CRef, 1)),
process_flag(trap_exit, false). process_flag(trap_exit, false).
t_share_subscribe_no_local(Config) ->
ConnFun = ?config(conn_fun, Config),
process_flag(trap_exit, true),
ShareTopic = <<"$share/sharename/TopicA">>,
{ok, Client} = emqtt:start_link([{proto_ver, v5} | Config]),
{ok, _} = emqtt:ConnFun(Client),
%% MQTT-5.0 [MQTT-3.8.3-4] and [MQTT-4.13.1-1] (Disconnect)
case catch emqtt:subscribe(Client, #{}, [{ShareTopic, [{nl, true}, {qos, 1}]}]) of
{'EXIT', {Reason, _Stk}} ->
?assertEqual({disconnected, ?RC_PROTOCOL_ERROR, #{}}, Reason)
end,
process_flag(trap_exit, false).

View File

@ -0,0 +1 @@
Fix to adhere to Protocol spec MQTT-5.0 [MQTT-3.8.3-4].