test(gw-authz): switch to `emqx_cth_suite` + simplify testsuite
Also separate DTLS related MQTT-SN test config, so that it doesn't leak into this test suite.
This commit is contained in:
parent
32a64cf201
commit
76c89ad372
|
@ -58,7 +58,6 @@
|
|||
-module(emqx_cth_suite).
|
||||
|
||||
-include_lib("common_test/include/ct.hrl").
|
||||
-include_lib("emqx/include/emqx_access_control.hrl").
|
||||
|
||||
-export([start/2]).
|
||||
-export([stop/1]).
|
||||
|
|
|
@ -238,9 +238,12 @@ http_authz_config() ->
|
|||
init_gateway_conf() ->
|
||||
ok = emqx_common_test_helpers:load_config(
|
||||
emqx_gateway_schema,
|
||||
merge_conf([X:default_config() || X <- ?CONFS], [])
|
||||
merge_conf(list_gateway_conf(), [])
|
||||
).
|
||||
|
||||
list_gateway_conf() ->
|
||||
[X:default_config() || X <- ?CONFS].
|
||||
|
||||
merge_conf([Conf | T], Acc) ->
|
||||
case re:run(Conf, "\s*gateway\\.(.*)", [global, {capture, all_but_first, list}, dotall]) of
|
||||
{match, [[Content]]} ->
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include_lib("common_test/include/ct.hrl").
|
||||
|
||||
-import(emqx_gateway_auth_ct, [init_gateway_conf/0, with_resource/3]).
|
||||
-import(emqx_gateway_auth_ct, [with_resource/3]).
|
||||
|
||||
-define(checkMatch(Guard),
|
||||
(fun(Expr) ->
|
||||
|
@ -54,44 +54,33 @@ groups() ->
|
|||
emqx_gateway_auth_ct:init_groups(?MODULE, ?AUTHNS).
|
||||
|
||||
init_per_group(AuthName, Conf) ->
|
||||
{ok, _} = emqx_cluster_rpc:start_link(node(), emqx_cluster_rpc, 1000),
|
||||
ok = emqx_authz_test_lib:reset_authorizers(),
|
||||
emqx_gateway_auth_ct:start_auth(AuthName),
|
||||
timer:sleep(500),
|
||||
Conf.
|
||||
Apps = emqx_cth_suite:start(
|
||||
[
|
||||
{emqx_conf, "authorization { no_match = deny, cache { enable = false } }"},
|
||||
emqx_auth,
|
||||
emqx_auth_http,
|
||||
{emqx_gateway, emqx_gateway_auth_ct:list_gateway_conf()}
|
||||
| emqx_gateway_test_utils:all_gateway_apps()
|
||||
],
|
||||
#{work_dir => emqx_cth_suite:work_dir(Conf)}
|
||||
),
|
||||
ok = emqx_gateway_auth_ct:start_auth(AuthName),
|
||||
[{group_apps, Apps} | Conf].
|
||||
|
||||
end_per_group(AuthName, Conf) ->
|
||||
emqx_gateway_auth_ct:stop_auth(AuthName),
|
||||
ok = emqx_gateway_auth_ct:stop_auth(AuthName),
|
||||
ok = emqx_cth_suite:stop(?config(group_apps, Conf)),
|
||||
Conf.
|
||||
|
||||
init_per_suite(Config) ->
|
||||
emqx_config:erase(gateway),
|
||||
emqx_gateway_test_utils:load_all_gateway_apps(),
|
||||
init_gateway_conf(),
|
||||
emqx_mgmt_api_test_util:init_suite([
|
||||
grpc, emqx_conf, emqx_auth, emqx_auth_http, emqx_gateway
|
||||
]),
|
||||
meck:new(emqx_authz_file, [non_strict, passthrough, no_history, no_link]),
|
||||
meck:expect(emqx_authz_file, create, fun(S) -> S end),
|
||||
application:ensure_all_started(cowboy),
|
||||
emqx_gateway_auth_ct:start(),
|
||||
Config.
|
||||
{ok, Apps1} = application:ensure_all_started(grpc),
|
||||
{ok, Apps2} = application:ensure_all_started(cowboy),
|
||||
{ok, _} = emqx_gateway_auth_ct:start(),
|
||||
[{suite_apps, Apps1 ++ Apps2} | Config].
|
||||
|
||||
end_per_suite(Config) ->
|
||||
meck:unload(emqx_authz_file),
|
||||
emqx_gateway_auth_ct:stop(),
|
||||
ok = emqx_authz_test_lib:restore_authorizers(),
|
||||
emqx_config:erase(gateway),
|
||||
emqx_mgmt_api_test_util:end_suite([
|
||||
emqx_gateway, emqx_auth_http, emqx_auth, emqx_conf, grpc
|
||||
]),
|
||||
Config.
|
||||
|
||||
init_per_testcase(_Case, Config) ->
|
||||
{ok, _} = emqx_cluster_rpc:start_link(node(), emqx_cluster_rpc, 1000),
|
||||
Config.
|
||||
|
||||
end_per_testcase(_Case, Config) ->
|
||||
ok = emqx_gateway_auth_ct:stop(),
|
||||
ok = emqx_cth_suite:stop_apps(?config(suite_apps, Config)),
|
||||
Config.
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
|
|
|
@ -103,12 +103,18 @@ assert_fields_exist(Ks, Map) ->
|
|||
end,
|
||||
Ks
|
||||
).
|
||||
|
||||
load_all_gateway_apps() ->
|
||||
application:load(emqx_gateway_stomp),
|
||||
application:load(emqx_gateway_mqttsn),
|
||||
application:load(emqx_gateway_coap),
|
||||
application:load(emqx_gateway_lwm2m),
|
||||
application:load(emqx_gateway_exproto).
|
||||
emqx_cth_suite:load_apps(all_gateway_apps()).
|
||||
|
||||
all_gateway_apps() ->
|
||||
[
|
||||
emqx_gateway_stomp,
|
||||
emqx_gateway_mqttsn,
|
||||
emqx_gateway_coap,
|
||||
emqx_gateway_lwm2m,
|
||||
emqx_gateway_exproto
|
||||
].
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% http
|
||||
|
|
|
@ -85,6 +85,12 @@
|
|||
" listeners.udp.default {\n"
|
||||
" bind = 1884\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
>>).
|
||||
|
||||
-define(CONF_DTLS, <<
|
||||
"\n"
|
||||
"gateway.mqttsn {"
|
||||
" listeners.dtls.default {\n"
|
||||
" bind = 1885\n"
|
||||
" dtls_options {\n"
|
||||
|
@ -110,7 +116,7 @@ init_per_suite(Config) ->
|
|||
{CACertfile, _} = emqx_cth_tls:write_cert(PrivDir, Root),
|
||||
{Certfile, Keyfile} = emqx_cth_tls:write_cert(PrivDir, Server),
|
||||
Conf = emqx_template:render_strict(
|
||||
emqx_template:parse(?CONF_DEFAULT),
|
||||
emqx_template:parse([?CONF_DEFAULT, ?CONF_DTLS]),
|
||||
#{
|
||||
cacertfile => CACertfile,
|
||||
certfile => Certfile,
|
||||
|
|
Loading…
Reference in New Issue