Merge branch 'issue#599' into emq10
This commit is contained in:
commit
b877cec208
|
@ -46,7 +46,7 @@
|
||||||
%% Authetication. Anonymous Default
|
%% Authetication. Anonymous Default
|
||||||
{auth, [
|
{auth, [
|
||||||
%% Authentication with username, password
|
%% Authentication with username, password
|
||||||
{username, [{test, "password"}, {"test1", "password1"}]},
|
%% {username, [{test, "password"}, {"test1", "password1"}]},
|
||||||
|
|
||||||
%% Authentication with clientid
|
%% Authentication with clientid
|
||||||
%{clientid, [{password, no}, {file, "etc/clients.config"}]},
|
%{clientid, [{password, no}, {file, "etc/clients.config"}]},
|
||||||
|
@ -104,8 +104,8 @@
|
||||||
%% Statistics Collection Interval(seconds)
|
%% Statistics Collection Interval(seconds)
|
||||||
{collect_interval, 20},
|
{collect_interval, 20},
|
||||||
|
|
||||||
%% Expired after 2 days
|
%% Expired after 2 day (unit: minute)
|
||||||
{expired_after, 48}
|
{expired_after, 2880}
|
||||||
|
|
||||||
]},
|
]},
|
||||||
%% Queue
|
%% Queue
|
||||||
|
@ -173,14 +173,12 @@
|
||||||
|
|
||||||
%% Subscribe topics automatically when client connected
|
%% Subscribe topics automatically when client connected
|
||||||
{subscription, [
|
{subscription, [
|
||||||
|
|
||||||
|
%% $c will be replaced by clientid
|
||||||
|
%% {"$queue/clients/$c", 1},
|
||||||
|
|
||||||
%% Static subscriptions from backend
|
%% Static subscriptions from backend
|
||||||
backend,
|
backend
|
||||||
|
|
||||||
%% $u will be replaced with username
|
|
||||||
{"$queue/username/$u", 1},
|
|
||||||
|
|
||||||
%% $c will be replaced with clientid
|
|
||||||
{"$queue/clients/$c", 1}
|
|
||||||
]}
|
]}
|
||||||
|
|
||||||
%% Rewrite rules
|
%% Rewrite rules
|
||||||
|
|
|
@ -336,6 +336,12 @@ validate_clientid(#mqtt_packet_connect{client_id = ClientId},
|
||||||
when (size(ClientId) >= 1) andalso (size(ClientId) =< MaxLen) ->
|
when (size(ClientId) >= 1) andalso (size(ClientId) =< MaxLen) ->
|
||||||
true;
|
true;
|
||||||
|
|
||||||
|
%% Issue#599: Null clientId and clean_sess = false
|
||||||
|
validate_clientid(#mqtt_packet_connect{client_id = ClientId,
|
||||||
|
clean_sess = CleanSess}, _ProtoState)
|
||||||
|
when size(ClientId) == 0 andalso (not CleanSess) ->
|
||||||
|
false;
|
||||||
|
|
||||||
%% MQTT3.1.1 allow null clientId.
|
%% MQTT3.1.1 allow null clientId.
|
||||||
validate_clientid(#mqtt_packet_connect{proto_ver =?MQTT_PROTO_V311,
|
validate_clientid(#mqtt_packet_connect{proto_ver =?MQTT_PROTO_V311,
|
||||||
client_id = ClientId}, _ProtoState)
|
client_id = ClientId}, _ProtoState)
|
||||||
|
|
|
@ -23,7 +23,8 @@
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
[{group, pubsub},
|
[{group, protocol},
|
||||||
|
{group, pubsub},
|
||||||
{group, router},
|
{group, router},
|
||||||
{group, session},
|
{group, session},
|
||||||
{group, retainer},
|
{group, retainer},
|
||||||
|
@ -35,7 +36,9 @@ all() ->
|
||||||
{group, cli}].
|
{group, cli}].
|
||||||
|
|
||||||
groups() ->
|
groups() ->
|
||||||
[{pubsub, [sequence],
|
[{protocol, [sequence],
|
||||||
|
[mqtt_connect]},
|
||||||
|
{pubsub, [sequence],
|
||||||
[create_topic,
|
[create_topic,
|
||||||
create_subscription,
|
create_subscription,
|
||||||
subscribe_unsubscribe,
|
subscribe_unsubscribe,
|
||||||
|
@ -88,6 +91,24 @@ end_per_suite(_Config) ->
|
||||||
application:stop(gproc),
|
application:stop(gproc),
|
||||||
emqttd_mnesia:ensure_stopped().
|
emqttd_mnesia:ensure_stopped().
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% Protocol Test
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
|
mqtt_connect(_) ->
|
||||||
|
%% Issue #599
|
||||||
|
%% Empty clientId and clean_session = false
|
||||||
|
?assertEqual(<<32,2,0,2>>, connect_broker_(<<16,12,0,4,77,81,84,84,4,0,0,90,0,0>>, 4)),
|
||||||
|
%% Empty clientId and clean_session = true
|
||||||
|
?assertEqual(<<32,2,0,0>>, connect_broker_(<<16,12,0,4,77,81,84,84,4,2,0,90,0,0>>, 4)).
|
||||||
|
|
||||||
|
connect_broker_(Packet, RecvSize) ->
|
||||||
|
{ok, Sock} = gen_tcp:connect({127,0,0,1}, 1883, [binary, {packet, raw}, {active, false}]),
|
||||||
|
gen_tcp:send(Sock, Packet),
|
||||||
|
{ok, Data} = gen_tcp:recv(Sock, RecvSize, 3000),
|
||||||
|
gen_tcp:close(Sock),
|
||||||
|
Data.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% PubSub Test
|
%% PubSub Test
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -156,6 +177,7 @@ pubsub_queue(_) ->
|
||||||
Self = self(), Q = <<"$queue/abc">>,
|
Self = self(), Q = <<"$queue/abc">>,
|
||||||
SubFun = fun() ->
|
SubFun = fun() ->
|
||||||
emqttd:subscribe(Q),
|
emqttd:subscribe(Q),
|
||||||
|
timer:sleep(1),
|
||||||
{ok, Msgs} = loop_recv(Q, 10),
|
{ok, Msgs} = loop_recv(Q, 10),
|
||||||
Self ! {recv, self(), Msgs}
|
Self ! {recv, self(), Msgs}
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Reference in New Issue