Merge pull request #7848 from JimMoen/fix-authn-flaky-test

fix(authn): make sure http headers are bin
This commit is contained in:
zhouzb 2022-04-29 20:46:18 +08:00 committed by GitHub
commit 1de2a80b93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -172,7 +172,7 @@ create(
State = #{
method => Method,
path => Path,
headers => Headers,
headers => ensure_header_name_type(Headers),
base_path_templete => emqx_authn_utils:parse_str(Path),
base_query_template => emqx_authn_utils:parse_deep(
cow_qs:parse_qs(to_bin(Query))
@ -421,3 +421,14 @@ to_bin(L) when is_list(L) ->
get_conf_val(Name, Conf) ->
hocon_maps:get(?CONF_NS ++ "." ++ Name, Conf).
ensure_header_name_type(Headers) ->
Fun = fun
(Key, _Val, Acc) when is_binary(Key) ->
Acc;
(Key, Val, Acc) when is_atom(Key) ->
Acc2 = maps:remove(Key, Acc),
BinKey = erlang:atom_to_binary(Key),
Acc2#{BinKey => Val}
end,
maps:fold(Fun, Headers, Headers).