test(authz): deps on emqx_conf instead of meck emqx_schema
This commit is contained in:
parent
883c1b2e59
commit
814e01c0cb
|
@ -22,8 +22,6 @@
|
||||||
-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").
|
||||||
|
|
||||||
-define(CONF_DEFAULT, <<"authorization: {sources: []}">>).
|
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
emqx_common_test_helpers:all(?MODULE).
|
emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
|
@ -31,35 +29,33 @@ groups() ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
|
|
||||||
meck:expect(emqx_schema, fields, fun("authorization") ->
|
|
||||||
meck:passthrough(["authorization"]) ++
|
|
||||||
emqx_authz_schema:fields("authorization");
|
|
||||||
(F) -> meck:passthrough([F])
|
|
||||||
end),
|
|
||||||
|
|
||||||
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
||||||
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end),
|
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end),
|
||||||
meck:expect(emqx_resource, update, fun(_, _, _, _) -> {ok, meck_data} end),
|
meck:expect(emqx_resource, update, fun(_, _, _, _) -> {ok, meck_data} end),
|
||||||
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
|
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
|
||||||
|
|
||||||
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
|
ok = emqx_common_test_helpers:start_apps(
|
||||||
ok = emqx_common_test_helpers:start_apps([emqx_authz]),
|
[emqx_conf, emqx_authz], fun set_special_configs/1),
|
||||||
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
|
||||||
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(?CMD_REPLACE, []),
|
{ok, _} = emqx_authz:update(?CMD_REPLACE, []),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_resource]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
||||||
meck:unload(emqx_resource),
|
meck:unload(emqx_resource),
|
||||||
meck:unload(emqx_schema),
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
init_per_testcase(_, Config) ->
|
init_per_testcase(_, Config) ->
|
||||||
{ok, _} = emqx_authz:update(?CMD_REPLACE, []),
|
{ok, _} = emqx_authz:update(?CMD_REPLACE, []),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
|
set_special_configs(emqx_authz) ->
|
||||||
|
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
||||||
|
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
||||||
|
{ok, _} = emqx:update_config([authorization, sources], []),
|
||||||
|
ok;
|
||||||
|
set_special_configs(_App) ->
|
||||||
|
ok.
|
||||||
|
|
||||||
-define(SOURCE1, #{<<"type">> => <<"http">>,
|
-define(SOURCE1, #{<<"type">> => <<"http">>,
|
||||||
<<"enable">> => true,
|
<<"enable">> => true,
|
||||||
<<"url">> => <<"https://fake.com:443/">>,
|
<<"url">> => <<"https://fake.com:443/">>,
|
||||||
|
|
|
@ -22,26 +22,11 @@
|
||||||
-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").
|
||||||
|
|
||||||
-define(CONF_DEFAULT, <<"""
|
|
||||||
authorization
|
|
||||||
{sources = [
|
|
||||||
{ type = \"built-in-database\"
|
|
||||||
enable = true
|
|
||||||
}
|
|
||||||
]}
|
|
||||||
""">>).
|
|
||||||
|
|
||||||
-define(HOST, "http://127.0.0.1:18083/").
|
-define(HOST, "http://127.0.0.1:18083/").
|
||||||
-define(API_VERSION, "v5").
|
-define(API_VERSION, "v5").
|
||||||
-define(BASE_PATH, "api").
|
-define(BASE_PATH, "api").
|
||||||
|
|
||||||
|
|
||||||
roots() -> ["authorization"].
|
|
||||||
|
|
||||||
fields("authorization") ->
|
|
||||||
emqx_authz_schema:fields("authorization") ++
|
|
||||||
emqx_schema:fields("authorization").
|
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
emqx_common_test_helpers:all(?MODULE).
|
emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
|
@ -49,13 +34,14 @@ groups() ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
ok = emqx_common_test_helpers:start_apps([emqx_authz, emqx_dashboard],
|
ok = emqx_common_test_helpers:start_apps(
|
||||||
fun set_special_configs/1),
|
[emqx_conf, emqx_authz, emqx_dashboard],
|
||||||
|
fun set_special_configs/1),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx_authz:update(replace, []),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_dashboard]),
|
emqx_common_test_helpers:stop_apps([emqx_dashboard, emqx_authz, emqx_conf]),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
set_special_configs(emqx_dashboard) ->
|
set_special_configs(emqx_dashboard) ->
|
||||||
|
@ -70,9 +56,10 @@ set_special_configs(emqx_dashboard) ->
|
||||||
emqx_config:put([emqx_dashboard], Config),
|
emqx_config:put([emqx_dashboard], Config),
|
||||||
ok;
|
ok;
|
||||||
set_special_configs(emqx_authz) ->
|
set_special_configs(emqx_authz) ->
|
||||||
ok = emqx_config:init_load(?MODULE, ?CONF_DEFAULT),
|
|
||||||
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
||||||
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
||||||
|
{ok, _} = emqx:update_config([authorization, sources],
|
||||||
|
[#{<<"type">> => <<"built-in-database">>}]),
|
||||||
ok;
|
ok;
|
||||||
set_special_configs(_App) ->
|
set_special_configs(_App) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
-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").
|
||||||
|
|
||||||
-define(CONF_DEFAULT, <<"authorization: {sources: []}">>).
|
|
||||||
|
|
||||||
-define(HOST, "http://127.0.0.1:18083/").
|
-define(HOST, "http://127.0.0.1:18083/").
|
||||||
-define(API_VERSION, "v5").
|
-define(API_VERSION, "v5").
|
||||||
-define(BASE_PATH, "api").
|
-define(BASE_PATH, "api").
|
||||||
|
@ -35,14 +33,14 @@ groups() ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
ok = emqx_common_test_helpers:start_apps([emqx_authz, emqx_dashboard], fun set_special_configs/1),
|
ok = emqx_common_test_helpers:start_apps(
|
||||||
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
[emqx_conf, emqx_authz, emqx_dashboard],
|
||||||
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
fun set_special_configs/1),
|
||||||
|
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
emqx_common_test_helpers:stop_apps([emqx_resource, emqx_authz, emqx_dashboard]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_dashboard]),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
set_special_configs(emqx_dashboard) ->
|
set_special_configs(emqx_dashboard) ->
|
||||||
|
@ -56,6 +54,11 @@ set_special_configs(emqx_dashboard) ->
|
||||||
},
|
},
|
||||||
emqx_config:put([emqx_dashboard], Config),
|
emqx_config:put([emqx_dashboard], Config),
|
||||||
ok;
|
ok;
|
||||||
|
set_special_configs(emqx_authz) ->
|
||||||
|
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
||||||
|
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
||||||
|
{ok, _} = emqx:update_config([authorization, sources], []),
|
||||||
|
ok;
|
||||||
set_special_configs(_App) ->
|
set_special_configs(_App) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
-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").
|
||||||
|
|
||||||
-define(CONF_DEFAULT, <<"authorization: {sources: []}">>).
|
|
||||||
|
|
||||||
-define(HOST, "http://127.0.0.1:18083/").
|
-define(HOST, "http://127.0.0.1:18083/").
|
||||||
-define(API_VERSION, "v5").
|
-define(API_VERSION, "v5").
|
||||||
-define(BASE_PATH, "api").
|
-define(BASE_PATH, "api").
|
||||||
|
@ -94,13 +92,6 @@ groups() ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
|
|
||||||
meck:expect(emqx_schema, fields, fun("authorization") ->
|
|
||||||
meck:passthrough(["authorization"]) ++
|
|
||||||
emqx_authz_schema:fields("authorization");
|
|
||||||
(F) -> meck:passthrough([F])
|
|
||||||
end),
|
|
||||||
|
|
||||||
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
||||||
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end),
|
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end),
|
||||||
meck:expect(emqx_resource, create_dry_run, fun(emqx_connector_mysql, _) -> {ok, meck_data};
|
meck:expect(emqx_resource, create_dry_run, fun(emqx_connector_mysql, _) -> {ok, meck_data};
|
||||||
|
@ -110,19 +101,15 @@ init_per_suite(Config) ->
|
||||||
meck:expect(emqx_resource, health_check, fun(_) -> ok end),
|
meck:expect(emqx_resource, health_check, fun(_) -> ok end),
|
||||||
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
|
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
|
||||||
|
|
||||||
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
|
ok = emqx_common_test_helpers:start_apps(
|
||||||
|
[emqx_conf, emqx_authz, emqx_dashboard],
|
||||||
ok = emqx_common_test_helpers:start_apps([emqx_authz, emqx_dashboard], fun set_special_configs/1),
|
fun set_special_configs/1),
|
||||||
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
|
||||||
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
|
||||||
|
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx_authz:update(replace, []),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_resource, emqx_authz, emqx_dashboard]),
|
emqx_common_test_helpers:stop_apps([emqx_dashboard, emqx_authz, emqx_conf]),
|
||||||
meck:unload(emqx_resource),
|
meck:unload(emqx_resource),
|
||||||
meck:unload(emqx_schema),
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
set_special_configs(emqx_dashboard) ->
|
set_special_configs(emqx_dashboard) ->
|
||||||
|
@ -137,7 +124,9 @@ set_special_configs(emqx_dashboard) ->
|
||||||
emqx_config:put([emqx_dashboard], Config),
|
emqx_config:put([emqx_dashboard], Config),
|
||||||
ok;
|
ok;
|
||||||
set_special_configs(emqx_authz) ->
|
set_special_configs(emqx_authz) ->
|
||||||
emqx_config:put([authorization], #{sources => []}),
|
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
||||||
|
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
||||||
|
{ok, _} = emqx:update_config([authorization, sources], []),
|
||||||
ok;
|
ok;
|
||||||
set_special_configs(_App) ->
|
set_special_configs(_App) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
-include("emqx_authz.hrl").
|
-include("emqx_authz.hrl").
|
||||||
-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").
|
||||||
-define(CONF_DEFAULT, <<"authorization: {sources: []}">>).
|
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
emqx_common_test_helpers:all(?MODULE).
|
emqx_common_test_helpers:all(?MODULE).
|
||||||
|
@ -30,22 +29,14 @@ groups() ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
|
|
||||||
meck:expect(emqx_schema, fields, fun("authorization") ->
|
|
||||||
meck:passthrough(["authorization"]) ++
|
|
||||||
emqx_authz_schema:fields("authorization");
|
|
||||||
(F) -> meck:passthrough([F])
|
|
||||||
end),
|
|
||||||
|
|
||||||
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
||||||
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end),
|
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end),
|
||||||
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
|
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
|
||||||
|
|
||||||
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
|
ok = emqx_common_test_helpers:start_apps(
|
||||||
ok = emqx_common_test_helpers:start_apps([emqx_authz]),
|
[emqx_conf, emqx_authz],
|
||||||
|
fun set_special_configs/1),
|
||||||
|
|
||||||
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
|
||||||
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
|
||||||
Rules = [#{<<"type">> => <<"http">>,
|
Rules = [#{<<"type">> => <<"http">>,
|
||||||
<<"url">> => <<"https://fake.com:443/">>,
|
<<"url">> => <<"https://fake.com:443/">>,
|
||||||
<<"headers">> => #{},
|
<<"headers">> => #{},
|
||||||
|
@ -58,9 +49,16 @@ init_per_suite(Config) ->
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx_authz:update(replace, []),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_resource]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
||||||
meck:unload(emqx_resource),
|
meck:unload(emqx_resource),
|
||||||
meck:unload(emqx_schema),
|
ok.
|
||||||
|
|
||||||
|
set_special_configs(emqx_authz) ->
|
||||||
|
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
||||||
|
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
||||||
|
{ok, _} = emqx:update_config([authorization, sources], []),
|
||||||
|
ok;
|
||||||
|
set_special_configs(_App) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
-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").
|
||||||
|
|
||||||
-define(CONF_DEFAULT, <<"authorization: {sources: []}">>).
|
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
emqx_common_test_helpers:all(?MODULE).
|
emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
|
@ -31,26 +29,24 @@ groups() ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
|
ok = emqx_common_test_helpers:start_apps(
|
||||||
meck:expect(emqx_schema, fields, fun("authorization") ->
|
[emqx_conf, emqx_authz],
|
||||||
meck:passthrough(["authorization"]) ++
|
fun set_special_configs/1
|
||||||
emqx_authz_schema:fields("authorization");
|
),
|
||||||
(F) -> meck:passthrough([F])
|
|
||||||
end),
|
|
||||||
|
|
||||||
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
|
|
||||||
ok = emqx_common_test_helpers:start_apps([emqx_authz]),
|
|
||||||
|
|
||||||
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
|
||||||
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
|
||||||
Rules = [#{<<"type">> => <<"built-in-database">>}],
|
|
||||||
{ok, _} = emqx_authz:update(replace, Rules),
|
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx_authz:update(replace, []),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
||||||
meck:unload(emqx_schema),
|
ok.
|
||||||
|
|
||||||
|
set_special_configs(emqx_authz) ->
|
||||||
|
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
||||||
|
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
||||||
|
{ok, _} = emqx:update_config([authorization, sources],
|
||||||
|
[#{<<"type">> => <<"built-in-database">>}]),
|
||||||
|
ok;
|
||||||
|
set_special_configs(_App) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
init_per_testcase(t_authz, Config) ->
|
init_per_testcase(t_authz, Config) ->
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
-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").
|
||||||
|
|
||||||
-define(CONF_DEFAULT, <<"authorization: {sources: []}">>).
|
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
emqx_common_test_helpers:all(?MODULE).
|
emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
|
@ -31,21 +29,15 @@ groups() ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
|
|
||||||
meck:expect(emqx_schema, fields, fun("authorization") ->
|
|
||||||
meck:passthrough(["authorization"]) ++
|
|
||||||
emqx_authz_schema:fields("authorization");
|
|
||||||
(F) -> meck:passthrough([F])
|
|
||||||
end),
|
|
||||||
|
|
||||||
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
||||||
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end),
|
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end),
|
||||||
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
|
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
|
||||||
|
|
||||||
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
|
ok = emqx_common_test_helpers:start_apps(
|
||||||
ok = emqx_common_test_helpers:start_apps([emqx_authz]),
|
[emqx_conf, emqx_authz],
|
||||||
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
fun set_special_configs/1
|
||||||
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
),
|
||||||
|
|
||||||
Rules = [#{<<"type">> => <<"mongodb">>,
|
Rules = [#{<<"type">> => <<"mongodb">>,
|
||||||
<<"mongo_type">> => <<"single">>,
|
<<"mongo_type">> => <<"single">>,
|
||||||
<<"server">> => <<"127.0.0.1:27017">>,
|
<<"server">> => <<"127.0.0.1:27017">>,
|
||||||
|
@ -60,9 +52,16 @@ init_per_suite(Config) ->
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx_authz:update(replace, []),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_resource]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
||||||
meck:unload(emqx_resource),
|
meck:unload(emqx_resource),
|
||||||
meck:unload(emqx_schema),
|
ok.
|
||||||
|
|
||||||
|
set_special_configs(emqx_authz) ->
|
||||||
|
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
||||||
|
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
||||||
|
{ok, _} = emqx:update_config([authorization, sources], []),
|
||||||
|
ok;
|
||||||
|
set_special_configs(_App) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
-define(SOURCE1,[#{<<"topics">> => [<<"#">>],
|
-define(SOURCE1,[#{<<"topics">> => [<<"#">>],
|
||||||
|
|
|
@ -31,22 +31,14 @@ groups() ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
|
|
||||||
meck:expect(emqx_schema, fields, fun("authorization") ->
|
|
||||||
meck:passthrough(["authorization"]) ++
|
|
||||||
emqx_authz_schema:fields("authorization");
|
|
||||||
(F) -> meck:passthrough([F])
|
|
||||||
end),
|
|
||||||
|
|
||||||
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
||||||
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ),
|
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ),
|
||||||
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
|
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
|
||||||
|
|
||||||
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
|
ok = emqx_common_test_helpers:start_apps(
|
||||||
ok = emqx_common_test_helpers:start_apps([emqx_authz]),
|
[emqx_conf, emqx_authz],
|
||||||
|
fun set_special_configs/1),
|
||||||
|
|
||||||
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
|
||||||
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
|
||||||
Rules = [#{<<"type">> => <<"mysql">>,
|
Rules = [#{<<"type">> => <<"mysql">>,
|
||||||
<<"server">> => <<"127.0.0.1:27017">>,
|
<<"server">> => <<"127.0.0.1:27017">>,
|
||||||
<<"pool_size">> => 1,
|
<<"pool_size">> => 1,
|
||||||
|
@ -62,9 +54,16 @@ init_per_suite(Config) ->
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx_authz:update(replace, []),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_resource]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
||||||
meck:unload(emqx_resource),
|
meck:unload(emqx_resource),
|
||||||
meck:unload(emqx_schema),
|
ok.
|
||||||
|
|
||||||
|
set_special_configs(emqx_authz) ->
|
||||||
|
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
||||||
|
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
||||||
|
{ok, _} = emqx:update_config([authorization, sources], []),
|
||||||
|
ok;
|
||||||
|
set_special_configs(_App) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
-define(COLUMNS, [ <<"action">>
|
-define(COLUMNS, [ <<"action">>
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
-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").
|
||||||
|
|
||||||
-define(CONF_DEFAULT, <<"authorization: {sources: []}">>).
|
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
emqx_common_test_helpers:all(?MODULE).
|
emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
|
@ -31,22 +29,14 @@ groups() ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
|
|
||||||
meck:expect(emqx_schema, fields, fun("authorization") ->
|
|
||||||
meck:passthrough(["authorization"]) ++
|
|
||||||
emqx_authz_schema:fields("authorization");
|
|
||||||
(F) -> meck:passthrough([F])
|
|
||||||
end),
|
|
||||||
|
|
||||||
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
||||||
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ),
|
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ),
|
||||||
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
|
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
|
||||||
|
|
||||||
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
|
ok = emqx_common_test_helpers:start_apps(
|
||||||
ok = emqx_common_test_helpers:start_apps([emqx_authz]),
|
[emqx_conf, emqx_authz],
|
||||||
|
fun set_special_configs/1),
|
||||||
|
|
||||||
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
|
||||||
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
|
||||||
Rules = [#{<<"type">> => <<"postgresql">>,
|
Rules = [#{<<"type">> => <<"postgresql">>,
|
||||||
<<"server">> => <<"127.0.0.1:27017">>,
|
<<"server">> => <<"127.0.0.1:27017">>,
|
||||||
<<"pool_size">> => 1,
|
<<"pool_size">> => 1,
|
||||||
|
@ -62,9 +52,16 @@ init_per_suite(Config) ->
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx_authz:update(replace, []),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_resource]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
||||||
meck:unload(emqx_resource),
|
meck:unload(emqx_resource),
|
||||||
meck:unload(emqx_schema),
|
ok.
|
||||||
|
|
||||||
|
set_special_configs(emqx_authz) ->
|
||||||
|
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
||||||
|
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
||||||
|
{ok, _} = emqx:update_config([authorization, sources], []),
|
||||||
|
ok;
|
||||||
|
set_special_configs(_App) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
-define(COLUMNS, [ {column, <<"action">>, meck, meck, meck, meck, meck, meck, meck}
|
-define(COLUMNS, [ {column, <<"action">>, meck, meck, meck, meck, meck, meck, meck}
|
||||||
|
|
|
@ -30,22 +30,14 @@ groups() ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
|
|
||||||
meck:expect(emqx_schema, fields, fun("authorization") ->
|
|
||||||
meck:passthrough(["authorization"]) ++
|
|
||||||
emqx_authz_schema:fields("authorization");
|
|
||||||
(F) -> meck:passthrough([F])
|
|
||||||
end),
|
|
||||||
|
|
||||||
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
||||||
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ),
|
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ),
|
||||||
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
|
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
|
||||||
|
|
||||||
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
|
ok = emqx_common_test_helpers:start_apps(
|
||||||
ok = emqx_common_test_helpers:start_apps([emqx_authz]),
|
[emqx_conf, emqx_authz],
|
||||||
|
fun set_special_configs/1),
|
||||||
|
|
||||||
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
|
||||||
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
|
||||||
Rules = [#{<<"type">> => <<"redis">>,
|
Rules = [#{<<"type">> => <<"redis">>,
|
||||||
<<"server">> => <<"127.0.0.1:27017">>,
|
<<"server">> => <<"127.0.0.1:27017">>,
|
||||||
<<"pool_size">> => 1,
|
<<"pool_size">> => 1,
|
||||||
|
@ -62,7 +54,14 @@ end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx_authz:update(replace, []),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_resource]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_resource]),
|
||||||
meck:unload(emqx_resource),
|
meck:unload(emqx_resource),
|
||||||
meck:unload(emqx_schema),
|
ok.
|
||||||
|
|
||||||
|
set_special_configs(emqx_authz) ->
|
||||||
|
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
||||||
|
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
||||||
|
{ok, _} = emqx:update_config([authorization, sources], []),
|
||||||
|
ok;
|
||||||
|
set_special_configs(_App) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
-define(SOURCE1, [<<"test/%u">>, <<"publish">>]).
|
-define(SOURCE1, [<<"test/%u">>, <<"publish">>]).
|
||||||
|
|
|
@ -32,11 +32,22 @@ all() ->
|
||||||
emqx_common_test_helpers:all(?MODULE).
|
emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
ok = emqx_common_test_helpers:start_apps([emqx_authz]),
|
ok = emqx_common_test_helpers:start_apps(
|
||||||
|
[emqx_conf, emqx_authz],
|
||||||
|
fun set_special_configs/1),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz]),
|
{ok, _} = emqx_authz:update(replace, []),
|
||||||
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
||||||
|
ok.
|
||||||
|
|
||||||
|
set_special_configs(emqx_authz) ->
|
||||||
|
{ok, _} = emqx:update_config([authorization, cache, enable], false),
|
||||||
|
{ok, _} = emqx:update_config([authorization, no_match], deny),
|
||||||
|
{ok, _} = emqx:update_config([authorization, sources], []),
|
||||||
|
ok;
|
||||||
|
set_special_configs(_App) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_compile(_) ->
|
t_compile(_) ->
|
||||||
|
|
|
@ -89,7 +89,8 @@ load_gateway(GwName, Conf) ->
|
||||||
unconvert_listeners(Ls) when is_list(Ls) ->
|
unconvert_listeners(Ls) when is_list(Ls) ->
|
||||||
lists:foldl(fun(Lis, Acc) ->
|
lists:foldl(fun(Lis, Acc) ->
|
||||||
{[Type, Name], Lis1} = maps_key_take([<<"type">>, <<"name">>], Lis),
|
{[Type, Name], Lis1} = maps_key_take([<<"type">>, <<"name">>], Lis),
|
||||||
emqx_map_lib:deep_merge(Acc, #{Type => #{Name => Lis1}})
|
NLis1 = maps:without([<<"id">>], Lis1),
|
||||||
|
emqx_map_lib:deep_merge(Acc, #{Type => #{Name => NLis1}})
|
||||||
end, #{}, Ls).
|
end, #{}, Ls).
|
||||||
|
|
||||||
maps_key_take(Ks, M) ->
|
maps_key_take(Ks, M) ->
|
||||||
|
|
Loading…
Reference in New Issue