Add condition to handle when mqx_topic_alias do not exist

This commit is contained in:
Gilbert Wong 2018-09-06 19:09:29 +08:00
parent c145cb89f4
commit 765ab5ad7b
3 changed files with 52 additions and 42 deletions

View File

@ -69,6 +69,8 @@ do_check_pub(Props = #{ topic_alias := TopicAlias}, [{max_topic_alias, MaxTopicA
end;
do_check_pub(#{retain := true}, [{mqtt_retain_available, false}|_Caps]) ->
{error, ?RC_RETAIN_NOT_SUPPORTED};
do_check_pub(Props, [{max_topic_alias, _} | Caps]) ->
do_check_pub(Props, Caps);
do_check_pub(Props, [{mqtt_retain_available, _}|Caps]) ->
do_check_pub(Props, Caps).

View File

@ -33,36 +33,36 @@
-export([shutdown/2]).
-record(pstate, {
zone,
sendfun,
peername,
peercert,
proto_ver,
proto_name,
ackprops,
client_id,
is_assigned,
conn_pid,
conn_props,
ack_props,
username,
session,
clean_start,
topic_aliases,
packet_size,
will_topic,
will_msg,
keepalive,
mountpoint,
is_super,
is_bridge,
enable_ban,
enable_acl,
recv_stats,
send_stats,
connected,
connected_at
}).
zone,
sendfun,
peername,
peercert,
proto_ver,
proto_name,
ackprops,
client_id,
is_assigned,
conn_pid,
conn_props,
ack_props,
username,
session,
clean_start,
topic_aliases,
packet_size,
will_topic,
will_msg,
keepalive,
mountpoint,
is_super,
is_bridge,
enable_ban,
enable_acl,
recv_stats,
send_stats,
connected,
connected_at
}).
-type(state() :: #pstate{}).
-export_type([state/0]).

View File

@ -63,10 +63,12 @@ t_check_pub(_) ->
{ok, _} = emqx_zone:start_link(),
PubCaps = #{
max_qos_allowed => ?QOS_1,
mqtt_retain_available => false
mqtt_retain_available => false,
max_topic_alias => 4
},
emqx_zone:set_env(zone, '$mqtt_pub_caps', PubCaps),
timer:sleep(100),
ct:log("~p", [emqx_mqtt_caps:get_caps(zone, publish)]),
BadPubProps1 = #{
qos => ?QOS_2,
retain => false
@ -77,6 +79,12 @@ t_check_pub(_) ->
retain => true
},
{error, ?RC_RETAIN_NOT_SUPPORTED} = emqx_mqtt_caps:check_pub(zone, BadPubProps2),
BadPubProps3 = #{
qos => ?QOS_1,
retain => false,
topic_alias => 5
},
{error, ?RC_TOPIC_ALIAS_INVALID} = emqx_mqtt_caps:check_pub(zone, BadPubProps3),
PubProps = #{
qos => ?QOS_1,
retain => false