From 06a2fcd2a0eb36db756c9126c7301d2e567209e8 Mon Sep 17 00:00:00 2001 From: fgerlits Date: Wed, 24 Nov 2004 11:09:23 +0000 Subject: [PATCH] added a test authentication client, and (temporarily) removed the 'make -C modules/storageServer' lines from the makefiles --- .../modules/authentication/etc/Makefile.in | 8 +- .../Authentication/WebAuthenticationClient.h | 6 +- .../src/TestAuthenticationClient.cxx | 188 ++++++++++++++++ .../src/TestAuthenticationClient.h | 202 ++++++++++++++++++ .../src/TestAuthenticationClientTest.cxx | 123 +++++++++++ .../src/TestAuthenticationClientTest.h | 115 ++++++++++ .../products/scheduler/etc/Makefile.in | 6 +- 7 files changed, 639 insertions(+), 9 deletions(-) create mode 100644 livesupport/modules/authentication/src/TestAuthenticationClient.cxx create mode 100644 livesupport/modules/authentication/src/TestAuthenticationClient.h create mode 100644 livesupport/modules/authentication/src/TestAuthenticationClientTest.cxx create mode 100644 livesupport/modules/authentication/src/TestAuthenticationClientTest.h diff --git a/livesupport/modules/authentication/etc/Makefile.in b/livesupport/modules/authentication/etc/Makefile.in index 56eb41adc..631edae74 100644 --- a/livesupport/modules/authentication/etc/Makefile.in +++ b/livesupport/modules/authentication/etc/Makefile.in @@ -20,8 +20,8 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # -# Author : $Author: maroy $ -# Version : $Revision: 1.3 $ +# Author : $Author: fgerlits $ +# Version : $Revision: 1.4 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/etc/Makefile.in,v $ # # @configure_input@ @@ -96,9 +96,11 @@ LDFLAGS = @LDFLAGS@ -pthread -L${USR_LIB_DIR} -L${CORE_LIB_DIR} -L${LIB_DIR} # Dependencies #------------------------------------------------------------------------------- AUTHENTICATION_LIB_OBJS = ${TMP_DIR}/AuthenticationClientFactory.o \ + ${TMP_DIR}/TestAuthenticationClient.o \ ${TMP_DIR}/WebAuthenticationClient.o TEST_RUNNER_OBJS = ${TMP_DIR}/WebAuthenticationClientTest.o \ + ${TMP_DIR}/TestAuthenticationClientTest.o \ ${TMP_DIR}/TestRunner.o TEST_RUNNER_LIBS = -l${AUTHENTICATION_LIB} -l${CORE_LIB} -lxml++-1.0 \ @@ -133,7 +135,7 @@ distclean: clean docclean ${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te* check: all ${TEST_RUNNER} - ${MAKE} -C ${STORAGE_SERVER_DIR} +# ${MAKE} -C ${STORAGE_SERVER_DIR} LD_LIBRARY_PATH=${USR_LIB_DIR} ${TEST_RUNNER} \ -o ${TEST_RESULTS} -s ${TEST_XSLT} diff --git a/livesupport/modules/authentication/include/LiveSupport/Authentication/WebAuthenticationClient.h b/livesupport/modules/authentication/include/LiveSupport/Authentication/WebAuthenticationClient.h index f6437ffc6..1f429d934 100644 --- a/livesupport/modules/authentication/include/LiveSupport/Authentication/WebAuthenticationClient.h +++ b/livesupport/modules/authentication/include/LiveSupport/Authentication/WebAuthenticationClient.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/include/LiveSupport/Authentication/Attic/WebAuthenticationClient.h,v $ ------------------------------------------------------------------------------*/ @@ -69,7 +69,7 @@ using namespace LiveSupport::Core; * called webAuthentication. This element contains a child element * specifying the location of the authentication server. * - * A authenticationClientFactory configuration element may look like the following: + * A webAuthentication configuration element may look like the following: * *

  *  <webAuthentication>
@@ -92,7 +92,7 @@ using namespace LiveSupport::Core;
  *  
