test(chan): verify hooks receive peercert until connected
This commit is contained in:
parent
74c04b847c
commit
3cd95f40e5
|
@ -29,3 +29,33 @@
|
|||
)
|
||||
)
|
||||
).
|
||||
|
||||
-define(drainMailbox(),
|
||||
(fun F__Flush_() ->
|
||||
receive
|
||||
X__Msg_ -> [X__Msg_ | F__Flush_()]
|
||||
after 0 -> []
|
||||
end
|
||||
end)()
|
||||
).
|
||||
|
||||
-define(assertReceive(PATTERN),
|
||||
?assertReceive(PATTERN, 1000)
|
||||
).
|
||||
|
||||
-define(assertReceive(PATTERN, TIMEOUT),
|
||||
(fun() ->
|
||||
receive
|
||||
X__V = PATTERN -> X__V
|
||||
after TIMEOUT ->
|
||||
erlang:error(
|
||||
{assertReceive, [
|
||||
{module, ?MODULE},
|
||||
{line, ?LINE},
|
||||
{expression, (??PATTERN)},
|
||||
{mailbox, ?drainMailbox()}
|
||||
]}
|
||||
)
|
||||
end
|
||||
end)()
|
||||
).
|
||||
|
|
|
@ -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
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue