Merge pull request #10905 from thalesmg/fix-enforce-binary-rootkey-config-v50

fix(config): enforce root key name to be a binary (raw config)
This commit is contained in:
Thales Macedo Garitezi 2023-06-01 10:27:48 -03:00 committed by GitHub
commit 7740987a17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 3 deletions

View File

@ -299,14 +299,15 @@ get_raw(KeyPath, Default) -> do_get_raw(KeyPath, Default).
put_raw(Config) -> put_raw(Config) ->
maps:fold( maps:fold(
fun(RootName, RootV, _) -> fun(RootName, RootV, _) ->
?MODULE:put_raw([RootName], RootV) ?MODULE:put_raw([bin(RootName)], RootV)
end, end,
ok, ok,
hocon_maps:ensure_plain(Config) hocon_maps:ensure_plain(Config)
). ).
-spec put_raw(emqx_utils_maps:config_key_path(), term()) -> ok. -spec put_raw(emqx_utils_maps:config_key_path(), term()) -> ok.
put_raw(KeyPath, Config) -> put_raw(KeyPath0, Config) ->
KeyPath = [bin(K) || K <- KeyPath0],
Putter = fun(Path, Map, Value) -> Putter = fun(Path, Map, Value) ->
emqx_utils_maps:deep_force_put(Path, Map, Value) emqx_utils_maps:deep_force_put(Path, Map, Value)
end, end,

View File

@ -297,6 +297,7 @@ t_update_config({init, Config}) ->
]; ];
t_update_config(Config) when is_list(Config) -> t_update_config(Config) when is_list(Config) ->
emqx_config_handler:add_handler([?CONF_ROOT], emqx_authentication), emqx_config_handler:add_handler([?CONF_ROOT], emqx_authentication),
ok = emqx_config_handler:add_handler([listeners, '?', '?', ?CONF_ROOT], emqx_authentication),
ok = register_provider(?config("auth1"), ?MODULE), ok = register_provider(?config("auth1"), ?MODULE),
ok = register_provider(?config("auth2"), ?MODULE), ok = register_provider(?config("auth2"), ?MODULE),
Global = ?config(global), Global = ?config(global),

View File

@ -279,7 +279,7 @@ does_module_exist(Mod) ->
clear_listeners() -> clear_listeners() ->
emqx_config:put([listeners], #{}), emqx_config:put([listeners], #{}),
emqx_config:put_raw([listeners], #{}), emqx_config:put_raw([<<"listeners">>], #{}),
ok. ok.
assert_http_get(URL) -> assert_http_get(URL) ->