test(frame): malformed utf-8 packet

This commit is contained in:
JimMoen 2022-03-10 14:01:29 +08:00
parent 2b17d6e297
commit 3505e286ba
1 changed files with 20 additions and 1 deletions

View File

@ -43,7 +43,8 @@ groups() ->
[{parse, [parallel],
[t_parse_cont,
t_parse_frame_too_large,
t_parse_frame_malformed_variable_byte_integer
t_parse_frame_malformed_variable_byte_integer,
t_parse_malformed_utf8_string
]},
{connect, [parallel],
[t_serialize_parse_v3_connect,
@ -136,6 +137,24 @@ t_parse_frame_malformed_variable_byte_integer(_) ->
?catch_error(malformed_variable_byte_integer,
emqx_frame:parse(MalformedPayload, ParseState)).
t_parse_malformed_utf8_string(_) ->
MalformedPacket = <<16,31,0,4,
%% Specification name, should be "MQTT"
%% 77,81,84,84,
%% malformed 1-Byte UTF-8 in (U+0000 .. U+001F] && [U+007F])
16#00,16#01,16#1F,16#7F,
4,194,0,60,
0,4,101,109,
113,120,0,5,
97,100,109,105,
110,0,6,112,
117,98,108,105,
99>>,
ParseState = emqx_frame:initial_parse_state(#{strict_mode => true}),
?catch_error(utf8_string_invalid, emqx_frame:parse(MalformedPacket, ParseState)).
t_serialize_parse_v3_connect(_) ->
Bin = <<16,37,0,6,77,81,73,115,100,112,3,2,0,60,0,23,109,111,115,
113,112,117, 98,47,49,48,52,53,49,45,105,77,97,99,46,108,