(AuthenticationClientInterface::loadPreferences() now throws std::invalid_argument if the only problem is "key not found")
This commit is contained in:
fgerlits 2005-05-06 11:36:17 +00:00
parent 753ae360e2
commit 125d6ceb64
9 changed files with 81 additions and 39 deletions

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.9 $
Author : $Author: fgerlits $
Version : $Revision: 1.10 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/include/LiveSupport/Authentication/AuthenticationClientInterface.h,v $
------------------------------------------------------------------------------*/
@ -68,8 +68,8 @@ using namespace LiveSupport::Core;
/**
* An interface for authentication clients.
*
* @author $Author: maroy $
* @version $Revision: 1.9 $
* @author $Author: fgerlits $
* @version $Revision: 1.10 $
*/
class AuthenticationClientInterface
{
@ -135,6 +135,8 @@ class AuthenticationClientInterface
* @param sessionId the ID of the current session (from login())
* @param key the name of the item
*
* @exception std::invalid_argument
* no such preference key found
* @exception XmlRpcInvalidArgumentException
* bad sessionId argument
* @exception XmlRpcCommunicationException
@ -149,7 +151,8 @@ class AuthenticationClientInterface
virtual Ptr<Glib::ustring>::Ref
loadPreferencesItem(Ptr<SessionId>::Ref sessionId,
const Glib::ustring & key)
throw (XmlRpcException)
throw (XmlRpcException,
std::invalid_argument)
= 0;
/**

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.6 $
Author : $Author: fgerlits $
Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/AuthenticationClientFactoryTest.cxx,v $
------------------------------------------------------------------------------*/
@ -165,7 +165,9 @@ AuthenticationClientFactoryTest :: preferencesTest(void)
try {
prefValue = authentication->loadPreferencesItem(sessionId, "eye_color");
CPPUNIT_FAIL("Retrieved non-existent user preferences item.");
} catch (std::invalid_argument &e) {
} catch (XmlRpcException &e) {
CPPUNIT_FAIL(e.what());
}
// check normal save and load
@ -232,7 +234,9 @@ AuthenticationClientFactoryTest :: preferencesTest(void)
try {
newPrefValue = authentication->loadPreferencesItem(sessionId, "hour");
CPPUNIT_FAIL("Allowed to load preference after it was deleted");
} catch (std::invalid_argument &e) {
} catch (XmlRpcException &e) {
CPPUNIT_FAIL(e.what());
}
// and log out

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.7 $
Author : $Author: fgerlits $
Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/TestAuthenticationClient.cxx,v $
------------------------------------------------------------------------------*/
@ -215,7 +215,8 @@ Ptr<Glib::ustring>::Ref
TestAuthenticationClient :: loadPreferencesItem(
Ptr<SessionId>::Ref sessionId,
const Glib::ustring & key)
throw (XmlRpcException)
throw (XmlRpcException,
std::invalid_argument)
{
if (!sessionId
|| sessionIdList.find(sessionId->getId()) == sessionIdList.end()) {
@ -225,10 +226,10 @@ TestAuthenticationClient :: loadPreferencesItem(
PreferencesType::iterator it;
if ((it = preferences.find(key)) == preferences.end()) {
throw XmlRpcException("no such user preferences item");
throw std::invalid_argument("no such user preferences item");
}
Ptr<Glib::ustring>::Ref value(new Glib::ustring(*it->second));
return value;
}

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.10 $
Author : $Author: fgerlits $
Version : $Revision: 1.11 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/TestAuthenticationClient.h,v $
------------------------------------------------------------------------------*/
@ -94,8 +94,8 @@ using namespace LiveSupport::Core;
* &lt;!ATTLIST user password CDATA #REQUIRED &gt;
* </code></pre>
*
* @author $Author: maroy $
* @version $Revision: 1.10 $
* @author $Author: fgerlits $
* @version $Revision: 1.11 $
*/
class TestAuthenticationClient :
virtual public Configurable,
@ -227,13 +227,14 @@ class TestAuthenticationClient :
*
* @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
* @exception XmlRpcException invalid session ID
* @exception std::invalid_argument no such preference key found
*/
virtual Ptr<Glib::ustring>::Ref
loadPreferencesItem(Ptr<SessionId>::Ref sessionId,
const Glib::ustring & key)
throw (XmlRpcException);
throw (XmlRpcException,
std::invalid_argument);
/**
* Store a `user preferences' item on the server.

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.8 $
Author : $Author: fgerlits $
Version : $Revision: 1.9 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/TestAuthenticationClientTest.cxx,v $
------------------------------------------------------------------------------*/
@ -193,7 +193,9 @@ TestAuthenticationClientTest :: preferencesTest(void)
try {
prefValue = tac->loadPreferencesItem(sessionId, "eye_color");
CPPUNIT_FAIL("Retrieved non-existent user preferences item.");
} catch (std::invalid_argument &e) {
} catch (XmlRpcException &e) {
CPPUNIT_FAIL(e.what());
}
// check normal save and load
@ -260,7 +262,9 @@ TestAuthenticationClientTest :: preferencesTest(void)
try {
newPrefValue = tac->loadPreferencesItem(sessionId, "hour");
CPPUNIT_FAIL("Allowed to load preference after it was deleted");
} catch (std::invalid_argument &e) {
} catch (XmlRpcException &e) {
CPPUNIT_FAIL(e.what());
}
// and log out

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.11 $
Author : $Author: fgerlits $
Version : $Revision: 1.12 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/WebAuthenticationClient.cxx,v $
------------------------------------------------------------------------------*/
@ -174,6 +174,16 @@ static const std::string preferencesValueParamName = "value";
*----------------------------------------------------------------------------*/
static const std::string preferencesStatusParamName = "status";
/*------------------------------------------------------------------------------
* The name of the fault code parameter
*----------------------------------------------------------------------------*/
static const std::string faultCodeParamName = "faultCode";
/*------------------------------------------------------------------------------
* The fault code for the "invalid preference key" error
*----------------------------------------------------------------------------*/
static const int invalidPreferenceKeyFaultCode = 849;
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~ authentication server constants: resetStorage */
@ -423,7 +433,8 @@ Ptr<Glib::ustring>::Ref
WebAuthenticationClient :: loadPreferencesItem(
Ptr<SessionId>::Ref sessionId,
const Glib::ustring & key)
throw (XmlRpcException)
throw (XmlRpcException,
std::invalid_argument)
{
if (!sessionId) {
throw Core::XmlRpcInvalidArgumentException("Missing session ID.");
@ -447,14 +458,22 @@ WebAuthenticationClient :: loadPreferencesItem(
"Could not execute XML-RPC method.");
}
xmlRpcClient.close();
if (xmlRpcClient.isFault()) {
std::stringstream eMsg;
eMsg << "XML-RPC method "
<< loadPreferencesMethodName
<< " returned fault response:\n"
<< result;
throw Core::XmlRpcMethodFaultException(eMsg.str());
<< loadPreferencesMethodName
<< " returned fault response:\n"
<< result;
if (result.hasMember(faultCodeParamName)
&& result[faultCodeParamName].getType()
== XmlRpcValue::TypeInt
&& int(result[faultCodeParamName])
== invalidPreferenceKeyFaultCode) {
throw std::invalid_argument(eMsg.str());
} else {
throw Core::XmlRpcMethodFaultException(eMsg.str());
}
}
if (! result.hasMember(preferencesValueParamName)

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.7 $
Author : $Author: fgerlits $
Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/WebAuthenticationClient.h,v $
------------------------------------------------------------------------------*/
@ -92,8 +92,8 @@ using namespace LiveSupport::Core;
* &lt;!ATTLIST location path CDATA #REQUIRED &gt;
* </code></pre>
*
* @author $Author: maroy $
* @version $Revision: 1.7 $
* @author $Author: fgerlits $
* @version $Revision: 1.8 $
*/
class WebAuthenticationClient :
virtual public Configurable,
@ -212,6 +212,8 @@ class WebAuthenticationClient :
* @param sessionId the ID of the current session (from login())
* @param key the name of the item
*
* @exception std::invalid_argument
* no such preference key found
* @exception XmlRpcInvalidArgumentException
* bad sessionId argument
* @exception XmlRpcCommunicationException
@ -224,7 +226,8 @@ class WebAuthenticationClient :
virtual Ptr<Glib::ustring>::Ref
loadPreferencesItem(Ptr<SessionId>::Ref sessionId,
const Glib::ustring & key)
throw (XmlRpcException);
throw (XmlRpcException,
std::invalid_argument);
/**
* Store a `user preferences' item on the server.

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.11 $
Author : $Author: fgerlits $
Version : $Revision: 1.12 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/WebAuthenticationClientTest.cxx,v $
------------------------------------------------------------------------------*/
@ -196,8 +196,10 @@ WebAuthenticationClientTest :: preferencesTest(void)
// check "no such key" error
try {
prefValue = wac->loadPreferencesItem(sessionId, "eye_color");
CPPUNIT_FAIL("Retrieved non-existent user preferences item.");
CPPUNIT_FAIL("Retrieved non-existent user preferences item");
} catch (std::invalid_argument &e) {
} catch (XmlRpcException &e) {
CPPUNIT_FAIL(e.what());
}
// check normal save and load
@ -264,7 +266,9 @@ WebAuthenticationClientTest :: preferencesTest(void)
try {
newPrefValue = wac->loadPreferencesItem(sessionId, "hour");
CPPUNIT_FAIL("Allowed to load preference after it was deleted");
} catch (std::invalid_argument &e) {
} catch (XmlRpcException &e) {
CPPUNIT_FAIL(e.what());
}
// and log out

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.37 $
Version : $Revision: 1.38 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.cxx,v $
------------------------------------------------------------------------------*/
@ -467,8 +467,11 @@ GLiveSupport :: loadScratchpadContents(void) throw ()
std::cerr << "error loading user preferences: " << e.what()
<< std::endl;
return;
} catch (std::invalid_argument &e) {
// no scratchpad stored for this user yet; no problem
return;
}
// just store this as a space-delimited list of ids
std::istringstream prefsString(prefsUstring->raw());
Ptr<Playable>::Ref playable;