Merge pull request #13420 from thalesmg/20240705-r57-fix-mt-empty-topics
fix(schema validation & message transformation): forbid empty topic filter list
This commit is contained in:
commit
d34fc7a03a
|
@ -231,6 +231,8 @@ do_validate_unique_names([#{<<"name">> := Name} | _Rest], Acc) when is_map_key(N
|
|||
do_validate_unique_names([#{<<"name">> := Name} | Rest], Acc) ->
|
||||
do_validate_unique_names(Rest, Acc#{Name => true}).
|
||||
|
||||
validate_unique_topics([]) ->
|
||||
{error, <<"at least one topic filter must be defined">>};
|
||||
validate_unique_topics(Topics) ->
|
||||
Grouped = maps:groups_from_list(
|
||||
fun(T) -> T end,
|
||||
|
|
|
@ -87,6 +87,19 @@ schema_test_() ->
|
|||
)
|
||||
])
|
||||
)},
|
||||
{"topics must be non-empty",
|
||||
?_assertThrow(
|
||||
{_Schema, [
|
||||
#{
|
||||
reason := <<"at least one topic filter must be defined", _/binary>>,
|
||||
value := [],
|
||||
kind := validation_error
|
||||
}
|
||||
]},
|
||||
parse_and_check([
|
||||
transformation(<<"foo">>, [dummy_operation()], #{<<"topics">> => []})
|
||||
])
|
||||
)},
|
||||
{"names are unique",
|
||||
?_assertThrow(
|
||||
{_Schema, [
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{application, emqx_schema_validation, [
|
||||
{description, "EMQX Schema Validation"},
|
||||
{vsn, "0.1.1"},
|
||||
{vsn, "0.1.2"},
|
||||
{registered, [emqx_schema_validation_sup, emqx_schema_validation_registry]},
|
||||
{mod, {emqx_schema_validation_app, []}},
|
||||
{applications, [
|
||||
|
|
|
@ -259,6 +259,8 @@ do_validate_unique_schema_checks(
|
|||
do_validate_unique_schema_checks([_Check | Rest], Seen, Duplicated) ->
|
||||
do_validate_unique_schema_checks(Rest, Seen, Duplicated).
|
||||
|
||||
validate_unique_topics([]) ->
|
||||
{error, <<"at least one topic filter must be defined">>};
|
||||
validate_unique_topics(Topics) ->
|
||||
Grouped = maps:groups_from_list(
|
||||
fun(T) -> T end,
|
||||
|
|
|
@ -117,6 +117,19 @@ schema_test_() ->
|
|||
)
|
||||
])
|
||||
)},
|
||||
{"topics must be non-empty",
|
||||
?_assertThrow(
|
||||
{_Schema, [
|
||||
#{
|
||||
reason := <<"at least one topic filter must be defined", _/binary>>,
|
||||
value := [],
|
||||
kind := validation_error
|
||||
}
|
||||
]},
|
||||
parse_and_check([
|
||||
validation(<<"foo">>, [sql_check()], #{<<"topics">> => []})
|
||||
])
|
||||
)},
|
||||
{"foreach expression is not allowed",
|
||||
?_assertThrow(
|
||||
{_Schema, [
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Added a schema validation to forbid empty topic filter lists when configuring a Schema Validation.
|
Loading…
Reference in New Issue