From f7c0d2947800b1e74e45102a2fa65c24e7c63ad2 Mon Sep 17 00:00:00 2001 From: Andrew Mayorov Date: Thu, 9 Mar 2023 14:04:32 +0300 Subject: [PATCH] test(tde): add testcase for a nasty string in SQL query Similar to what we have in mysql and pgqsl testsuites. --- .../test/emqx_ee_bridge_tdengine_SUITE.erl | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib-ee/emqx_ee_bridge/test/emqx_ee_bridge_tdengine_SUITE.erl b/lib-ee/emqx_ee_bridge/test/emqx_ee_bridge_tdengine_SUITE.erl index 4c17ba1a1..3b580ec61 100644 --- a/lib-ee/emqx_ee_bridge/test/emqx_ee_bridge_tdengine_SUITE.erl +++ b/lib-ee/emqx_ee_bridge/test/emqx_ee_bridge_tdengine_SUITE.erl @@ -426,6 +426,32 @@ t_bad_sql_parameter(Config) -> end, ok. +t_nasty_sql_string(Config) -> + ?assertMatch( + {ok, _}, + create_bridge(Config) + ), + % NOTE + % Column `payload` has BINARY type, so we would certainly like to test it + % with `lists:seq(1, 127)`, but: + % 1. There's no way to insert zero byte in an SQL string, seems that TDengine's + % parser[1] has no escaping sequence for it so a zero byte probably confuses + % interpreter somewhere down the line. + % 2. Bytes > 127 come back as U+FFFDs (i.e. replacement characters) in UTF-8 for + % some reason. + % + % [1]: https://github.com/taosdata/TDengine/blob/066cb34a/source/libs/parser/src/parUtil.c#L279-L301 + Payload = list_to_binary(lists:seq(1, 127)), + Message = #{payload => Payload, timestamp => erlang:system_time(millisecond)}, + ?assertMatch( + {ok, #{<<"code">> := 0, <<"rows">> := 1}}, + send_message(Config, Message) + ), + ?assertEqual( + Payload, + connect_and_get_payload(Config) + ). + to_bin(List) when is_list(List) -> unicode:characters_to_binary(List, utf8); to_bin(Bin) when is_binary(Bin) ->