fix(emqx_authz): check if type param matches type in body

This commit is contained in:
Stefan Strigler 2023-03-06 11:05:53 +01:00
parent a4aece396a
commit d0ea7f4647
4 changed files with 19 additions and 1 deletions

View File

@ -262,8 +262,10 @@ source(get, #{bindings := #{type := Type}}) ->
end; end;
source(put, #{bindings := #{type := <<"file">>}, body := #{<<"type">> := <<"file">>} = Body}) -> source(put, #{bindings := #{type := <<"file">>}, body := #{<<"type">> := <<"file">>} = Body}) ->
update_authz_file(Body); update_authz_file(Body);
source(put, #{bindings := #{type := Type}, body := Body}) -> source(put, #{bindings := #{type := Type}, body := #{<<"type">> := Type} = Body}) ->
update_config({?CMD_REPLACE, Type}, Body); update_config({?CMD_REPLACE, Type}, Body);
source(put, #{bindings := #{type := _Type}, body := #{<<"type">> := _OtherType}}) ->
{400, #{code => <<"BAD_REQUEST">>, message => <<"Type mismatch">>}};
source(delete, #{bindings := #{type := Type}}) -> source(delete, #{bindings := #{type := Type}}) ->
update_config({?CMD_DELETE, Type}, #{}). update_config({?CMD_DELETE, Type}, #{}).

View File

@ -332,6 +332,7 @@ t_api(_) ->
uri(["authorization", "sources", "postgresql"]), uri(["authorization", "sources", "postgresql"]),
?SOURCE4#{<<"server">> := <<"fake">>} ?SOURCE4#{<<"server">> := <<"fake">>}
), ),
{ok, 204, _} = request( {ok, 204, _} = request(
put, put,
uri(["authorization", "sources", "redis"]), uri(["authorization", "sources", "redis"]),
@ -343,6 +344,19 @@ t_api(_) ->
} }
), ),
{ok, 400, TypeMismatch} = request(
put,
uri(["authorization", "sources", "file"]),
#{<<"type">> => <<"built_in_database">>, <<"enable">> => false}
),
?assertMatch(
#{
<<"code">> := <<"BAD_REQUEST">>,
<<"message">> := <<"Type mismatch", _/binary>>
},
jiffy:decode(TypeMismatch, [return_maps])
),
lists:foreach( lists:foreach(
fun(#{<<"type">> := Type}) -> fun(#{<<"type">> := Type}) ->
{ok, 204, _} = request( {ok, 204, _} = request(

View File

@ -0,0 +1 @@
Check if type in `PUT /authorization/sources/:type` matches `type` given in body of request.

View File

@ -0,0 +1 @@
检查 `PUT /authorization/sources/:type` 中的类型是否与请求正文中的 `type` 相符。