parent
cc25ec5835
commit
47720b906f
|
@ -1012,6 +1012,9 @@ maybe_username_as_clientid(_ConnPkt, ClientInfo = #{zone := Zone, username := Us
|
||||||
false -> ok
|
false -> ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
maybe_assign_clientid(_ConnPkt, ClientInfo = #{clientid := ClientId})
|
||||||
|
when ClientId /= undefined ->
|
||||||
|
{ok, ClientInfo};
|
||||||
maybe_assign_clientid(#mqtt_packet_connect{clientid = <<>>}, ClientInfo) ->
|
maybe_assign_clientid(#mqtt_packet_connect{clientid = <<>>}, ClientInfo) ->
|
||||||
%% Generate a rand clientId
|
%% Generate a rand clientId
|
||||||
{ok, ClientInfo#{clientid => emqx_guid:to_base62(emqx_guid:gen())}};
|
{ok, ClientInfo#{clientid => emqx_guid:to_base62(emqx_guid:gen())}};
|
||||||
|
|
|
@ -45,7 +45,8 @@
|
||||||
all() ->
|
all() ->
|
||||||
[{group, mqttv3},
|
[{group, mqttv3},
|
||||||
{group, mqttv4},
|
{group, mqttv4},
|
||||||
{group, mqttv5}
|
{group, mqttv5},
|
||||||
|
{group, others}
|
||||||
].
|
].
|
||||||
|
|
||||||
groups() ->
|
groups() ->
|
||||||
|
@ -66,17 +67,26 @@ groups() ->
|
||||||
]},
|
]},
|
||||||
{mqttv5, [non_parallel_tests],
|
{mqttv5, [non_parallel_tests],
|
||||||
[t_basic_with_props_v5
|
[t_basic_with_props_v5
|
||||||
|
]},
|
||||||
|
{others, [non_parallel_tests],
|
||||||
|
[t_username_as_clientid,
|
||||||
|
t_certcn_as_clientid
|
||||||
]}
|
]}
|
||||||
].
|
].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
emqx_ct_helpers:boot_modules(all),
|
emqx_ct_helpers:boot_modules(all),
|
||||||
emqx_ct_helpers:start_apps([]),
|
emqx_ct_helpers:start_apps([], fun set_special_confs/1),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
emqx_ct_helpers:stop_apps([]).
|
emqx_ct_helpers:stop_apps([]).
|
||||||
|
|
||||||
|
set_special_confs(emqx) ->
|
||||||
|
emqx_ct_helpers:change_emqx_opts(ssl_twoway, [{peer_cert_as_username, cn}]);
|
||||||
|
set_special_confs(_) ->
|
||||||
|
ok.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Test cases for MQTT v3
|
%% Test cases for MQTT v3
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
@ -110,10 +120,7 @@ t_cm_registry(_) ->
|
||||||
{_, Pid, _, _} = lists:keyfind(registry, 1, Info),
|
{_, Pid, _, _} = lists:keyfind(registry, 1, Info),
|
||||||
ignored = gen_server:call(Pid, <<"Unexpected call">>),
|
ignored = gen_server:call(Pid, <<"Unexpected call">>),
|
||||||
gen_server:cast(Pid, <<"Unexpected cast">>),
|
gen_server:cast(Pid, <<"Unexpected cast">>),
|
||||||
Pid ! <<"Unexpected info">>,
|
Pid ! <<"Unexpected info">>.
|
||||||
ok = application:stop(mnesia),
|
|
||||||
emqx_ct_helpers:stop_apps([]),
|
|
||||||
emqx_ct_helpers:start_apps([]).
|
|
||||||
|
|
||||||
t_will_message(_Config) ->
|
t_will_message(_Config) ->
|
||||||
{ok, C1} = emqtt:start_link([{clean_start, true},
|
{ok, C1} = emqtt:start_link([{clean_start, true},
|
||||||
|
@ -263,6 +270,23 @@ t_basic(_Opts) ->
|
||||||
?assertEqual(3, length(recv_msgs(3))),
|
?assertEqual(3, length(recv_msgs(3))),
|
||||||
ok = emqtt:disconnect(C).
|
ok = emqtt:disconnect(C).
|
||||||
|
|
||||||
|
t_username_as_clientid(_) ->
|
||||||
|
emqx_zone:set_env(external, use_username_as_clientid, true),
|
||||||
|
Username = <<"usera">>,
|
||||||
|
{ok, C} = emqtt:start_link([{username, Username}]),
|
||||||
|
{ok, _} = emqtt:connect(C),
|
||||||
|
#{clientinfo := #{clientid := Username}} = emqx_cm:get_chan_info(Username),
|
||||||
|
emqtt:disconnect(C).
|
||||||
|
|
||||||
|
t_certcn_as_clientid(_) ->
|
||||||
|
CN = <<"0004.novalocal">>,
|
||||||
|
emqx_zone:set_env(external, use_username_as_clientid, true),
|
||||||
|
SslConf = emqx_ct_helpers:client_ssl_twoway(),
|
||||||
|
{ok, C} = emqtt:start_link([{port, 8883}, {ssl, true}, {ssl_opts, SslConf}]),
|
||||||
|
{ok, _} = emqtt:connect(C),
|
||||||
|
#{clientinfo := #{clientid := CN}} = emqx_cm:get_chan_info(CN),
|
||||||
|
emqtt:disconnect(C).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Helper functions
|
%% Helper functions
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue