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).
|
-module(emqx_cth_suite).
|
||||||
|
|
||||||
-include_lib("common_test/include/ct.hrl").
|
-include_lib("common_test/include/ct.hrl").
|
||||||
-include_lib("emqx/include/emqx_access_control.hrl").
|
|
||||||
|
|
||||||
-export([start/2]).
|
-export([start/2]).
|
||||||
-export([stop/1]).
|
-export([stop/1]).
|
||||||
|
|
|
@ -238,9 +238,12 @@ http_authz_config() ->
|
||||||
init_gateway_conf() ->
|
init_gateway_conf() ->
|
||||||
ok = emqx_common_test_helpers:load_config(
|
ok = emqx_common_test_helpers:load_config(
|
||||||
emqx_gateway_schema,
|
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) ->
|
merge_conf([Conf | T], Acc) ->
|
||||||
case re:run(Conf, "\s*gateway\\.(.*)", [global, {capture, all_but_first, list}, dotall]) of
|
case re:run(Conf, "\s*gateway\\.(.*)", [global, {capture, all_but_first, list}, dotall]) of
|
||||||
{match, [[Content]]} ->
|
{match, [[Content]]} ->
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-include_lib("common_test/include/ct.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),
|
-define(checkMatch(Guard),
|
||||||
(fun(Expr) ->
|
(fun(Expr) ->
|
||||||
|
@ -54,44 +54,33 @@ groups() ->
|
||||||
emqx_gateway_auth_ct:init_groups(?MODULE, ?AUTHNS).
|
emqx_gateway_auth_ct:init_groups(?MODULE, ?AUTHNS).
|
||||||
|
|
||||||
init_per_group(AuthName, Conf) ->
|
init_per_group(AuthName, Conf) ->
|
||||||
{ok, _} = emqx_cluster_rpc:start_link(node(), emqx_cluster_rpc, 1000),
|
Apps = emqx_cth_suite:start(
|
||||||
ok = emqx_authz_test_lib:reset_authorizers(),
|
[
|
||||||
emqx_gateway_auth_ct:start_auth(AuthName),
|
{emqx_conf, "authorization { no_match = deny, cache { enable = false } }"},
|
||||||
timer:sleep(500),
|
emqx_auth,
|
||||||
Conf.
|
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) ->
|
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.
|
Conf.
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
emqx_config:erase(gateway),
|
{ok, Apps1} = application:ensure_all_started(grpc),
|
||||||
emqx_gateway_test_utils:load_all_gateway_apps(),
|
{ok, Apps2} = application:ensure_all_started(cowboy),
|
||||||
init_gateway_conf(),
|
{ok, _} = emqx_gateway_auth_ct:start(),
|
||||||
emqx_mgmt_api_test_util:init_suite([
|
[{suite_apps, Apps1 ++ Apps2} | Config].
|
||||||
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.
|
|
||||||
|
|
||||||
end_per_suite(Config) ->
|
end_per_suite(Config) ->
|
||||||
meck:unload(emqx_authz_file),
|
ok = emqx_gateway_auth_ct:stop(),
|
||||||
emqx_gateway_auth_ct:stop(),
|
ok = emqx_cth_suite:stop_apps(?config(suite_apps, Config)),
|
||||||
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) ->
|
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
|
|
|
@ -103,12 +103,18 @@ assert_fields_exist(Ks, Map) ->
|
||||||
end,
|
end,
|
||||||
Ks
|
Ks
|
||||||
).
|
).
|
||||||
|
|
||||||
load_all_gateway_apps() ->
|
load_all_gateway_apps() ->
|
||||||
application:load(emqx_gateway_stomp),
|
emqx_cth_suite:load_apps(all_gateway_apps()).
|
||||||
application:load(emqx_gateway_mqttsn),
|
|
||||||
application:load(emqx_gateway_coap),
|
all_gateway_apps() ->
|
||||||
application:load(emqx_gateway_lwm2m),
|
[
|
||||||
application:load(emqx_gateway_exproto).
|
emqx_gateway_stomp,
|
||||||
|
emqx_gateway_mqttsn,
|
||||||
|
emqx_gateway_coap,
|
||||||
|
emqx_gateway_lwm2m,
|
||||||
|
emqx_gateway_exproto
|
||||||
|
].
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% http
|
%% http
|
||||||
|
|
|
@ -85,6 +85,12 @@
|
||||||
" listeners.udp.default {\n"
|
" listeners.udp.default {\n"
|
||||||
" bind = 1884\n"
|
" bind = 1884\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
|
"}\n"
|
||||||
|
>>).
|
||||||
|
|
||||||
|
-define(CONF_DTLS, <<
|
||||||
|
"\n"
|
||||||
|
"gateway.mqttsn {"
|
||||||
" listeners.dtls.default {\n"
|
" listeners.dtls.default {\n"
|
||||||
" bind = 1885\n"
|
" bind = 1885\n"
|
||||||
" dtls_options {\n"
|
" dtls_options {\n"
|
||||||
|
@ -110,7 +116,7 @@ init_per_suite(Config) ->
|
||||||
{CACertfile, _} = emqx_cth_tls:write_cert(PrivDir, Root),
|
{CACertfile, _} = emqx_cth_tls:write_cert(PrivDir, Root),
|
||||||
{Certfile, Keyfile} = emqx_cth_tls:write_cert(PrivDir, Server),
|
{Certfile, Keyfile} = emqx_cth_tls:write_cert(PrivDir, Server),
|
||||||
Conf = emqx_template:render_strict(
|
Conf = emqx_template:render_strict(
|
||||||
emqx_template:parse(?CONF_DEFAULT),
|
emqx_template:parse([?CONF_DEFAULT, ?CONF_DTLS]),
|
||||||
#{
|
#{
|
||||||
cacertfile => CACertfile,
|
cacertfile => CACertfile,
|
||||||
certfile => Certfile,
|
certfile => Certfile,
|
||||||
|
|
Loading…
Reference in New Issue