Merge pull request #10074 from sstrigler/EMQX-8550-put-authorization-sources-type-doesnt-check-type-constraint

fix(emqx_authz): check if type param matches type in body
This commit is contained in:
Stefan Strigler 2023-03-06 13:39:59 +01:00 committed by GitHub
commit bd7e789bea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 1 deletions

View File

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

View File

@ -332,6 +332,7 @@ t_api(_) ->
uri(["authorization", "sources", "postgresql"]),
?SOURCE4#{<<"server">> := <<"fake">>}
),
{ok, 204, _} = request(
put,
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(
fun(#{<<"type">> := Type}) ->
{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` 相符。