diff --git a/client/cpp/src/authentication_state.cpp b/client/cpp/src/authentication_state.cpp index 6546e50..344981e 100644 --- a/client/cpp/src/authentication_state.cpp +++ b/client/cpp/src/authentication_state.cpp @@ -138,7 +138,7 @@ namespace sopmq { _dispatcher->set_handler(std::function()); //set the handler for the AuthAck - std::function func = std::bind(&authentication_state::on_auth_ack, shared_from_this(), _1); + std::function func = std::bind(&authentication_state::on_auth_ack, this, _1); _dispatcher->set_handler(func); AnswerChallengeMessage_ptr acm = std::make_shared(); diff --git a/node/src/csunauthenticated.cpp b/node/src/csunauthenticated.cpp index 2d3be95..18df621 100644 --- a/node/src/csunauthenticated.cpp +++ b/node/src/csunauthenticated.cpp @@ -53,7 +53,7 @@ namespace sopmq { csunauthenticated::~csunauthenticated() { - + LOG_SRC(debug) << "~csunauthenticated()"; } void csunauthenticated::unhandled_message(Message_ptr message) @@ -97,7 +97,7 @@ namespace sopmq { // set the new handler for the client answer std::function func - = std::bind(&csunauthenticated::handle_answer_challenge_message, shared_from_this(), _1); + = std::bind(&csunauthenticated::handle_answer_challenge_message, this, _1); _dispatcher.set_handler(func); @@ -109,9 +109,6 @@ namespace sopmq { { LOG_SRC(debug) << "handle_answer_challenge_message()"; - auto connptr = _conn.lock(); - if (connptr == nullptr) return; - std::function authCallback = [&](bool authd) { //remember this is coming back from the libuv stuff inside the cassandra //driver, so we need to get back into our IO thread @@ -120,6 +117,9 @@ namespace sopmq { { //user is good to go _ioService.post([&] { + auto connptr = _conn.lock(); + if (connptr == nullptr) return; + AuthAckMessage_ptr response = std::make_shared(); response->set_authorized(true); response->set_allocated_identity(messageutil::build_id(connptr->get_next_id(), message->identity().id())); @@ -131,6 +131,9 @@ namespace sopmq { { //no good _ioService.post([&] { + auto connptr = _conn.lock(); + if (connptr == nullptr) return; + AuthAckMessage_ptr response = std::make_shared(); response->set_authorized(false); response->set_allocated_identity(messageutil::build_id(connptr->get_next_id(), message->identity().id())); @@ -170,7 +173,7 @@ namespace sopmq { void csunauthenticated::start() { std::function func - = std::bind(&csunauthenticated::handle_get_challenge_message, shared_from_this(), _1); + = std::bind(&csunauthenticated::handle_get_challenge_message, this, _1); _dispatcher.set_handler(func); @@ -189,7 +192,7 @@ namespace sopmq { { //read a message from the network messageutil::read_message(_ioService, conn->get_socket(), - std::bind(&csunauthenticated::handle_read_result, this, _1), + std::bind(&csunauthenticated::handle_read_result, shared_from_this(), _1), _dispatcher, settings::instance().maxMessageSize); } } diff --git a/test/src/test-operations.cpp b/test/src/test-operations.cpp index b7cf048..a0f5700 100644 --- a/test/src/test-operations.cpp +++ b/test/src/test-operations.cpp @@ -20,6 +20,8 @@ #include "server.h" #include "cluster_builder.h" #include "endpoint.h" +#include "settings.h" +#include "user_account.h" #include #include @@ -30,6 +32,8 @@ using namespace sopmq::client; using namespace sopmq::shared::net; +using sopmq::node::settings; +using sopmq::node::user_account; class OperationsTest : public ::testing::Test { @@ -62,7 +66,13 @@ class OperationsTest : public ::testing::Test TEST_F(OperationsTest, TestAuthentication) { - /* + if (settings::instance().cassandraSeeds.size() == 0) return; + + const char* const USERNAME = "test"; + const char* const PASSWORD = "test"; + + user_account::create(USERNAME, PASSWORD, 1); + boost::asio::io_service clientIoService; cluster_builder builder; builder.add_endpoint(endpoint("sopmq1://127.0.0.1:8481")); @@ -89,5 +99,4 @@ TEST_F(OperationsTest, TestAuthentication) boost::asio::io_service::work work(clientIoService); clientIoService.run(); - */ }