added C++ API in the authentication module for the new storage server
methods loadPref and savePref
This commit is contained in:
parent
34330c184a
commit
0bf873f13c
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.4 $
|
||||
Version : $Revision: 1.5 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/include/LiveSupport/Authentication/AuthenticationClientInterface.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -44,7 +44,11 @@
|
|||
|
||||
#include "LiveSupport/Core/Ptr.h"
|
||||
#include "LiveSupport/Core/SessionId.h"
|
||||
#include "LiveSupport/Authentication/AuthenticationException.h"
|
||||
#include "LiveSupport/Core/XmlRpcException.h"
|
||||
#include "LiveSupport/Core/XmlRpcInvalidArgumentException.h"
|
||||
#include "LiveSupport/Core/XmlRpcCommunicationException.h"
|
||||
#include "LiveSupport/Core/XmlRpcMethodFaultException.h"
|
||||
#include "LiveSupport/Core/XmlRpcMethodResponseException.h"
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace Authentication {
|
||||
|
@ -64,7 +68,7 @@ using namespace LiveSupport::Core;
|
|||
* An interface for authentication clients.
|
||||
*
|
||||
* @author $Author: fgerlits $
|
||||
* @version $Revision: 1.4 $
|
||||
* @version $Revision: 1.5 $
|
||||
*/
|
||||
class AuthenticationClientInterface
|
||||
{
|
||||
|
@ -83,13 +87,13 @@ class AuthenticationClientInterface
|
|||
* fault response
|
||||
* @exception XmlRpcMethodResponseException response from XML-RPC
|
||||
* method is incorrect
|
||||
* @exception AuthenticationException other error
|
||||
* (TestStorageClient only)
|
||||
* @exception XmlRpcException other error
|
||||
* (TestAuthenticationClient only)
|
||||
* @return the new session ID
|
||||
*/
|
||||
virtual Ptr<SessionId>::Ref
|
||||
login(const std::string &login, const std::string &password)
|
||||
throw (AuthenticationException)
|
||||
throw (XmlRpcException)
|
||||
= 0;
|
||||
|
||||
/**
|
||||
|
@ -102,12 +106,60 @@ class AuthenticationClientInterface
|
|||
* fault response
|
||||
* @exception XmlRpcMethodResponseException response from XML-RPC
|
||||
* method is incorrect
|
||||
* @exception AuthenticationException other error
|
||||
* (TestStorageClient only)
|
||||
* @exception XmlRpcException other error
|
||||
* (TestAuthenticationClient only)
|
||||
*/
|
||||
virtual void
|
||||
logout(Ptr<SessionId>::Ref sessionId)
|
||||
throw (AuthenticationException)
|
||||
throw (XmlRpcException)
|
||||
= 0;
|
||||
|
||||
/**
|
||||
* Load a `user preferences' item from the server.
|
||||
*
|
||||
* @param sessionId the ID of the current session (from login())
|
||||
* @param key the name of the item
|
||||
*
|
||||
* @exception XmlRpcInvalidArgumentException
|
||||
* bad sessionId argument
|
||||
* @exception XmlRpcCommunicationException
|
||||
* problem with performing XML-RPC call
|
||||
* @exception XmlRpcMethodFaultException
|
||||
* XML-RPC method returned fault response
|
||||
* @exception XmlRpcMethodResponseException
|
||||
* response from XML-RPC method is incorrect
|
||||
* @exception XmlRpcException other error
|
||||
* (TestAuthenticationClient only)
|
||||
*/
|
||||
virtual Ptr<Glib::ustring>::Ref
|
||||
loadPreferencesItem(Ptr<SessionId>::Ref sessionId,
|
||||
const Glib::ustring & key)
|
||||
throw (XmlRpcException)
|
||||
= 0;
|
||||
|
||||
/**
|
||||
* Store a `user preferences' item on the server.
|
||||
*
|
||||
* @param sessionId the ID of the current session (from login())
|
||||
* @param key the name of the item
|
||||
* @param value the (new) value of the item
|
||||
*
|
||||
* @exception XmlRpcInvalidArgumentException
|
||||
* bad sessionId or value argument
|
||||
* @exception XmlRpcCommunicationException
|
||||
* problem with performing XML-RPC call
|
||||
* @exception XmlRpcMethodFaultException
|
||||
* XML-RPC method returned fault response
|
||||
* @exception XmlRpcMethodResponseException
|
||||
* response from XML-RPC method is incorrect
|
||||
* @exception XmlRpcException other error
|
||||
* (TestAuthenticationClient only)
|
||||
*/
|
||||
virtual void
|
||||
savePreferencesItem(Ptr<SessionId>::Ref sessionId,
|
||||
const Glib::ustring & key,
|
||||
Ptr<const Glib::ustring>::Ref value)
|
||||
throw (XmlRpcException)
|
||||
= 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,115 +0,0 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/include/LiveSupport/Authentication/Attic/AuthenticationException.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef LiveSupport_Authentication_AuthenticationException_h
|
||||
#define LiveSupport_Authentication_AuthenticationException_h
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace Authentication {
|
||||
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* Common parent of exception classes for this module.
|
||||
*
|
||||
* @author $Author: fgerlits $
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
class AuthenticationException : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
AuthenticationException(const std::string &msg)
|
||||
: std::runtime_error(msg) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* XML-RPC communication problem.
|
||||
*/
|
||||
class XmlRpcCommunicationException : public AuthenticationException
|
||||
{
|
||||
public:
|
||||
XmlRpcCommunicationException(const std::string &msg)
|
||||
: AuthenticationException(msg) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* XML-RPC fault thrown by the method called.
|
||||
*/
|
||||
class XmlRpcMethodFaultException : public AuthenticationException
|
||||
{
|
||||
public:
|
||||
XmlRpcMethodFaultException(const std::string &msg)
|
||||
: AuthenticationException(msg) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Unexpected response from the XML-RPC method.
|
||||
*/
|
||||
class XmlRpcMethodResponseException : public AuthenticationException
|
||||
{
|
||||
public:
|
||||
XmlRpcMethodResponseException(const std::string &msg)
|
||||
: AuthenticationException(msg) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace Authentication
|
||||
} // namespace LiveSupport
|
||||
|
||||
#endif // LiveSupport_Authentication_AuthenticationException_h
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.2 $
|
||||
Version : $Revision: 1.3 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/AuthenticationClientFactoryTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -119,7 +119,7 @@ AuthenticationClientFactoryTest :: firstTest(void)
|
|||
try {
|
||||
sessionId = authentication->login("root", "q");
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,99 @@ AuthenticationClientFactoryTest :: firstTest(void)
|
|||
try {
|
||||
authentication->logout(sessionId);
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Test to see if we can save and load user preferences.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
AuthenticationClientFactoryTest :: preferencesTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
Ptr<AuthenticationClientFactory>::Ref
|
||||
acf = AuthenticationClientFactory::getInstance();
|
||||
Ptr<AuthenticationClientInterface>::Ref
|
||||
authentication = acf->getAuthenticationClient();
|
||||
|
||||
Ptr<SessionId>::Ref sessionId;
|
||||
Ptr<const Glib::ustring>::Ref prefValue;
|
||||
|
||||
// check "please log in" error
|
||||
try {
|
||||
prefValue = authentication->loadPreferencesItem(sessionId, "something");
|
||||
CPPUNIT_FAIL("Allowed operation without login.");
|
||||
} catch (XmlRpcException &e) {
|
||||
}
|
||||
|
||||
// log in
|
||||
try {
|
||||
sessionId = authentication->login("root", "q");
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
// check "no such key" error
|
||||
try {
|
||||
prefValue = authentication->loadPreferencesItem(sessionId, "eye_color");
|
||||
CPPUNIT_FAIL("Retrieved non-existent user preferences item.");
|
||||
} catch (XmlRpcException &e) {
|
||||
}
|
||||
|
||||
// check normal save and load
|
||||
prefValue.reset(new const Glib::ustring("chyornye"));
|
||||
try {
|
||||
authentication->savePreferencesItem(sessionId, "eye_color", prefValue);
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
Ptr<const Glib::ustring>::Ref newPrefValue;
|
||||
try {
|
||||
newPrefValue = authentication->loadPreferencesItem(sessionId, "eye_color");
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(*newPrefValue == *prefValue);
|
||||
|
||||
// try some unicode characters
|
||||
prefValue.reset(new const Glib::ustring("страстные"));
|
||||
try {
|
||||
authentication->savePreferencesItem(sessionId, "eye_color", prefValue);
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
try {
|
||||
newPrefValue = authentication->loadPreferencesItem(sessionId, "eye_color");
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(*newPrefValue == "страстные");
|
||||
|
||||
// check another normal save and load
|
||||
prefValue.reset(new const Glib::ustring("ne dobryj"));
|
||||
try {
|
||||
authentication->savePreferencesItem(sessionId, "hour", prefValue);
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
try {
|
||||
newPrefValue = authentication->loadPreferencesItem(sessionId, "hour");
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(*newPrefValue == *prefValue);
|
||||
|
||||
// and log out
|
||||
try {
|
||||
authentication->logout(sessionId);
|
||||
}
|
||||
catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.1 $
|
||||
Version : $Revision: 1.2 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/AuthenticationClientFactoryTest.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -61,13 +61,14 @@ using namespace LiveSupport::Core;
|
|||
* Unit test for the AuthenticationClientFactory class.
|
||||
*
|
||||
* @author $Author: fgerlits $
|
||||
* @version $Revision: 1.1 $
|
||||
* @version $Revision: 1.2 $
|
||||
* @see AuthenticationClientFactory
|
||||
*/
|
||||
class AuthenticationClientFactoryTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(AuthenticationClientFactoryTest);
|
||||
CPPUNIT_TEST(firstTest);
|
||||
CPPUNIT_TEST(preferencesTest);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
protected:
|
||||
|
@ -80,6 +81,14 @@ class AuthenticationClientFactoryTest : public CPPUNIT_NS::TestFixture
|
|||
void
|
||||
firstTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
/**
|
||||
* Test saving and load of user preferences.
|
||||
*
|
||||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
void
|
||||
preferencesTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.4 $
|
||||
Version : $Revision: 1.5 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/TestAuthenticationClient.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -99,7 +99,7 @@ TestAuthenticationClient :: configure(const xmlpp::Element & element)
|
|||
throw (std::invalid_argument)
|
||||
{
|
||||
if (element.get_name() != configElementNameStr) {
|
||||
std::string eMsg = "Bad configuration element ";
|
||||
std::string eMsg = "bad configuration element ";
|
||||
eMsg += element.get_name();
|
||||
throw std::invalid_argument(eMsg);
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ TestAuthenticationClient :: configure(const xmlpp::Element & element)
|
|||
= dynamic_cast<const xmlpp::Element*> (*it);
|
||||
if (!(attribute = userConfigElement
|
||||
->get_attribute(userLoginAttrName))) {
|
||||
std::string eMsg = "Missing attribute ";
|
||||
std::string eMsg = "missing attribute ";
|
||||
eMsg += userLoginAttrName;
|
||||
throw std::invalid_argument(eMsg);
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ TestAuthenticationClient :: configure(const xmlpp::Element & element)
|
|||
|
||||
if (!(attribute = userConfigElement
|
||||
->get_attribute(userPasswordAttrName))) {
|
||||
std::string eMsg = "Missing attribute ";
|
||||
std::string eMsg = "missing attribute ";
|
||||
eMsg += userPasswordAttrName;
|
||||
throw std::invalid_argument(eMsg);
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ TestAuthenticationClient :: configure(const xmlpp::Element & element)
|
|||
Ptr<SessionId>::Ref
|
||||
TestAuthenticationClient :: login(const std::string & login,
|
||||
const std::string & password)
|
||||
throw (AuthenticationException)
|
||||
throw (XmlRpcException)
|
||||
{
|
||||
Ptr<SessionId>::Ref sessionId;
|
||||
|
||||
|
@ -170,7 +170,7 @@ TestAuthenticationClient :: login(const std::string & login,
|
|||
return sessionId;
|
||||
}
|
||||
else {
|
||||
throw AuthenticationException("Incorrect login or password.");
|
||||
throw XmlRpcException("incorrect login or password");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,14 +180,57 @@ TestAuthenticationClient :: login(const std::string & login,
|
|||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
TestAuthenticationClient :: logout(Ptr<SessionId>::Ref sessionId)
|
||||
throw (AuthenticationException)
|
||||
throw (XmlRpcException)
|
||||
{
|
||||
// this returns the number of entries found and erased
|
||||
if (sessionIdList.erase(sessionId->getId())) {
|
||||
if (!sessionId || sessionIdList.erase(sessionId->getId())) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
throw AuthenticationException("Logout called without previous login.");
|
||||
throw XmlRpcException("logout() called without previous login()");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Load a `user preferences' item from the server.
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<Glib::ustring>::Ref
|
||||
TestAuthenticationClient :: loadPreferencesItem(
|
||||
Ptr<SessionId>::Ref sessionId,
|
||||
const Glib::ustring & key)
|
||||
throw (XmlRpcException)
|
||||
{
|
||||
if (!sessionId
|
||||
|| sessionIdList.find(sessionId->getId()) == sessionIdList.end()) {
|
||||
throw XmlRpcException("loadPreferences() called before login()");
|
||||
}
|
||||
|
||||
preferencesType::iterator it;
|
||||
|
||||
if ((it = preferences.find(key)) == preferences.end()) {
|
||||
throw XmlRpcException("no such user preferences item");
|
||||
}
|
||||
Ptr<Glib::ustring>::Ref value(new Glib::ustring(*it->second));
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Store a `user preferences' item on the server.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
TestAuthenticationClient :: savePreferencesItem(
|
||||
Ptr<SessionId>::Ref sessionId,
|
||||
const Glib::ustring & key,
|
||||
Ptr<const Glib::ustring>::Ref value)
|
||||
throw (XmlRpcException)
|
||||
{
|
||||
if (sessionIdList.find(sessionId->getId()) == sessionIdList.end()) {
|
||||
throw XmlRpcException("loadPreferences() called before login()");
|
||||
}
|
||||
|
||||
preferences[key] = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.6 $
|
||||
Version : $Revision: 1.7 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/TestAuthenticationClient.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -92,7 +92,7 @@ using namespace LiveSupport::Core;
|
|||
* </code></pre>
|
||||
*
|
||||
* @author $Author: fgerlits $
|
||||
* @version $Revision: 1.6 $
|
||||
* @version $Revision: 1.7 $
|
||||
*/
|
||||
class TestAuthenticationClient :
|
||||
virtual public Configurable,
|
||||
|
@ -131,6 +131,17 @@ class TestAuthenticationClient :
|
|||
*/
|
||||
int sessionCounter;
|
||||
|
||||
/**
|
||||
* A type for the list of user preferences.
|
||||
*/
|
||||
typedef std::map<const Glib::ustring, Ptr<const Glib::ustring>::Ref>
|
||||
preferencesType;
|
||||
|
||||
/**
|
||||
* A list of the user preferences items stored.
|
||||
*/
|
||||
preferencesType preferences;
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
|
@ -173,24 +184,50 @@ class TestAuthenticationClient :
|
|||
* null pointer.
|
||||
*
|
||||
* @return the new session ID
|
||||
* @exception AuthenticationException login or password is incorrect
|
||||
* @exception XmlRpcException login or password is incorrect
|
||||
* (does not match those given in the configuration file)
|
||||
*/
|
||||
virtual Ptr<SessionId>::Ref
|
||||
login(const std::string &login, const std::string &password)
|
||||
throw (AuthenticationException);
|
||||
throw (XmlRpcException);
|
||||
|
||||
/**
|
||||
* Logout from the authentication server.
|
||||
*
|
||||
* @param sessionId the ID of the session to end
|
||||
* @exception AuthenticationException the sessionId does not match
|
||||
* @exception XmlRpcException the sessionId does not match
|
||||
* one issued by login()
|
||||
*/
|
||||
virtual void
|
||||
logout(Ptr<SessionId>::Ref sessionId)
|
||||
throw (AuthenticationException);
|
||||
throw (XmlRpcException);
|
||||
|
||||
/**
|
||||
* Load a `user preferences' item from the server.
|
||||
*
|
||||
* @param sessionId the ID of the current session (from login())
|
||||
* @param key the name of the item
|
||||
* @exception XmlRpcException invalid session ID
|
||||
* or key does not match anything stored
|
||||
*/
|
||||
virtual Ptr<Glib::ustring>::Ref
|
||||
loadPreferencesItem(Ptr<SessionId>::Ref sessionId,
|
||||
const Glib::ustring & key)
|
||||
throw (XmlRpcException);
|
||||
|
||||
/**
|
||||
* Store a `user preferences' item on the server.
|
||||
*
|
||||
* @param sessionId the ID of the current session (from login())
|
||||
* @param key the name of the item
|
||||
* @param value the (new) value of the item
|
||||
* @exception XmlRpcException invalid session ID
|
||||
*/
|
||||
virtual void
|
||||
savePreferencesItem(Ptr<SessionId>::Ref sessionId,
|
||||
const Glib::ustring & key,
|
||||
Ptr<const Glib::ustring>::Ref value)
|
||||
throw (XmlRpcException);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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/src/TestAuthenticationClientTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -115,7 +115,7 @@ TestAuthenticationClientTest :: firstTest(void)
|
|||
sessionId = tac->login("Piszkos Fred", "malnaszor");
|
||||
CPPUNIT_FAIL("Allowed login with incorrect login and password.");
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
}
|
||||
|
||||
// TODO: this call writes some garbage to cerr; it should be told not to
|
||||
|
@ -124,20 +124,20 @@ TestAuthenticationClientTest :: firstTest(void)
|
|||
tac->logout(sessionId);
|
||||
CPPUNIT_FAIL("Allowed logout without previous login.");
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
}
|
||||
|
||||
try {
|
||||
sessionId = tac->login("root", "q");
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
try {
|
||||
tac->logout(sessionId);
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,93 @@ TestAuthenticationClientTest :: firstTest(void)
|
|||
tac->logout(sessionId);
|
||||
CPPUNIT_FAIL("Allowed to logout twice.");
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Test to see if we can save and load user preferences.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
TestAuthenticationClientTest :: preferencesTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
Ptr<SessionId>::Ref sessionId;
|
||||
Ptr<const Glib::ustring>::Ref prefValue;
|
||||
|
||||
// check "please log in" error
|
||||
try {
|
||||
prefValue = tac->loadPreferencesItem(sessionId, "something");
|
||||
CPPUNIT_FAIL("Allowed operation without login.");
|
||||
} catch (XmlRpcException &e) {
|
||||
}
|
||||
|
||||
// log in
|
||||
try {
|
||||
sessionId = tac->login("root", "q");
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
// check "no such key" error
|
||||
try {
|
||||
prefValue = tac->loadPreferencesItem(sessionId, "eye_color");
|
||||
CPPUNIT_FAIL("Retrieved non-existent user preferences item.");
|
||||
} catch (XmlRpcException &e) {
|
||||
}
|
||||
|
||||
// check normal save and load
|
||||
prefValue.reset(new const Glib::ustring("chyornye"));
|
||||
try {
|
||||
tac->savePreferencesItem(sessionId, "eye_color", prefValue);
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
Ptr<const Glib::ustring>::Ref newPrefValue;
|
||||
try {
|
||||
newPrefValue = tac->loadPreferencesItem(sessionId, "eye_color");
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(*newPrefValue == *prefValue);
|
||||
|
||||
// try some unicode characters
|
||||
prefValue.reset(new const Glib::ustring("страстные"));
|
||||
try {
|
||||
tac->savePreferencesItem(sessionId, "eye_color", prefValue);
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
try {
|
||||
newPrefValue = tac->loadPreferencesItem(sessionId, "eye_color");
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(*newPrefValue == "страстные");
|
||||
|
||||
// check another normal save and load
|
||||
prefValue.reset(new const Glib::ustring("ne dobryj"));
|
||||
try {
|
||||
tac->savePreferencesItem(sessionId, "hour", prefValue);
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
try {
|
||||
newPrefValue = tac->loadPreferencesItem(sessionId, "hour");
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(*newPrefValue == *prefValue);
|
||||
|
||||
// and log out
|
||||
try {
|
||||
tac->logout(sessionId);
|
||||
}
|
||||
catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.1 $
|
||||
Version : $Revision: 1.2 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/TestAuthenticationClientTest.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -61,13 +61,14 @@ using namespace LiveSupport::Core;
|
|||
* Unit test for the TestAuthenticationClient class.
|
||||
*
|
||||
* @author $Author: fgerlits $
|
||||
* @version $Revision: 1.1 $
|
||||
* @version $Revision: 1.2 $
|
||||
* @see TestAuthenticationClient
|
||||
*/
|
||||
class TestAuthenticationClientTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestAuthenticationClientTest);
|
||||
CPPUNIT_TEST(firstTest);
|
||||
CPPUNIT_TEST(preferencesTest);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
|
@ -86,6 +87,14 @@ class TestAuthenticationClientTest : public CPPUNIT_NS::TestFixture
|
|||
void
|
||||
firstTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
/**
|
||||
* Test saving and load of user preferences.
|
||||
*
|
||||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
void
|
||||
preferencesTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.6 $
|
||||
Version : $Revision: 1.7 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/WebAuthenticationClient.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -66,22 +66,22 @@ const std::string WebAuthenticationClient::configElementNameStr
|
|||
= "webAuthentication";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the config child element for the storage server location
|
||||
* The name of the config child element for the authentication server location
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string locationConfigElementName = "location";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the config element attribute for the storage server name
|
||||
* The name of the config element attribute for the server name
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string locationServerAttrName = "server";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the config element attribute for the storage server port
|
||||
* The name of the config element attribute for the server port
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string locationPortAttrName = "port";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the config element attribute for the storage server php page
|
||||
* The name of the config element attribute for the server php page
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string locationPathAttrName = "path";
|
||||
|
||||
|
@ -89,7 +89,7 @@ static const std::string locationPathAttrName = "path";
|
|||
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ authentication server constants: login */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the login method on the storage server
|
||||
* The name of the login method on the server
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string loginMethodName = "locstor.login";
|
||||
|
||||
|
@ -112,7 +112,7 @@ static const std::string outputSessionIdParamName = "sessid";
|
|||
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ authentication server constants: logout */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the logout method on the storage server
|
||||
* The name of the logout method on the server
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string logoutMethodName = "locstor.logout";
|
||||
|
||||
|
@ -127,6 +127,52 @@ static const std::string inputSessionIdParamName = "sessid";
|
|||
static const std::string statusParamName = "status";
|
||||
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~ authentication server constants: load/save preferences */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the load preferences method on the server
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string loadPreferencesMethodName = "locstor.loadPref";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the save preferences method on the server
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string savePreferencesMethodName = "locstor.savePref";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the session ID parameter in the input structure
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string preferencesSessionIdParamName = "sessid";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the key parameter in the input structure
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string preferencesKeyParamName = "key";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the value parameter for both save and load methods
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string preferencesValueParamName = "value";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the return parameter for the save method
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string preferencesStatusParamName = "status";
|
||||
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~ authentication server constants: resetStorage */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the reset storage method on the server
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string resetStorageMethodName = "locstor.resetStorage";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the result parameter returned by the method (ignored here)
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const std::string resetStorageResultParamName = "gunids";
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
|
@ -202,7 +248,7 @@ WebAuthenticationClient :: configure(const xmlpp::Element & element)
|
|||
Ptr<SessionId>::Ref
|
||||
WebAuthenticationClient :: login(const std::string & login,
|
||||
const std::string & password)
|
||||
throw (AuthenticationException)
|
||||
throw (XmlRpcException)
|
||||
{
|
||||
XmlRpcValue parameters;
|
||||
XmlRpcValue result;
|
||||
|
@ -212,8 +258,8 @@ WebAuthenticationClient :: login(const std::string & login,
|
|||
storageServerPath.c_str(), false);
|
||||
|
||||
parameters.clear();
|
||||
parameters[loginParamName] = login.c_str();
|
||||
parameters[passwordParamName] = password.c_str();
|
||||
parameters[loginParamName] = login;
|
||||
parameters[passwordParamName] = password;
|
||||
|
||||
result.clear();
|
||||
if (!xmlRpcClient.execute(loginMethodName.c_str(), parameters, result)) {
|
||||
|
@ -224,21 +270,21 @@ WebAuthenticationClient :: login(const std::string & login,
|
|||
std::stringstream eMsg;
|
||||
eMsg << "Login method returned fault response:\n"
|
||||
<< result;
|
||||
throw Authentication::XmlRpcMethodFaultException(eMsg.str());
|
||||
throw Core::XmlRpcMethodFaultException(eMsg.str());
|
||||
}
|
||||
|
||||
if (! result.hasMember(outputSessionIdParamName)) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "Login method returned unexpected response:\n"
|
||||
<< result;
|
||||
throw Authentication::XmlRpcMethodResponseException(eMsg.str());
|
||||
throw Core::XmlRpcMethodResponseException(eMsg.str());
|
||||
}
|
||||
|
||||
if (result[outputSessionIdParamName].getType() != XmlRpcValue::TypeString) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "Login method returned unexpected response:\n"
|
||||
<< result;
|
||||
throw Authentication::XmlRpcMethodResponseException(eMsg.str());
|
||||
throw Core::XmlRpcMethodResponseException(eMsg.str());
|
||||
}
|
||||
|
||||
sessionId.reset(new SessionId(result[outputSessionIdParamName]));
|
||||
|
@ -251,8 +297,12 @@ WebAuthenticationClient :: login(const std::string & login,
|
|||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
WebAuthenticationClient :: logout(Ptr<SessionId>::Ref sessionId)
|
||||
throw (AuthenticationException)
|
||||
throw (XmlRpcException)
|
||||
{
|
||||
if (!sessionId) {
|
||||
throw Core::XmlRpcInvalidArgumentException("Missing session ID.");
|
||||
}
|
||||
|
||||
XmlRpcValue parameters;
|
||||
XmlRpcValue result;
|
||||
|
||||
|
@ -260,18 +310,18 @@ WebAuthenticationClient :: logout(Ptr<SessionId>::Ref sessionId)
|
|||
storageServerPath.c_str(), false);
|
||||
|
||||
parameters.clear();
|
||||
parameters[inputSessionIdParamName] = sessionId->getId().c_str();
|
||||
parameters[inputSessionIdParamName] = sessionId->getId();
|
||||
|
||||
result.clear();
|
||||
if (!xmlRpcClient.execute(logoutMethodName.c_str(), parameters, result)) {
|
||||
throw Authentication::XmlRpcCommunicationException("Logout failed.");
|
||||
throw Core::XmlRpcCommunicationException("Logout failed.");
|
||||
}
|
||||
|
||||
if (xmlRpcClient.isFault()) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "Logout method returned fault response:\n"
|
||||
<< result;
|
||||
throw Authentication::XmlRpcMethodFaultException(eMsg.str());
|
||||
throw Core::XmlRpcMethodFaultException(eMsg.str());
|
||||
}
|
||||
|
||||
if (! result.hasMember(statusParamName)
|
||||
|
@ -280,7 +330,169 @@ WebAuthenticationClient :: logout(Ptr<SessionId>::Ref sessionId)
|
|||
std::stringstream eMsg;
|
||||
eMsg << "Logout method returned unexpected response:\n"
|
||||
<< result;
|
||||
throw Authentication::XmlRpcMethodResponseException(eMsg.str());
|
||||
throw Core::XmlRpcMethodResponseException(eMsg.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Load a `user preferences' item from the server.
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<Glib::ustring>::Ref
|
||||
WebAuthenticationClient :: loadPreferencesItem(
|
||||
Ptr<SessionId>::Ref sessionId,
|
||||
const Glib::ustring & key)
|
||||
throw (XmlRpcException)
|
||||
{
|
||||
if (!sessionId) {
|
||||
throw Core::XmlRpcInvalidArgumentException("Missing session ID.");
|
||||
}
|
||||
|
||||
XmlRpcValue parameters;
|
||||
XmlRpcValue result;
|
||||
|
||||
XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort,
|
||||
storageServerPath.c_str(), false);
|
||||
|
||||
parameters.clear();
|
||||
parameters[preferencesSessionIdParamName] = sessionId->getId();
|
||||
parameters[preferencesKeyParamName] = std::string(key);
|
||||
|
||||
result.clear();
|
||||
if (!xmlRpcClient.execute(loadPreferencesMethodName.c_str(),
|
||||
parameters, result)) {
|
||||
throw Core::XmlRpcCommunicationException(
|
||||
"Could not execute XML-RPC method.");
|
||||
}
|
||||
|
||||
if (xmlRpcClient.isFault()) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "XML-RPC method "
|
||||
<< loadPreferencesMethodName
|
||||
<< " returned fault response:\n"
|
||||
<< result;
|
||||
throw Core::XmlRpcMethodFaultException(eMsg.str());
|
||||
}
|
||||
|
||||
if (! result.hasMember(preferencesValueParamName)
|
||||
|| result[preferencesValueParamName].getType()
|
||||
!= XmlRpcValue::TypeString) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "XML-RPC method "
|
||||
<< loadPreferencesMethodName
|
||||
<< " returned unexpected response:\n"
|
||||
<< result;
|
||||
throw Core::XmlRpcMethodResponseException(eMsg.str());
|
||||
}
|
||||
|
||||
Ptr<Glib::ustring>::Ref value(new Glib::ustring(std::string(
|
||||
result[preferencesValueParamName] )));
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Store a `user preferences' item on the server.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
WebAuthenticationClient :: savePreferencesItem(
|
||||
Ptr<SessionId>::Ref sessionId,
|
||||
const Glib::ustring & key,
|
||||
Ptr<const Glib::ustring>::Ref value)
|
||||
throw (XmlRpcException)
|
||||
{
|
||||
if (!sessionId) {
|
||||
throw Core::XmlRpcInvalidArgumentException("Missing session ID.");
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
throw Core::XmlRpcInvalidArgumentException("Missing value argument.");
|
||||
}
|
||||
|
||||
XmlRpcValue parameters;
|
||||
XmlRpcValue result;
|
||||
|
||||
XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort,
|
||||
storageServerPath.c_str(), false);
|
||||
|
||||
parameters.clear();
|
||||
parameters[preferencesSessionIdParamName] = sessionId->getId();
|
||||
parameters[preferencesKeyParamName] = std::string(key);
|
||||
parameters[preferencesValueParamName] = std::string(*value);
|
||||
|
||||
result.clear();
|
||||
if (!xmlRpcClient.execute(savePreferencesMethodName.c_str(),
|
||||
parameters, result)) {
|
||||
throw Core::XmlRpcCommunicationException(
|
||||
"Could not execute XML-RPC method.");
|
||||
}
|
||||
|
||||
if (xmlRpcClient.isFault()) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "XML-RPC method "
|
||||
<< savePreferencesMethodName
|
||||
<< " returned fault response:\n"
|
||||
<< result;
|
||||
throw Core::XmlRpcMethodFaultException(eMsg.str());
|
||||
}
|
||||
|
||||
if (! result.hasMember(preferencesStatusParamName)
|
||||
|| result[preferencesStatusParamName].getType()
|
||||
!= XmlRpcValue::TypeBoolean
|
||||
|| ! bool(result[preferencesStatusParamName])) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "XML-RPC method "
|
||||
<< savePreferencesMethodName
|
||||
<< " returned unexpected response:\n"
|
||||
<< result;
|
||||
throw Core::XmlRpcMethodResponseException(eMsg.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Reset the list of preferences to its initial (empty) state.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
WebAuthenticationClient :: reset(void)
|
||||
throw (Core::XmlRpcException)
|
||||
{
|
||||
XmlRpcValue parameters;
|
||||
XmlRpcValue result;
|
||||
|
||||
XmlRpcClient xmlRpcClient(storageServerName.c_str(), storageServerPort,
|
||||
storageServerPath.c_str(), false);
|
||||
|
||||
parameters.clear();
|
||||
parameters["dummy_param"] = "dummy_value";
|
||||
|
||||
result.clear();
|
||||
if (!xmlRpcClient.execute(resetStorageMethodName.c_str(),
|
||||
parameters, result)) {
|
||||
std::string eMsg = "cannot execute XML-RPC method '";
|
||||
eMsg += resetStorageMethodName;
|
||||
eMsg += "'";
|
||||
throw XmlRpcCommunicationException(eMsg);
|
||||
}
|
||||
|
||||
if (xmlRpcClient.isFault()) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "XML-RPC method '"
|
||||
<< resetStorageMethodName
|
||||
<< "' returned error message:\n"
|
||||
<< result;
|
||||
throw XmlRpcMethodFaultException(eMsg.str());
|
||||
}
|
||||
|
||||
if (! result.hasMember(resetStorageResultParamName)
|
||||
|| result[resetStorageResultParamName].getType()
|
||||
!= XmlRpcValue::TypeArray) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "XML-RPC method '"
|
||||
<< resetStorageMethodName
|
||||
<< "' returned unexpected value:\n"
|
||||
<< result;
|
||||
throw XmlRpcMethodResponseException(eMsg.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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/src/WebAuthenticationClient.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -46,7 +46,6 @@
|
|||
#include "LiveSupport/Core/Configurable.h"
|
||||
#include "LiveSupport/Core/SessionId.h"
|
||||
#include "LiveSupport/Authentication/AuthenticationClientInterface.h"
|
||||
#include "LiveSupport/Authentication/AuthenticationException.h"
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
|
@ -94,7 +93,7 @@ using namespace LiveSupport::Core;
|
|||
* </code></pre>
|
||||
*
|
||||
* @author $Author: fgerlits $
|
||||
* @version $Revision: 1.3 $
|
||||
* @version $Revision: 1.4 $
|
||||
*/
|
||||
class WebAuthenticationClient :
|
||||
virtual public Configurable,
|
||||
|
@ -177,7 +176,7 @@ class WebAuthenticationClient :
|
|||
*/
|
||||
virtual Ptr<SessionId>::Ref
|
||||
login(const std::string &login, const std::string &password)
|
||||
throw (AuthenticationException);
|
||||
throw (XmlRpcException);
|
||||
|
||||
/**
|
||||
* Logout from the authentication server.
|
||||
|
@ -193,8 +192,58 @@ class WebAuthenticationClient :
|
|||
*/
|
||||
virtual void
|
||||
logout(Ptr<SessionId>::Ref sessionId)
|
||||
throw (AuthenticationException);
|
||||
throw (XmlRpcException);
|
||||
|
||||
/**
|
||||
* Load a `user preferences' item from the server.
|
||||
*
|
||||
* @param sessionId the ID of the current session (from login())
|
||||
* @param key the name of the item
|
||||
*
|
||||
* @exception XmlRpcInvalidArgumentException
|
||||
* bad sessionId argument
|
||||
* @exception XmlRpcCommunicationException
|
||||
* problem with performing XML-RPC call
|
||||
* @exception XmlRpcMethodFaultException
|
||||
* XML-RPC method returned fault response
|
||||
* @exception XmlRpcMethodResponseException
|
||||
* response from XML-RPC method is incorrect
|
||||
*/
|
||||
virtual Ptr<Glib::ustring>::Ref
|
||||
loadPreferencesItem(Ptr<SessionId>::Ref sessionId,
|
||||
const Glib::ustring & key)
|
||||
throw (XmlRpcException);
|
||||
|
||||
/**
|
||||
* Store a `user preferences' item on the server.
|
||||
*
|
||||
* @param sessionId the ID of the current session (from login())
|
||||
* @param key the name of the item
|
||||
* @param value the (new) value of the item
|
||||
*
|
||||
* @exception XmlRpcInvalidArgumentException
|
||||
* bad sessionId or value argument
|
||||
* @exception XmlRpcCommunicationException
|
||||
* problem with performing XML-RPC call
|
||||
* @exception XmlRpcMethodFaultException
|
||||
* XML-RPC method returned fault response
|
||||
* @exception XmlRpcMethodResponseException
|
||||
* response from XML-RPC method is incorrect
|
||||
*/
|
||||
virtual void
|
||||
savePreferencesItem(Ptr<SessionId>::Ref sessionId,
|
||||
const Glib::ustring & key,
|
||||
Ptr<const Glib::ustring>::Ref value)
|
||||
throw (XmlRpcException);
|
||||
|
||||
/**
|
||||
* Reset the list of preferences to its initial (empty) state.
|
||||
*
|
||||
* @exception XmlRpcException if the server returns an error.
|
||||
*/
|
||||
void
|
||||
reset(void)
|
||||
throw (XmlRpcException);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.5 $
|
||||
Version : $Revision: 1.6 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/WebAuthenticationClientTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -71,7 +71,7 @@ static const std::string configFileName = "etc/webAuthentication.xml";
|
|||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Set up the test environment
|
||||
* Set up the test environment.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
WebAuthenticationClientTest :: setUp(void) throw ()
|
||||
|
@ -93,7 +93,7 @@ WebAuthenticationClientTest :: setUp(void) throw ()
|
|||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Clean up the test environment
|
||||
* Clean up the test environment.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
WebAuthenticationClientTest :: tearDown(void) throw ()
|
||||
|
@ -103,7 +103,7 @@ WebAuthenticationClientTest :: tearDown(void) throw ()
|
|||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Test to see if we can log on and off
|
||||
* Test to see if we can log on and off.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
WebAuthenticationClientTest :: firstTest(void)
|
||||
|
@ -115,7 +115,7 @@ WebAuthenticationClientTest :: firstTest(void)
|
|||
sessionId = wac->login("Piszkos Fred", "malnaszor");
|
||||
CPPUNIT_FAIL("Allowed login with incorrect login and password.");
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
}
|
||||
|
||||
sessionId.reset(new SessionId("bad_session_ID"));
|
||||
|
@ -123,20 +123,20 @@ WebAuthenticationClientTest :: firstTest(void)
|
|||
wac->logout(sessionId);
|
||||
CPPUNIT_FAIL("Allowed logout without previous login.");
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
}
|
||||
|
||||
try {
|
||||
sessionId = wac->login("root", "q");
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
try {
|
||||
wac->logout(sessionId);
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,103 @@ WebAuthenticationClientTest :: firstTest(void)
|
|||
wac->logout(sessionId);
|
||||
CPPUNIT_FAIL("Allowed to logout twice.");
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Test to see if we can save and load user preferences.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
WebAuthenticationClientTest :: preferencesTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
try {
|
||||
wac->reset();
|
||||
}
|
||||
catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
Ptr<SessionId>::Ref sessionId;
|
||||
Ptr<const Glib::ustring>::Ref prefValue;
|
||||
|
||||
// check "please log in" error
|
||||
try {
|
||||
prefValue = wac->loadPreferencesItem(sessionId, "something");
|
||||
CPPUNIT_FAIL("Allowed operation without login.");
|
||||
} catch (XmlRpcException &e) {
|
||||
}
|
||||
|
||||
// log in
|
||||
try {
|
||||
sessionId = wac->login("root", "q");
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
// check "no such key" error
|
||||
try {
|
||||
prefValue = wac->loadPreferencesItem(sessionId, "eye_color");
|
||||
CPPUNIT_ASSERT(*prefValue == ""); // but I don't think it should be
|
||||
// CPPUNIT_FAIL("Retrieved non-existent user preferences item.");
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what()); // but I don't think it should be
|
||||
}
|
||||
|
||||
// check normal save and load
|
||||
prefValue.reset(new const Glib::ustring("chyornye"));
|
||||
try {
|
||||
wac->savePreferencesItem(sessionId, "eye_color", prefValue);
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
Ptr<const Glib::ustring>::Ref newPrefValue;
|
||||
try {
|
||||
newPrefValue = wac->loadPreferencesItem(sessionId, "eye_color");
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(*newPrefValue == *prefValue);
|
||||
|
||||
// try some unicode characters
|
||||
prefValue.reset(new const Glib::ustring("страстные"));
|
||||
try {
|
||||
wac->savePreferencesItem(sessionId, "eye_color", prefValue);
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
try {
|
||||
newPrefValue = wac->loadPreferencesItem(sessionId, "eye_color");
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(*newPrefValue == "страстные");
|
||||
|
||||
// check another normal save and load
|
||||
prefValue.reset(new const Glib::ustring("ne dobryj"));
|
||||
try {
|
||||
wac->savePreferencesItem(sessionId, "hour", prefValue);
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
try {
|
||||
newPrefValue = wac->loadPreferencesItem(sessionId, "hour");
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(*newPrefValue == *prefValue);
|
||||
|
||||
// and log out
|
||||
try {
|
||||
wac->logout(sessionId);
|
||||
}
|
||||
catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.4 $
|
||||
Version : $Revision: 1.5 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/WebAuthenticationClientTest.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -61,13 +61,14 @@ using namespace LiveSupport::Core;
|
|||
* Unit test for the WebAuthenticationClient class.
|
||||
*
|
||||
* @author $Author: fgerlits $
|
||||
* @version $Revision: 1.4 $
|
||||
* @version $Revision: 1.5 $
|
||||
* @see WebAuthenticationClient
|
||||
*/
|
||||
class WebAuthenticationClientTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(WebAuthenticationClientTest);
|
||||
CPPUNIT_TEST(firstTest);
|
||||
CPPUNIT_TEST(preferencesTest);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
|
@ -86,6 +87,14 @@ class WebAuthenticationClientTest : public CPPUNIT_NS::TestFixture
|
|||
void
|
||||
firstTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
/**
|
||||
* Test saving and load of user preferences.
|
||||
*
|
||||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
void
|
||||
preferencesTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.25 $
|
||||
Version : $Revision: 1.26 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -148,20 +148,20 @@ WebStorageClientTest :: firstTest(void)
|
|||
authentication->logout(sessionId);
|
||||
CPPUNIT_FAIL("allowed logout operation without login");
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
}
|
||||
|
||||
try {
|
||||
sessionId = authentication->login("noSuchUser", "incorrectPassword");
|
||||
CPPUNIT_FAIL("Allowed login with incorrect password.");
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
}
|
||||
|
||||
try {
|
||||
sessionId = authentication->login("root", "q");
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
std::string eMsg = "Login failed.";
|
||||
eMsg += e.what();
|
||||
CPPUNIT_FAIL(eMsg);
|
||||
|
@ -170,7 +170,7 @@ WebStorageClientTest :: firstTest(void)
|
|||
try {
|
||||
authentication->logout(sessionId);
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
std::string eMsg = "Login failed.";
|
||||
eMsg += e.what();
|
||||
CPPUNIT_FAIL(eMsg);
|
||||
|
@ -199,7 +199,7 @@ WebStorageClientTest :: playlistTest(void)
|
|||
try {
|
||||
sessionId = authentication->login("root", "q");
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(sessionId);
|
||||
|
@ -388,7 +388,7 @@ WebStorageClientTest :: audioClipTest(void)
|
|||
try {
|
||||
sessionId = authentication->login("root", "q");
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(sessionId);
|
||||
|
@ -509,7 +509,7 @@ WebStorageClientTest :: audioClipTest(void)
|
|||
try{
|
||||
authentication->logout(sessionId);
|
||||
}
|
||||
catch (AuthenticationException &e) {
|
||||
catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
}
|
||||
|
@ -534,7 +534,7 @@ WebStorageClientTest :: simplePlaylistTest(void)
|
|||
Ptr<SessionId>::Ref sessionId;
|
||||
try {
|
||||
sessionId = authentication->login("root", "q");
|
||||
} catch (AuthenticationException &e) {
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(sessionId);
|
||||
|
|
Loading…
Reference in New Issue