fix: add handling of message_validation_failed ctx for rule testing
Before this commit, the backend could not handle the test context for message_validation_failed events that could be sent from the dashboard since no handling code for this contexts existed in the backend. This has now been fixed by adding such handling code. Fixes: https://emqx.atlassian.net/browse/EMQX-12354
This commit is contained in:
parent
1730a41337
commit
e811f4a392
|
@ -307,6 +307,13 @@ fields("ctx_delivery_dropped") ->
|
||||||
{"from_clientid", sc(binary(), #{desc => ?DESC("event_from_clientid")})},
|
{"from_clientid", sc(binary(), #{desc => ?DESC("event_from_clientid")})},
|
||||||
{"from_username", sc(binary(), #{desc => ?DESC("event_from_username")})}
|
{"from_username", sc(binary(), #{desc => ?DESC("event_from_username")})}
|
||||||
| msg_event_common_fields()
|
| msg_event_common_fields()
|
||||||
|
];
|
||||||
|
fields("ctx_schema_validation_failed") ->
|
||||||
|
Event = 'schema.validation_failed',
|
||||||
|
[
|
||||||
|
{"event_type", event_type_sc(Event)},
|
||||||
|
{"validation", sc(binary(), #{desc => ?DESC("event_validation")})}
|
||||||
|
| msg_event_common_fields()
|
||||||
].
|
].
|
||||||
|
|
||||||
rule_input_message_context() ->
|
rule_input_message_context() ->
|
||||||
|
@ -324,7 +331,8 @@ rule_input_message_context() ->
|
||||||
ref("ctx_connack"),
|
ref("ctx_connack"),
|
||||||
ref("ctx_check_authz_complete"),
|
ref("ctx_check_authz_complete"),
|
||||||
ref("ctx_bridge_mqtt"),
|
ref("ctx_bridge_mqtt"),
|
||||||
ref("ctx_delivery_dropped")
|
ref("ctx_delivery_dropped"),
|
||||||
|
ref("ctx_schema_validation_failed")
|
||||||
]),
|
]),
|
||||||
#{
|
#{
|
||||||
desc => ?DESC("test_context"),
|
desc => ?DESC("test_context"),
|
||||||
|
|
|
@ -197,6 +197,8 @@ is_test_runtime_env() ->
|
||||||
|
|
||||||
%% Most events have the original `topic' input, but their own topic (i.e.: `$events/...')
|
%% Most events have the original `topic' input, but their own topic (i.e.: `$events/...')
|
||||||
%% is different from `topic'.
|
%% is different from `topic'.
|
||||||
|
get_in_topic(#{event_type := schema_validation_failed}) ->
|
||||||
|
<<"$events/schema_validation_failed">>;
|
||||||
get_in_topic(Context) ->
|
get_in_topic(Context) ->
|
||||||
case maps:find(event_topic, Context) of
|
case maps:find(event_topic, Context) of
|
||||||
{ok, EventTopic} ->
|
{ok, EventTopic} ->
|
||||||
|
|
|
@ -214,6 +214,21 @@ t_ctx_delivery_dropped(_) ->
|
||||||
Expected = check_result([from_clientid, from_username, reason, qos, topic], [], Context),
|
Expected = check_result([from_clientid, from_username, reason, qos, topic], [], Context),
|
||||||
do_test(SQL, Context, Expected).
|
do_test(SQL, Context, Expected).
|
||||||
|
|
||||||
|
t_ctx_schema_validation_failed(_) ->
|
||||||
|
SQL =
|
||||||
|
<<"SELECT validation FROM \"$events/schema_validation_failed\"">>,
|
||||||
|
Context = #{
|
||||||
|
<<"clientid">> => <<"c_emqx">>,
|
||||||
|
<<"event_type">> => <<"schema_validation_failed">>,
|
||||||
|
<<"payload">> => <<"{\"msg\": \"hello\"}">>,
|
||||||
|
<<"qos">> => 1,
|
||||||
|
<<"topic">> => <<"t/a">>,
|
||||||
|
<<"username">> => <<"u_emqx">>,
|
||||||
|
<<"validation">> => <<"m">>
|
||||||
|
},
|
||||||
|
Expected = check_result([validation], [], Context),
|
||||||
|
do_test(SQL, Context, Expected).
|
||||||
|
|
||||||
t_mongo_date_function_should_return_string_in_test_env(_) ->
|
t_mongo_date_function_should_return_string_in_test_env(_) ->
|
||||||
SQL =
|
SQL =
|
||||||
<<"SELECT mongo_date() as mongo_date FROM \"$events/client_check_authz_complete\"">>,
|
<<"SELECT mongo_date() as mongo_date FROM \"$events/client_check_authz_complete\"">>,
|
||||||
|
|
|
@ -360,6 +360,12 @@ event_username.desc:
|
||||||
event_username.label:
|
event_username.label:
|
||||||
"""Username"""
|
"""Username"""
|
||||||
|
|
||||||
|
event_validation.desc:
|
||||||
|
"""Validation"""
|
||||||
|
|
||||||
|
event_validation.label:
|
||||||
|
"""Validation"""
|
||||||
|
|
||||||
root_rule_info.desc:
|
root_rule_info.desc:
|
||||||
"""Schema for rule info"""
|
"""Schema for rule info"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue