(Un)subscribe validates the number of topics and reason codes

Test Plan:
related to T12015
- (un)subscribe reason codes will always contain as many reason codes as there are topic filters
- if, by some odd chance, the client receives the wrong number of rcs or some are invalid, it will treat it as malformed
- both subscribe_op and unsubscribe_op should be 100% covered by tests now

Reviewers: ivica

Reviewed By: ivica

Subscribers: miljen, iljazovic

Differential Revision: https://repo.mireo.local/D27592
This commit is contained in:
Korina Šimičević
2024-01-30 15:25:58 +01:00
parent 4bf59cc18c
commit d6c4884d53
10 changed files with 405 additions and 81 deletions
+20 -5
View File
@@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(pid_overrun) {
}
void run_test(
error_code expected_ec, const std::string& topic_filter,
error_code expected_ec, const std::vector<std::string>& topics,
const unsubscribe_props& uprops = {}, const connack_props& cprops = {}
) {
constexpr int expected_handlers_called = 1;
@@ -45,24 +45,35 @@ void run_test(
using client_service_type = test::test_service<asio::ip::tcp::socket>;
auto svc_ptr = std::make_shared<client_service_type>(ioc.get_executor(), cprops);
auto handler = [&handlers_called, expected_ec]
auto handler = [&handlers_called, expected_ec, num_tp = topics.size()]
(error_code ec, std::vector<reason_code> rcs, unsuback_props) {
++handlers_called;
BOOST_CHECK(ec == expected_ec);
BOOST_ASSERT(rcs.size() == 1);
BOOST_CHECK_EQUAL(rcs[0], reason_codes::empty);
BOOST_ASSERT(rcs.size() == num_tp);
for (size_t i = 0; i < rcs.size(); ++i)
BOOST_CHECK_EQUAL(rcs[i], reason_codes::empty);
};
detail::unsubscribe_op<
client_service_type, decltype(handler)
> { svc_ptr, std::move(handler) }
.perform({ topic_filter }, uprops);
.perform(topics, uprops);
ioc.run_for(std::chrono::milliseconds(500));
BOOST_CHECK_EQUAL(handlers_called, expected_handlers_called);
}
void run_test(
error_code expected_ec, const std::string& topic,
const unsubscribe_props& uprops = {}, const connack_props& cprops = {}
) {
return run_test(
expected_ec, std::vector<std::string> { topic }, uprops, cprops
);
}
BOOST_AUTO_TEST_CASE(invalid_topic_filter_1) {
run_test(client::error::invalid_topic, "");
}
@@ -111,4 +122,8 @@ BOOST_AUTO_TEST_CASE(packet_too_large) {
);
}
BOOST_AUTO_TEST_CASE(zero_topic_filters) {
run_test(client::error::invalid_topic, std::vector<std::string> {});
}
BOOST_AUTO_TEST_SUITE_END()