Commit 37e6e3ad authored by Matthieu Kermagoret's avatar Matthieu Kermagoret
Browse files

Connector SSH: moved credentials class to the sessions namespace.

parent 55cf5bb9
......@@ -126,12 +126,12 @@ add_library("${CONNECTORLIB}"
"${SRC_DIR}/checks/listener.cc"
"${SRC_DIR}/checks/result.cc"
# "${SRC_DIR}/commander.cc"
# "${SRC_DIR}/credentials.cc"
"${SRC_DIR}/multiplexer.cc"
"${SRC_DIR}/orders/listener.cc"
"${SRC_DIR}/orders/parser.cc"
# "${SRC_DIR}/session.cc"
# "${SRC_DIR}/sessions.cc"
"${SRC_DIR}/sessions/credentials.cc"
"${SRC_DIR}/sessions/listener.cc"
# "${SRC_DIR}/socket_handle.cc"
# Headers.
......@@ -139,13 +139,13 @@ add_library("${CONNECTORLIB}"
"${INC_DIR}/checks/listener.hh"
"${INC_DIR}/checks/result.hh"
# "${INC_DIR}/commander.hh"
# "${INC_DIR}/credentials.hh"
"${INC_DIR}/multiplexer.hh"
"${INC_DIR}/namespace.hh"
"${INC_DIR}/orders/listener.hh"
"${INC_DIR}/orders/parser.hh"
# "${INC_DIR}/session.hh"
# "${INC_DIR}/sessions.hh"
"${INC_DIR}/sessions/credentials.hh"
"${INC_DIR}/sessions/listener.hh"
# "${INC_DIR}/socket_handle.hh"
)
......@@ -291,6 +291,47 @@ if (WITH_TESTING)
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
#
# sessions namespace tests.
#
# credentials tests.
# Default constructor.
set(TEST_NAME "sessions_credentials_ctor_default")
add_executable("${TEST_NAME}"
"${TEST_DIR}/sessions/credentials/ctor_default.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Host property.
set(TEST_NAME "sessions_credentials_host")
add_executable("${TEST_NAME}"
"${TEST_DIR}/sessions/credentials/host.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# User property.
set(TEST_NAME "sessions_credentials_user")
add_executable("${TEST_NAME}"
"${TEST_DIR}/sessions/credentials/user.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Password property.
set(TEST_NAME "sessions_credentials_password")
add_executable("${TEST_NAME}"
"${TEST_DIR}/sessions/credentials/password.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Copy constructor.
set(TEST_NAME "sessions_credentials_ctor_copy")
add_executable("${TEST_NAME}"
"${TEST_DIR}/sessions/credentials/ctor_copy.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Assignment operator.
set(TEST_NAME "sessions_credentials_assignment")
add_executable("${TEST_NAME}"
"${TEST_DIR}/sessions/credentials/assignment.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
else()
set(BUILD_UNIT_TEST "No")
endif ()
......
......@@ -18,49 +18,51 @@
** <http://www.gnu.org/licenses/>.
*/
#ifndef CCCS_CREDENTIALS_HH
# define CCCS_CREDENTIALS_HH
#ifndef CCCS_SESSIONS_CREDENTIALS_HH
# define CCCS_SESSIONS_CREDENTIALS_HH
# include <string>
# include "com/centreon/connector/ssh/namespace.hh"
CCCS_BEGIN()
/**
* @class credentials credentials.hh "com/centreon/connector/ssh/credentials.hh"
* @brief Connection credentials.
*
* Bundle together connection credentials : host, user and
* password. Methods are provided so that they can be compared.
*/
class credentials {
public:
credentials();
credentials(
std::string const& host,
std::string const& user,
std::string const& password);
credentials(credentials const& c);
~credentials();
credentials& operator=(credentials const& c);
bool operator==(credentials const& c) const;
bool operator!=(credentials const& c) const;
bool operator<(credentials const& c) const;
std::string const& get_host() const;
std::string const& get_password() const;
std::string const& get_user() const;
void set_host(std::string const& host);
void set_password(std::string const& password);
void set_user(std::string const& user);
namespace sessions {
/**
* @class credentials credentials.hh "com/centreon/connector/ssh/sessions/credentials.hh"
* @brief Connection credentials.
*
* Bundle together connection credentials : host, user and
* password. Methods are provided so that they can be compared.
*/
class credentials {
public:
credentials();
credentials(
std::string const& host,
std::string const& user,
std::string const& password);
credentials(credentials const& c);
~credentials();
credentials& operator=(credentials const& c);
bool operator==(credentials const& c) const;
bool operator!=(credentials const& c) const;
bool operator<(credentials const& c) const;
std::string const& get_host() const;
std::string const& get_password() const;
std::string const& get_user() const;
void set_host(std::string const& host);
void set_password(std::string const& password);
void set_user(std::string const& user);
private:
void _copy(credentials const& c);
private:
void _copy(credentials const& c);
std::string _host;
std::string _password;
std::string _user;
};
std::string _host;
std::string _password;
std::string _user;
};
}
CCCS_END()
#endif // !CCCS_CREDENTIALS_HH
#endif // !CCCS_SESSIONS_CREDENTIALS_HH
......@@ -18,9 +18,9 @@
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/credentials.hh"
#include "com/centreon/connector/ssh/sessions/credentials.hh"
using namespace com::centreon::connector::ssh;
using namespace com::centreon::connector::ssh::sessions;
/**************************************
* *
......
/*
** Copyright 2011 Merethis
**
** This file is part of Centreon Connector SSH.
**
** Centreon Connector SSH is free software: you can redistribute it
** and/or modify it under the terms of the GNU Affero General Public
** License as published by the Free Software Foundation, either version
** 3 of the License, or (at your option) any later version.
**
** Centreon Connector SSH is distributed in the hope that it will be
** useful, but WITHOUT ANY WARRANTY; without even the implied warranty
** of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public
** License along with Centreon Connector SSH. If not, see
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/sessions/credentials.hh"
using namespace com::centreon::connector::ssh::sessions;
/**
* Check that credentials can be copy constructed.
*
* @return 0 on success.
*/
int main() {
// Base object.
credentials creds1;
creds1.set_host("localhost");
creds1.set_user("root");
creds1.set_password("random words");
// Copy object.
credentials creds2;
creds2 = creds1;
// Reset base object.
creds1.set_host("centreon.com");
creds1.set_user("daemon");
creds1.set_password("please let me in");
// Check.
return ((creds1.get_host() != "centreon.com")
|| (creds1.get_user() != "daemon")
|| (creds1.get_password() != "please let me in")
|| (creds2.get_host() != "localhost")
|| (creds2.get_user() != "root")
|| (creds2.get_password() != "random words"));
}
/*
** Copyright 2011 Merethis
**
** This file is part of Centreon Connector SSH.
**
** Centreon Connector SSH is free software: you can redistribute it
** and/or modify it under the terms of the GNU Affero General Public
** License as published by the Free Software Foundation, either version
** 3 of the License, or (at your option) any later version.
**
** Centreon Connector SSH is distributed in the hope that it will be
** useful, but WITHOUT ANY WARRANTY; without even the implied warranty
** of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public
** License along with Centreon Connector SSH. If not, see
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/sessions/credentials.hh"
using namespace com::centreon::connector::ssh::sessions;
/**
* Check that credentials can be copy constructed.
*
* @return 0 on success.
*/
int main() {
// Base object.
credentials creds1;
creds1.set_host("localhost");
creds1.set_user("root");
creds1.set_password("random words");
// Copy object.
credentials creds2(creds1);
// Reset base object.
creds1.set_host("centreon.com");
creds1.set_user("daemon");
creds1.set_password("please let me in");
// Check.
return ((creds1.get_host() != "centreon.com")
|| (creds1.get_user() != "daemon")
|| (creds1.get_password() != "please let me in")
|| (creds2.get_host() != "localhost")
|| (creds2.get_user() != "root")
|| (creds2.get_password() != "random words"));
}
/*
** Copyright 2011 Merethis
**
** This file is part of Centreon Connector SSH.
**
** Centreon Connector SSH is free software: you can redistribute it
** and/or modify it under the terms of the GNU Affero General Public
** License as published by the Free Software Foundation, either version
** 3 of the License, or (at your option) any later version.
**
** Centreon Connector SSH is distributed in the hope that it will be
** useful, but WITHOUT ANY WARRANTY; without even the implied warranty
** of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public
** License along with Centreon Connector SSH. If not, see
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/sessions/credentials.hh"
using namespace com::centreon::connector::ssh::sessions;
/**
* Check that credentials are properly default constructed.
*
* @return 0 on success.
*/
int main() {
// Object.
credentials creds;
// Check.
return (!creds.get_host().empty()
|| !creds.get_password().empty()
|| !creds.get_user().empty()
|| !(creds == credentials())
|| (creds != credentials()));
}
/*
** Copyright 2011 Merethis
**
** This file is part of Centreon Connector SSH.
**
** Centreon Connector SSH is free software: you can redistribute it
** and/or modify it under the terms of the GNU Affero General Public
** License as published by the Free Software Foundation, either version
** 3 of the License, or (at your option) any later version.
**
** Centreon Connector SSH is distributed in the hope that it will be
** useful, but WITHOUT ANY WARRANTY; without even the implied warranty
** of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public
** License along with Centreon Connector SSH. If not, see
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/sessions/credentials.hh"
#define HOST1 "localhost"
#define HOST2 "www.centreon.com"
#define HOST3 "www.merethis.com"
/**
* Check credentials' host property.
*
* @return 0 on success.
*/
int main() {
// Object.
com::centreon::connector::ssh::sessions::credentials creds;
// Checks.
int retval(0);
creds.set_host(HOST1);
for (unsigned int i = 0; i < 100; ++i)
retval |= (creds.get_host() != HOST1);
creds.set_host(HOST2);
retval |= (creds.get_host() != HOST2);
creds.set_host(HOST3);
for (unsigned int i = 0; i < 1000; ++i)
retval |= (creds.get_host() != HOST3);
// Return check result.
return (retval);
}
/*
** Copyright 2011 Merethis
**
** This file is part of Centreon Connector SSH.
**
** Centreon Connector SSH is free software: you can redistribute it
** and/or modify it under the terms of the GNU Affero General Public
** License as published by the Free Software Foundation, either version
** 3 of the License, or (at your option) any later version.
**
** Centreon Connector SSH is distributed in the hope that it will be
** useful, but WITHOUT ANY WARRANTY; without even the implied warranty
** of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public
** License along with Centreon Connector SSH. If not, see
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/sessions/credentials.hh"
#define PASSWORD1 "mysimplepassword"
#define PASSWORD2 "thisis_42kinda*complicat3d"
#define PASSWORD3 "a/very{secure%p4ssw0rd;"
/**
* Check credentials' password property.
*
* @return 0 on success.
*/
int main() {
// Object.
com::centreon::connector::ssh::sessions::credentials creds;
// Checks.
int retval(0);
creds.set_password(PASSWORD1);
for (unsigned int i = 0; i < 100; ++i)
retval |= (creds.get_password() != PASSWORD1);
creds.set_password(PASSWORD2);
retval |= (creds.get_password() != PASSWORD2);
creds.set_password(PASSWORD3);
for (unsigned int i = 0; i < 1000; ++i)
retval |= (creds.get_password() != PASSWORD3);
// Return check result.
return (retval);
}
/*
** Copyright 2011 Merethis
**
** This file is part of Centreon Connector SSH.
**
** Centreon Connector SSH is free software: you can redistribute it
** and/or modify it under the terms of the GNU Affero General Public
** License as published by the Free Software Foundation, either version
** 3 of the License, or (at your option) any later version.
**
** Centreon Connector SSH is distributed in the hope that it will be
** useful, but WITHOUT ANY WARRANTY; without even the implied warranty
** of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public
** License along with Centreon Connector SSH. If not, see
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/sessions/credentials.hh"
#define USER1 "root"
#define USER2 "Centreon"
#define USER3 "Merethis"
/**
* Check credentials' user property.
*
* @return 0 on success.
*/
int main() {
// Object.
com::centreon::connector::ssh::sessions::credentials creds;
// Checks.
int retval(0);
creds.set_user(USER1);
for (unsigned int i = 0; i < 100; ++i)
retval |= (creds.get_user() != USER1);
creds.set_user(USER2);
retval |= (creds.get_user() != USER2);
creds.set_user(USER3);
for (unsigned int i = 0; i < 1000; ++i)
retval |= (creds.get_user() != USER3);
// Return check result.
return (retval);
}
Supports Markdown
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