Skip to content

Commit

Permalink
Completed full unit testing of the user authentication procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
ddaeschler committed Aug 31, 2014
1 parent f8abbec commit 3827121
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion client/cpp/src/authentication_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ namespace sopmq {
_dispatcher->set_handler(std::function<void(ChallengeResponseMessage_ptr)>());

//set the handler for the AuthAck
std::function<void(AuthAckMessage_ptr)> func = std::bind(&authentication_state::on_auth_ack, shared_from_this(), _1);
std::function<void(AuthAckMessage_ptr)> func = std::bind(&authentication_state::on_auth_ack, this, _1);
_dispatcher->set_handler(func);

AnswerChallengeMessage_ptr acm = std::make_shared<AnswerChallengeMessage>();
Expand Down
17 changes: 10 additions & 7 deletions node/src/csunauthenticated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace sopmq {

csunauthenticated::~csunauthenticated()
{

LOG_SRC(debug) << "~csunauthenticated()";
}

void csunauthenticated::unhandled_message(Message_ptr message)
Expand Down Expand Up @@ -97,7 +97,7 @@ namespace sopmq {

// set the new handler for the client answer
std::function<void(AnswerChallengeMessage_ptr)> 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);

Expand All @@ -109,9 +109,6 @@ namespace sopmq {
{
LOG_SRC(debug) << "handle_answer_challenge_message()";

auto connptr = _conn.lock();
if (connptr == nullptr) return;

std::function<void(bool)> 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
Expand All @@ -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<AuthAckMessage>();
response->set_authorized(true);
response->set_allocated_identity(messageutil::build_id(connptr->get_next_id(), message->identity().id()));
Expand All @@ -131,6 +131,9 @@ namespace sopmq {
{
//no good
_ioService.post([&] {
auto connptr = _conn.lock();
if (connptr == nullptr) return;

AuthAckMessage_ptr response = std::make_shared<AuthAckMessage>();
response->set_authorized(false);
response->set_allocated_identity(messageutil::build_id(connptr->get_next_id(), message->identity().id()));
Expand Down Expand Up @@ -170,7 +173,7 @@ namespace sopmq {
void csunauthenticated::start()
{
std::function<void(GetChallengeMessage_ptr)> 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);

Expand All @@ -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);
}
}
Expand Down
13 changes: 11 additions & 2 deletions test/src/test-operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "server.h"
#include "cluster_builder.h"
#include "endpoint.h"
#include "settings.h"
#include "user_account.h"

#include <boost/asio.hpp>
#include <boost/thread.hpp>
Expand All @@ -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
{
Expand Down Expand Up @@ -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"));
Expand All @@ -89,5 +99,4 @@ TEST_F(OperationsTest, TestAuthentication)

boost::asio::io_service::work work(clientIoService);
clientIoService.run();
*/
}

0 comments on commit 3827121

Please sign in to comment.