* * @author $Author: fgerlits $ - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ class WebAuthenticationClient : virtual public Configurable, diff --git a/livesupport/modules/authentication/src/TestAuthenticationClient.cxx b/livesupport/modules/authentication/src/TestAuthenticationClient.cxx new file mode 100644 index 000000000..b609ae2f0 --- /dev/null +++ b/livesupport/modules/authentication/src/TestAuthenticationClient.cxx @@ -0,0 +1,188 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/TestAuthenticationClient.cxx,v $ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#if HAVE_UNISTD_H +#include +#else +#error "Need unistd.h" +#endif + +#include // for testing only, REMOVE THIS later +#include +#include +#include +#include + +#include "TestAuthenticationClient.h" + +using namespace boost::posix_time; +using namespace XmlRpc; + +using namespace LiveSupport::Core; +using namespace LiveSupport::Authentication; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ configuration file constants */ + +/*------------------------------------------------------------------------------ + * The name of the config element for this class + *----------------------------------------------------------------------------*/ +const std::string TestAuthenticationClient::configElementNameStr + = "testAuthentication"; + +/*------------------------------------------------------------------------------ + * The name of the config child element for the login and password + *----------------------------------------------------------------------------*/ +static const std::string userConfigElementName = "user"; + +/*------------------------------------------------------------------------------ + * The name of the config element attribute for the login + *----------------------------------------------------------------------------*/ +static const std::string userLoginAttrName = "login"; + +/*------------------------------------------------------------------------------ + * The name of the config element attribute for the password + *----------------------------------------------------------------------------*/ +static const std::string userPasswordAttrName = "password"; + +/*------------------------------------------------------------------------------ + * The dummy sessionId string returned by this authentication client + *----------------------------------------------------------------------------*/ +static const std::string dummySessionIdString = "dummySessionId"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Configure the test storage client. + *----------------------------------------------------------------------------*/ +void +TestAuthenticationClient :: configure(const xmlpp::Element & element) + throw (std::invalid_argument, + std::logic_error) +{ + if (element.get_name() != configElementNameStr) { + std::string eMsg = "Bad configuration element "; + eMsg += element.get_name(); + throw std::invalid_argument(eMsg); + } + + const xmlpp::Attribute * attribute; + + // read the user data + xmlpp::Node::NodeList childNodes + = element.get_children(userConfigElementName); + xmlpp::Node::NodeList::iterator it = childNodes.begin(); + + if (it == childNodes.end()) { + std::string eMsg = "missing "; + eMsg += userConfigElementName; + eMsg += " XML element"; + throw std::invalid_argument(eMsg); + } + + const xmlpp::Element * userConfigElement + = dynamic_cast (*it); + if (!(attribute = userConfigElement + ->get_attribute(userLoginAttrName))) { + std::string eMsg = "Missing attribute "; + eMsg += userLoginAttrName; + throw std::invalid_argument(eMsg); + } + userLogin = attribute->get_value(); + + if (!(attribute = userConfigElement + ->get_attribute(userPasswordAttrName))) { + std::string eMsg = "Missing attribute "; + eMsg += userPasswordAttrName; + throw std::invalid_argument(eMsg); + } + userPassword = attribute->get_value(); + + ++it; + if (it != childNodes.end()) { + std::string eMsg = "more than one "; + eMsg += userConfigElementName; + eMsg += " XML element"; + throw std::invalid_argument(eMsg); + } + + sessionIdList.clear(); +} + + +/*------------------------------------------------------------------------------ + * Login to the storage server. + *----------------------------------------------------------------------------*/ +Ptr::Ref +TestAuthenticationClient :: login(const std::string & login, + const std::string & password) + throw () +{ + Ptr::Ref sessionId; // initialized to 0 + + if (login == userLogin && password == userPassword) { + std::stringstream sessionIdStream; + sessionIdStream << dummySessionIdString; + sessionIdStream << rand(); + sessionIdList.insert(sessionIdStream.str()); + sessionId.reset(new SessionId(sessionIdStream.str())); + } + return sessionId; +} + + +/*------------------------------------------------------------------------------ + * Logout from the storage server. + *----------------------------------------------------------------------------*/ +const bool +TestAuthenticationClient :: logout(Ptr::Ref sessionId) + throw () +{ + if (sessionIdList.erase(sessionId->getId())) { + return true; + } + else { + return false; + } +} + diff --git a/livesupport/modules/authentication/src/TestAuthenticationClient.h b/livesupport/modules/authentication/src/TestAuthenticationClient.h new file mode 100644 index 000000000..45684b078 --- /dev/null +++ b/livesupport/modules/authentication/src/TestAuthenticationClient.h @@ -0,0 +1,202 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/TestAuthenticationClient.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef TestAuthenticationClient_h +#define TestAuthenticationClient_h + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include +#include +#include + +#include "LiveSupport/Core/Ptr.h" +#include "LiveSupport/Core/Configurable.h" +#include "LiveSupport/Core/SessionId.h" +#include "LiveSupport/Core/AuthenticationClientInterface.h" + + +namespace LiveSupport { +namespace Authentication { + +using namespace LiveSupport; +using namespace LiveSupport::Core; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * A dummy authentication client. + * + * This object has to be configured with an XML configuration element + * called testAuthentication. This element contains a child element + * specifying the login and password. + * + * A testAuthentication configuration element may look like the following: + * + *

+ *  <testAuthentication>
+ *      <user
+ *          login="root"
+ *          password="q" 
+ *      />
+ *  </testAuthentication>
+ *  
+ * + * The DTD for the above element is: + * + *

+ *  <!ELEMENT testAuthentication (user) >
+ *  <!ELEMENT user EMPTY >
+ *  <!ATTLIST user login      CDATA      #REQUIRED >
+ *  <!ATTLIST user password   CDATA      #REQUIRED >
+ *  
+ * + * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + */ +class TestAuthenticationClient : + virtual public Configurable, + virtual public AuthenticationClientInterface +{ + private: + /** + * The name of the configuration XML elmenent used by + * TestAuthenticationClient + */ + static const std::string configElementNameStr; + + /** + * The name of the storage server, e.g. "myserver.mycompany.com". + */ + std::string userLogin; + + /** + * The path to the storage server php page. + */ + std::string userPassword; + + /** + * A type for the list of sessionId's. + */ + typedef std::set + sessionIdListType; + + /** + * A list of the sessionId's we have issued. + */ + sessionIdListType sessionIdList; + + + public: + /** + * A virtual destructor, as this class has virtual functions. + */ + virtual + ~TestAuthenticationClient(void) throw () + { + } + + /** + * Return the name of the XML element this object expects + * to be sent to a call to configure(). + * + * @return the name of the expected XML configuration element. + */ + static const std::string + getConfigElementName(void) throw () + { + return configElementNameStr; + } + + /** + * Configure the object based on the XML element supplied. + * + * @param element the XML element to configure the object from. + * @exception std::invalid_argument if the supplied XML element + * contains bad configuraiton information + * @exception std::logic_error if the scheduler daemon has already + * been configured, and can not be reconfigured. + */ + virtual void + configure(const xmlpp::Element & element) + throw (std::invalid_argument, + std::logic_error); + + /** + * Login to the storage server, using the data read from the + * configuration file. + * Returns a new session ID; in case of an error, returns a + * null pointer. + * + * For testing, use the login "root" with the password "q". + * + * @return the new session ID + */ + virtual Ptr::Ref + login(const std::string &login, const std::string &password) + throw (); + + /** + * Logout from the storage server. + * + * @param sessionId the ID of the session to end + * @return true if logged out successfully, false if not + */ + virtual const bool + logout(Ptr::Ref sessionId) + throw (); + +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace Authentication +} // namespace LiveSupport + +#endif // TestAuthenticationClient_h + diff --git a/livesupport/modules/authentication/src/TestAuthenticationClientTest.cxx b/livesupport/modules/authentication/src/TestAuthenticationClientTest.cxx new file mode 100644 index 000000000..146be13c9 --- /dev/null +++ b/livesupport/modules/authentication/src/TestAuthenticationClientTest.cxx @@ -0,0 +1,123 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/TestAuthenticationClientTest.cxx,v $ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#if HAVE_UNISTD_H +#include +#else +#error "Need unistd.h" +#endif + + +#include +#include +#include + +#include "LiveSupport/Core/SessionId.h" +#include "TestAuthenticationClientTest.h" + + +using namespace std; +using namespace LiveSupport::Core; +using namespace LiveSupport::Authentication; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +CPPUNIT_TEST_SUITE_REGISTRATION(TestAuthenticationClientTest); + +/** + * The name of the configuration file for the authentication client factory daemon. + */ +static const std::string configFileName = "etc/testAuthentication.xml"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Set up the test environment + *----------------------------------------------------------------------------*/ +void +TestAuthenticationClientTest :: setUp(void) throw () +{ + try { + Ptr::Ref parser( + new xmlpp::DomParser(configFileName, true)); + const xmlpp::Document * document = parser->get_document(); + const xmlpp::Element * root = document->get_root_node(); + + tac.reset(new TestAuthenticationClient()); + tac->configure(*root); + } catch (std::invalid_argument &e) { + CPPUNIT_FAIL("semantic error in configuration file"); + } catch (xmlpp::exception &e) { + CPPUNIT_FAIL("error parsing configuration file"); + } +} + + +/*------------------------------------------------------------------------------ + * Clean up the test environment + *----------------------------------------------------------------------------*/ +void +TestAuthenticationClientTest :: tearDown(void) throw () +{ + tac.reset(); +} + + +/*------------------------------------------------------------------------------ + * Test to see if we can log on and off + *----------------------------------------------------------------------------*/ +void +TestAuthenticationClientTest :: firstTest(void) + throw (CPPUNIT_NS::Exception) +{ + Ptr::Ref sessionId; + + CPPUNIT_ASSERT(!(sessionId = tac->login("Piszkos Fred", "malnaszor"))); + + sessionId.reset(new SessionId("ceci n'est pas un session ID")); + CPPUNIT_ASSERT(!tac->logout(sessionId)); + + CPPUNIT_ASSERT( sessionId = tac->login("root", "q")); + CPPUNIT_ASSERT( tac->logout(sessionId)); + CPPUNIT_ASSERT(!tac->logout(sessionId)); +} + diff --git a/livesupport/modules/authentication/src/TestAuthenticationClientTest.h b/livesupport/modules/authentication/src/TestAuthenticationClientTest.h new file mode 100644 index 000000000..3622ba7de --- /dev/null +++ b/livesupport/modules/authentication/src/TestAuthenticationClientTest.h @@ -0,0 +1,115 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/TestAuthenticationClientTest.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef TestAuthenticationClientTest_h +#define TestAuthenticationClientTest_h + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include + +#include "TestAuthenticationClient.h" + +namespace LiveSupport { +namespace Authentication { + +using namespace LiveSupport::Core; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * Unit test for the TestAuthenticationClient class. + * + * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + * @see TestAuthenticationClient + */ +class TestAuthenticationClientTest : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(TestAuthenticationClientTest); + CPPUNIT_TEST(firstTest); + CPPUNIT_TEST_SUITE_END(); + + private: + /** + * The TestAuthenticationClient instance to test. + */ + Ptr::Ref tac; + + protected: + + /** + * A simple test. + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + firstTest(void) throw (CPPUNIT_NS::Exception); + + public: + + /** + * Set up the environment for the test case. + */ + void + setUp(void) throw (); + + /** + * Clean up the environment after the test case. + */ + void + tearDown(void) throw (); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace Authentication +} // namespace LiveSupport + +#endif // TestAuthenticationClientTest_h + diff --git a/livesupport/products/scheduler/etc/Makefile.in b/livesupport/products/scheduler/etc/Makefile.in index b8df3a6cc..ba9d06a49 100644 --- a/livesupport/products/scheduler/etc/Makefile.in +++ b/livesupport/products/scheduler/etc/Makefile.in @@ -20,8 +20,8 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # -# Author : $Author: maroy $ -# Version : $Revision: 1.25 $ +# Author : $Author: fgerlits $ +# Version : $Revision: 1.26 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/etc/Makefile.in,v $ # # @configure_input@ @@ -273,7 +273,7 @@ uninstall: ${SCHEDULER_EXE} uninstall storage_server_init: - ${MAKE} -C ${STORAGE_SERVER_DIR} +# ${MAKE} -C ${STORAGE_SERVER_DIR} #-------------------------------------------------------------------------------