Pass paho zero_length_clientid test case
This commit is contained in:
parent
b10f49b52c
commit
5f42f88401
|
@ -73,6 +73,7 @@ init(#{peername := Peername, peercert := Peercert, sendfun := SendFun}, Options)
|
||||||
peercert = Peercert,
|
peercert = Peercert,
|
||||||
proto_ver = ?MQTT_PROTO_V4,
|
proto_ver = ?MQTT_PROTO_V4,
|
||||||
proto_name = <<"MQTT">>,
|
proto_name = <<"MQTT">>,
|
||||||
|
client_id = <<>>,
|
||||||
client_pid = self(),
|
client_pid = self(),
|
||||||
username = init_username(Peercert, Options),
|
username = init_username(Peercert, Options),
|
||||||
is_super = false,
|
is_super = false,
|
||||||
|
@ -201,6 +202,8 @@ process(?CONNECT_PACKET(
|
||||||
username = Username,
|
username = Username,
|
||||||
password = Password} = Connect), PState) ->
|
password = Password} = Connect), PState) ->
|
||||||
|
|
||||||
|
io:format("~p~n", [Connect]),
|
||||||
|
|
||||||
PState1 = set_username(Username,
|
PState1 = set_username(Username,
|
||||||
PState#pstate{client_id = ClientId,
|
PState#pstate{client_id = ClientId,
|
||||||
proto_ver = ProtoVer,
|
proto_ver = ProtoVer,
|
||||||
|
@ -334,8 +337,12 @@ process(?PACKET(?DISCONNECT), PState) ->
|
||||||
connack({?RC_SUCCESS, SP, PState}) ->
|
connack({?RC_SUCCESS, SP, PState}) ->
|
||||||
deliver({connack, ?RC_SUCCESS, sp(SP)}, PState);
|
deliver({connack, ?RC_SUCCESS, sp(SP)}, PState);
|
||||||
|
|
||||||
connack({ReasonCode, PState}) ->
|
connack({ReasonCode, PState = #pstate{proto_ver = ProtoVer}}) ->
|
||||||
deliver({connack, ReasonCode, 0}, PState),
|
_ = deliver({connack, if ProtoVer =:= ?MQTT_PROTO_V5 ->
|
||||||
|
ReasonCode;
|
||||||
|
true ->
|
||||||
|
emqx_reason_codes:compat(connack, ReasonCode)
|
||||||
|
end}, PState),
|
||||||
{error, emqx_reason_codes:name(ReasonCode), PState}.
|
{error, emqx_reason_codes:name(ReasonCode), PState}.
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
|
@ -415,7 +422,7 @@ send(Packet = ?PACKET(Type), PState = #pstate{proto_ver = Ver,
|
||||||
%% Assign a clientid
|
%% Assign a clientid
|
||||||
|
|
||||||
maybe_assign_client_id(PState = #pstate{client_id = <<>>, ackprops = AckProps}) ->
|
maybe_assign_client_id(PState = #pstate{client_id = <<>>, ackprops = AckProps}) ->
|
||||||
ClientId = iolist_to_binary(["emqx_", emqx_guid:gen()]),
|
ClientId = emqx_guid:to_base62(emqx_guid:gen()),
|
||||||
AckProps1 = set_property('Assigned-Client-Identifier', ClientId, AckProps),
|
AckProps1 = set_property('Assigned-Client-Identifier', ClientId, AckProps),
|
||||||
PState#pstate{client_id = ClientId, ackprops = AckProps1};
|
PState#pstate{client_id = ClientId, ackprops = AckProps1};
|
||||||
maybe_assign_client_id(PState) ->
|
maybe_assign_client_id(PState) ->
|
||||||
|
@ -464,18 +471,20 @@ check_proto_ver(#mqtt_packet_connect{proto_ver = Ver,
|
||||||
false -> {error, ?RC_PROTOCOL_ERROR}
|
false -> {error, ?RC_PROTOCOL_ERROR}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% Issue#599: Null clientId and clean_start = false
|
|
||||||
check_client_id(#mqtt_packet_connect{client_id = ClientId,
|
|
||||||
clean_start = false}, _PState)
|
|
||||||
when ClientId == undefined; ClientId == <<>> ->
|
|
||||||
{error, ?RC_CLIENT_IDENTIFIER_NOT_VALID};
|
|
||||||
|
|
||||||
%% MQTT3.1 does not allow null clientId
|
%% MQTT3.1 does not allow null clientId
|
||||||
check_client_id(#mqtt_packet_connect{proto_ver = ?MQTT_PROTO_V3,
|
check_client_id(#mqtt_packet_connect{proto_ver = ?MQTT_PROTO_V3,
|
||||||
client_id = ClientId}, _PState)
|
client_id = <<>>}, _PState) ->
|
||||||
when ClientId == undefined; ClientId == <<>> ->
|
|
||||||
{error, ?RC_CLIENT_IDENTIFIER_NOT_VALID};
|
{error, ?RC_CLIENT_IDENTIFIER_NOT_VALID};
|
||||||
|
|
||||||
|
%% Issue#599: Null clientId and clean_start = false
|
||||||
|
check_client_id(#mqtt_packet_connect{client_id = <<>>,
|
||||||
|
clean_start = false}, _PState) ->
|
||||||
|
{error, ?RC_CLIENT_IDENTIFIER_NOT_VALID};
|
||||||
|
|
||||||
|
check_client_id(#mqtt_packet_connect{client_id = <<>>,
|
||||||
|
clean_start = true}, _PState) ->
|
||||||
|
ok;
|
||||||
|
|
||||||
check_client_id(#mqtt_packet_connect{client_id = ClientId}, #pstate{zone = Zone}) ->
|
check_client_id(#mqtt_packet_connect{client_id = ClientId}, #pstate{zone = Zone}) ->
|
||||||
Len = byte_size(ClientId),
|
Len = byte_size(ClientId),
|
||||||
MaxLen = emqx_zone:get_env(Zone, max_clientid_len),
|
MaxLen = emqx_zone:get_env(Zone, max_clientid_len),
|
||||||
|
|
|
@ -15,7 +15,10 @@
|
||||||
%% @doc MQTT5 reason codes
|
%% @doc MQTT5 reason codes
|
||||||
-module(emqx_reason_codes).
|
-module(emqx_reason_codes).
|
||||||
|
|
||||||
|
-include("emqx_mqtt.hrl").
|
||||||
|
|
||||||
-export([name/1, text/1]).
|
-export([name/1, text/1]).
|
||||||
|
-export([compat/2]).
|
||||||
|
|
||||||
name(16#00) -> success;
|
name(16#00) -> success;
|
||||||
name(16#01) -> granted_qos1;
|
name(16#01) -> granted_qos1;
|
||||||
|
@ -107,3 +110,21 @@ text(16#A1) -> <<"Subscription Identifiers not supported">>;
|
||||||
text(16#A2) -> <<"Wildcard Subscriptions not supported">>;
|
text(16#A2) -> <<"Wildcard Subscriptions not supported">>;
|
||||||
text(Code) -> iolist_to_binary(["Unkown Reason Code:", integer_to_list(Code)]).
|
text(Code) -> iolist_to_binary(["Unkown Reason Code:", integer_to_list(Code)]).
|
||||||
|
|
||||||
|
compat(connack, 16#80) -> ?CONNACK_PROTO_VER;
|
||||||
|
compat(connack, 16#81) -> ?CONNACK_PROTO_VER;
|
||||||
|
compat(connack, 16#82) -> ?CONNACK_PROTO_VER;
|
||||||
|
compat(connack, 16#83) -> ?CONNACK_PROTO_VER;
|
||||||
|
compat(connack, 16#84) -> ?CONNACK_PROTO_VER;
|
||||||
|
compat(connack, 16#85) -> ?CONNACK_INVALID_ID;
|
||||||
|
compat(connack, 16#86) -> ?CONNACK_CREDENTIALS;
|
||||||
|
compat(connack, 16#87) -> ?CONNACK_AUTH;
|
||||||
|
compat(connack, 16#88) -> ?CONNACK_SERVER;
|
||||||
|
compat(connack, 16#89) -> ?CONNACK_SERVER;
|
||||||
|
compat(connack, 16#8A) -> ?CONNACK_AUTH;
|
||||||
|
compat(connack, 16#8B) -> ?CONNACK_SERVER;
|
||||||
|
compat(connack, 16#8C) -> ?CONNACK_AUTH;
|
||||||
|
compat(connack, 16#97) -> ?CONNACK_SERVER;
|
||||||
|
compat(connack, 16#9C) -> ?CONNACK_SERVER;
|
||||||
|
compat(connack, 16#9D) -> ?CONNACK_SERVER;
|
||||||
|
compat(connack, 16#9F) -> ?CONNACK_SERVER.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue