|
|
@@ -22,6 +22,8 @@
|
|
|
-import(lists, [nth/2]).
|
|
|
|
|
|
-include_lib("emqx/include/emqx_mqtt.hrl").
|
|
|
+-include_lib("emqx/include/emqx_hooks.hrl").
|
|
|
+-include_lib("emqx/include/asserts.hrl").
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
|
-include_lib("common_test/include/ct.hrl").
|
|
|
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
|
|
@@ -76,7 +78,7 @@ groups() ->
|
|
|
t_certcn_as_clientid_default_config_tls,
|
|
|
t_certcn_as_clientid_tlsv1_3,
|
|
|
t_certcn_as_clientid_tlsv1_2,
|
|
|
- t_no_peercert_after_connected
|
|
|
+ t_peercert_preserved_before_connected
|
|
|
]}
|
|
|
].
|
|
|
|
|
|
@@ -380,8 +382,18 @@ t_certcn_as_clientid_tlsv1_3(_) ->
|
|
|
t_certcn_as_clientid_tlsv1_2(_) ->
|
|
|
tls_certcn_as_clientid('tlsv1.2').
|
|
|
|
|
|
-t_no_peercert_after_connected(_) ->
|
|
|
- emqx_config:put_zone_conf(default, [mqtt], #{}),
|
|
|
+t_peercert_preserved_before_connected(_) ->
|
|
|
+ ok = emqx_config:put_zone_conf(default, [mqtt], #{}),
|
|
|
+ ok = emqx_hooks:add(
|
|
|
+ 'client.connect',
|
|
|
+ {?MODULE, on_hook, ['client.connect', self()]},
|
|
|
+ ?HP_HIGHEST
|
|
|
+ ),
|
|
|
+ ok = emqx_hooks:add(
|
|
|
+ 'client.connected',
|
|
|
+ {?MODULE, on_hook, ['client.connected', self()]},
|
|
|
+ ?HP_HIGHEST
|
|
|
+ ),
|
|
|
ClientId = atom_to_binary(?FUNCTION_NAME),
|
|
|
SslConf = emqx_common_test_helpers:client_ssl_twoway(default),
|
|
|
{ok, Client} = emqtt:start_link([
|
|
|
@@ -391,12 +403,21 @@ t_no_peercert_after_connected(_) ->
|
|
|
{ssl_opts, SslConf}
|
|
|
]),
|
|
|
{ok, _} = emqtt:connect(Client),
|
|
|
+ _ = ?assertReceive({'client.connect', #{peercert := PC}} when is_binary(PC)),
|
|
|
+ _ = ?assertReceive({'client.connected', #{peercert := PC}} when is_binary(PC)),
|
|
|
[ConnPid] = emqx_cm:lookup_channels(ClientId),
|
|
|
?assertMatch(
|
|
|
#{conninfo := ConnInfo} when not is_map_key(peercert, ConnInfo),
|
|
|
emqx_connection:info(ConnPid)
|
|
|
).
|
|
|
|
|
|
+on_hook(ConnInfo, _, 'client.connect' = HP, Pid) ->
|
|
|
+ _ = Pid ! {HP, ConnInfo},
|
|
|
+ ok;
|
|
|
+on_hook(_ClientInfo, ConnInfo, 'client.connected' = HP, Pid) ->
|
|
|
+ _ = Pid ! {HP, ConnInfo},
|
|
|
+ ok.
|
|
|
+
|
|
|
%%--------------------------------------------------------------------
|
|
|
%% Helper functions
|
|
|
%%--------------------------------------------------------------------
|