Commit 2cbfa145 authored by Samir Halilcevic's avatar Samir Halilcevic

Add unit tests for failing UTF-8

parent 1fe2518f
......@@ -350,7 +350,6 @@ SCENARIO("the application shuts down on invalid UTF-8 message") {
detail::rfc6455::assemble_frame(detail::rfc6455::continuation_frame, 0x0,
data_span.subspan(11), frame);
transport->push(frame);
THEN("the server aborts the application") {
CHECK_EQ(transport->handle_input(), 0);
CHECK_EQ(app->abort_reason, sec::malformed_message);
......@@ -359,7 +358,7 @@ SCENARIO("the application shuts down on invalid UTF-8 message") {
MESSAGE("Aborted with: " << app->abort_reason);
}
}
WHEN("the client sends the first invalid byte") {
WHEN("the client sends the invalid byte on a frame boundary") {
reset();
byte_buffer frame;
detail::rfc6455::assemble_frame(detail::rfc6455::text_frame, 0x0,
......@@ -379,6 +378,54 @@ SCENARIO("the application shuts down on invalid UTF-8 message") {
MESSAGE("Aborted with: " << app->abort_reason);
}
}
WHEN("the client sends an invalid text frame byte by byte") {
reset();
byte_buffer frame;
detail::rfc6455::assemble_frame(detail::rfc6455::text_frame, 0x0,
data_span, frame, 0);
for (auto i = 0; i < 14; i++) {
transport->push(make_span(frame).subspan(i, 1));
CHECK_EQ(transport->handle_input(), 0);
CHECK(!app->has_aborted());
}
THEN("the server aborts when receiving the invalid byte") {
transport->push(make_span(frame).subspan(14, 1));
CHECK_EQ(transport->handle_input(), 0);
CHECK_EQ(app->abort_reason, sec::malformed_message);
CHECK_EQ(fetch_status(transport->output_buffer()),
static_cast<int>(net::web_socket::status::inconsistent_data));
MESSAGE("Aborted with: " << app->abort_reason);
}
WHEN("the client sends the first frame of a text messagee") {
reset();
byte_buffer frame;
detail::rfc6455::assemble_frame(detail::rfc6455::text_frame, 0x0,
data_span.subspan(0, 6), frame, 0);
transport->push(frame);
CHECK_EQ(transport->handle_input(),
static_cast<ptrdiff_t>(frame.size()));
CHECK(!app->has_aborted());
}
AND_WHEN("sending the invalid continuation frame byte by byte") {
byte_buffer frame;
detail::rfc6455::assemble_frame(detail::rfc6455::continuation_frame,
0x0, data_span.subspan(6), frame);
for (auto i = 0; i < 8; i++) {
transport->push(make_span(frame).subspan(i, 1));
CHECK_EQ(transport->handle_input(), 0);
CHECK(!app->has_aborted());
}
THEN("the server aborts the application on the invalid byte") {
transport->push(make_span(frame).subspan(8, 1));
CHECK_EQ(transport->handle_input(), 0);
CHECK_EQ(app->abort_reason, sec::malformed_message);
CHECK_EQ(fetch_status(transport->output_buffer()),
static_cast<int>(
net::web_socket::status::inconsistent_data));
MESSAGE("Aborted with: " << app->abort_reason);
}
}
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment