forked from boostorg/mqtt5
Add re authentication tests
Summary: related to T12015 Reviewers: ivica Reviewed By: ivica Subscribers: miljen, iljazovic Differential Revision: https://repo.mireo.local/D27436
This commit is contained in:
@@ -82,7 +82,7 @@ inline std::string to_readable_packet(std::string packet) {
|
||||
|
||||
std::ostringstream stream;
|
||||
|
||||
if (code == control_code_e::connack || code == control_code_e::disconnect) {
|
||||
if (code == control_code_e::connack || code == control_code_e::auth) {
|
||||
stream << code_to_str(code);
|
||||
return stream.str();
|
||||
}
|
||||
@@ -99,6 +99,16 @@ inline std::string to_readable_packet(std::string packet) {
|
||||
stream << " props: " << to_readable_props(props);
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
if (code == control_code_e::disconnect) {
|
||||
auto disconnect = decoders::decode_disconnect(*varlen, begin);
|
||||
auto& [rc, props] = *disconnect;
|
||||
stream << code_to_str(code);
|
||||
stream << " rc: " << int(rc);
|
||||
stream << " reason string: " << props[prop::reason_string].value_or("");
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
if (code == control_code_e::publish) {
|
||||
auto publish = decoders::decode_publish(
|
||||
control_byte, *varlen, begin
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
#ifndef ASYNC_MQTT5_TEST_TEST_AUTHENTICATORS_HPP
|
||||
#define ASYNC_MQTT5_TEST_TEST_AUTHENTICATORS_HPP
|
||||
|
||||
#include <boost/asio/dispatch.hpp>
|
||||
#include <boost/asio/prepend.hpp>
|
||||
|
||||
#include <async_mqtt5/types.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace async_mqtt5::test {
|
||||
|
||||
namespace asio = boost::asio;
|
||||
|
||||
struct test_authenticator {
|
||||
test_authenticator() = default;
|
||||
|
||||
template <typename CompletionToken>
|
||||
decltype(auto) async_auth(
|
||||
auth_step_e step, std::string data,
|
||||
CompletionToken&& token
|
||||
) {
|
||||
using error_code = boost::system::error_code;
|
||||
using Signature = void (error_code, std::string);
|
||||
|
||||
auto initiate = [](auto handler, auth_step_e, std::string) {
|
||||
asio::dispatch(
|
||||
asio::prepend(std::move(handler), error_code {}, "")
|
||||
);
|
||||
};
|
||||
|
||||
return asio::async_initiate<CompletionToken, Signature>(
|
||||
initiate, token, step, std::move(data)
|
||||
);
|
||||
}
|
||||
|
||||
std::string_view method() const {
|
||||
return "method";
|
||||
}
|
||||
};
|
||||
|
||||
template <auth_step_e fail_on_step>
|
||||
struct fail_test_authenticator {
|
||||
fail_test_authenticator() = default;
|
||||
|
||||
template <typename CompletionToken>
|
||||
decltype(auto) async_auth(
|
||||
auth_step_e step, std::string data,
|
||||
CompletionToken&& token
|
||||
) {
|
||||
using error_code = boost::system::error_code;
|
||||
using Signature = void (error_code, std::string);
|
||||
|
||||
auto initiate = [](auto handler, auth_step_e step, std::string) {
|
||||
error_code ec;
|
||||
if (fail_on_step == step)
|
||||
ec = asio::error::no_recovery;
|
||||
|
||||
asio::dispatch(
|
||||
asio::prepend(std::move(handler), ec, "")
|
||||
);
|
||||
};
|
||||
|
||||
return asio::async_initiate<CompletionToken, Signature>(
|
||||
initiate, token, step, std::move(data)
|
||||
);
|
||||
}
|
||||
|
||||
std::string_view method() const {
|
||||
return "method";
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace async_mqtt5::test
|
||||
|
||||
#endif // ASYNC_MQTT5_TEST_TEST_AUTHENTICATORS_HPP
|
||||
Reference in New Issue
Block a user