test(psk): test psk file reading and handshake
This commit is contained in:
parent
d2684a25c8
commit
f1ff80fc16
|
@ -15,10 +15,85 @@
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
-module(emqx_psk_file_SUITE).
|
-module(emqx_psk_file_SUITE).
|
||||||
|
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
-compile(export_all).
|
-compile(export_all).
|
||||||
|
|
||||||
all() -> [].
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
groups() ->
|
all() ->
|
||||||
[].
|
emqx_ct:all(?MODULE).
|
||||||
|
|
||||||
|
init_per_suite(Config) ->
|
||||||
|
emqx_ct_helpers:start_apps([emqx_psk_file], fun set_special_confs/1),
|
||||||
|
Config.
|
||||||
|
|
||||||
|
end_per_suite(_) ->
|
||||||
|
emqx_ct_helpers:stop_apps([emqx_psk_file]).
|
||||||
|
|
||||||
|
set_special_confs(emqx) ->
|
||||||
|
emqx_ct_helpers:change_emqx_opts(
|
||||||
|
ssl_twoway, [{ssl_options,
|
||||||
|
[{versions, ['tlsv1.2','tlsv1.1', tlsv1]},
|
||||||
|
{ciphers, psk_ciphers()},
|
||||||
|
{user_lookup_fun,{fun emqx_psk:lookup/3,<<>>}}
|
||||||
|
]
|
||||||
|
}]),
|
||||||
|
application:set_env(emqx, plugins_loaded_file,
|
||||||
|
emqx_ct_helpers:deps_path(emqx, "test/emqx_SUITE_data/loaded_plugins"));
|
||||||
|
set_special_confs(emqx_psk_file) ->
|
||||||
|
Path = emqx_ct_helpers:deps_path(emqx_psk_file, "etc/psk.txt"),
|
||||||
|
application:set_env(emqx_psk_file, path, Path),
|
||||||
|
application:set_env(emqx_psk_file, delimiter, ":");
|
||||||
|
set_special_confs(_App) ->
|
||||||
|
ok.
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% cases
|
||||||
|
|
||||||
|
t_psk_loaded(_) ->
|
||||||
|
?assertEqual({stop, <<"1234">>},
|
||||||
|
emqx_psk_file:on_psk_lookup(<<"client1">>, undefined)).
|
||||||
|
|
||||||
|
t_psk_ciphers(_) ->
|
||||||
|
lists:foreach(fun(Cipher) ->
|
||||||
|
{ok, C} = do_emqtt_connect(Cipher),
|
||||||
|
emqtt:disconnect(C)
|
||||||
|
end, psk_ciphers()).
|
||||||
|
|
||||||
|
do_emqtt_connect(Cipher) ->
|
||||||
|
{ok, C} = emqtt:start_link(
|
||||||
|
[{proto_ver, v5},
|
||||||
|
{port, 8883},
|
||||||
|
{ssl, true},
|
||||||
|
{ssl_opts, ssl_opts(Cipher)}
|
||||||
|
]),
|
||||||
|
{ok, _} = emqtt:connect(C),
|
||||||
|
{ok, C}.
|
||||||
|
|
||||||
|
psk_ciphers() ->
|
||||||
|
["RSA-PSK-AES256-GCM-SHA384","RSA-PSK-AES256-CBC-SHA384",
|
||||||
|
"RSA-PSK-AES128-GCM-SHA256","RSA-PSK-AES128-CBC-SHA256",
|
||||||
|
"RSA-PSK-AES256-CBC-SHA","RSA-PSK-AES128-CBC-SHA"].
|
||||||
|
|
||||||
|
ssl_opts(Cipher) ->
|
||||||
|
TlsFile = fun(Name) ->
|
||||||
|
emqx_ct_helpers:app_path(
|
||||||
|
emqx,
|
||||||
|
filename:join(["etc", "certs", Name]))
|
||||||
|
end,
|
||||||
|
[{cacertfile, TlsFile("cacert.pem")},
|
||||||
|
{certfile, TlsFile("client-cert.pem")},
|
||||||
|
{keyfile, TlsFile("client-key.pem")},
|
||||||
|
{verify, verify_peer},
|
||||||
|
{server_name_indication, disable},
|
||||||
|
{protocol, tls},
|
||||||
|
{versions, ['tlsv1.2', 'tlsv1.1']},
|
||||||
|
{psk_identity, "client1"},
|
||||||
|
{user_lookup_fun, {fun ?MODULE:on_psk_client_lookup/3, #{}}},
|
||||||
|
{ciphers, [Cipher]}
|
||||||
|
].
|
||||||
|
|
||||||
|
on_psk_client_lookup(psk, _PSKId, _UserState) ->
|
||||||
|
{stop, Psk} = emqx_psk_file:on_psk_lookup(<<"client1">>, undefined),
|
||||||
|
{ok, Psk}.
|
||||||
|
|
Loading…
Reference in New Issue