fix(emqx_authz): update config with own schema module

This commit is contained in:
Zaiming Shi 2021-07-29 22:05:20 +02:00 committed by turtleDeng
parent cf1246f026
commit 9dcb725898
2 changed files with 10 additions and 7 deletions

View File

@ -49,7 +49,7 @@ lookup() ->
emqx_config:get(?CONF_KEY_PATH, []). emqx_config:get(?CONF_KEY_PATH, []).
update(Cmd, Rules) -> update(Cmd, Rules) ->
emqx_config:update(?CONF_KEY_PATH, {Cmd, Rules}). emqx_config:update(emqx_authz_schema, ?CONF_KEY_PATH, {Cmd, Rules}).
%% For now we only support re-creating the entire rule list %% For now we only support re-creating the entire rule list
pre_config_update({head, Rule}, OldConf) when is_map(Rule), is_list(OldConf) -> pre_config_update({head, Rule}, OldConf) when is_map(Rule), is_list(OldConf) ->

View File

@ -34,6 +34,13 @@
% -define(API_VERSION, "v4"). % -define(API_VERSION, "v4").
% -define(BASE_PATH, "api"). % -define(BASE_PATH, "api").
-define(CONF_DEFAULT, <<"""
authorization:{
rules: [
]
}
""">>).
all() -> all() ->
%% TODO: V5 API %% TODO: V5 API
%% emqx_ct:all(?MODULE). %% emqx_ct:all(?MODULE).
@ -43,11 +50,7 @@ groups() ->
[]. [].
init_per_suite(Config) -> init_per_suite(Config) ->
%% important! let emqx_schema include the current app! ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_schema, includes, fun() -> ["authorization"] end ),
meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end),
ok = emqx_ct_helpers:start_apps([emqx_authz]), ok = emqx_ct_helpers:start_apps([emqx_authz]),
%create_default_app(), %create_default_app(),
@ -55,7 +58,6 @@ init_per_suite(Config) ->
end_per_suite(_Config) -> end_per_suite(_Config) ->
%delete_default_app(), %delete_default_app(),
meck:unload(emqx_schema),
emqx_ct_helpers:stop_apps([emqx_authz]). emqx_ct_helpers:stop_apps([emqx_authz]).
% set_special_configs(emqx) -> % set_special_configs(emqx) ->
@ -79,6 +81,7 @@ end_per_suite(_Config) ->
% %%------------------------------------------------------------------------------ % %%------------------------------------------------------------------------------
t_api_unit_test(_Config) -> t_api_unit_test(_Config) ->
%% TODO: Decode from JSON or HOCON, instead of hand-crafting decode result
Rule1 = #{<<"principal">> => Rule1 = #{<<"principal">> =>
#{<<"and">> => [#{<<"username">> => <<"^test?">>}, #{<<"and">> => [#{<<"username">> => <<"^test?">>},
#{<<"clientid">> => <<"^test?">>} #{<<"clientid">> => <<"^test?">>}