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

View file

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

View file

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

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $ Author : $Author: fgerlits $
Version : $Revision: 1.10 $ Version : $Revision: 1.11 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/TestAuthenticationClient.h,v $ 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; * &lt;!ATTLIST user password CDATA #REQUIRED &gt;
* </code></pre> * </code></pre>
* *
* @author $Author: maroy $ * @author $Author: fgerlits $
* @version $Revision: 1.10 $ * @version $Revision: 1.11 $
*/ */
class TestAuthenticationClient : class TestAuthenticationClient :
virtual public Configurable, virtual public Configurable,
@ -227,13 +227,14 @@ class TestAuthenticationClient :
* *
* @param sessionId the ID of the current session (from login()) * @param sessionId the ID of the current session (from login())
* @param key the name of the item * @param key the name of the item
* @exception XmlRpcException invalid session ID * @exception XmlRpcException invalid session ID
* or key does not match anything stored * @exception std::invalid_argument no such preference key found
*/ */
virtual Ptr<Glib::ustring>::Ref virtual Ptr<Glib::ustring>::Ref
loadPreferencesItem(Ptr<SessionId>::Ref sessionId, loadPreferencesItem(Ptr<SessionId>::Ref sessionId,
const Glib::ustring & key) const Glib::ustring & key)
throw (XmlRpcException); throw (XmlRpcException,
std::invalid_argument);
/** /**
* Store a `user preferences' item on the server. * 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 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $ Author : $Author: fgerlits $
Version : $Revision: 1.8 $ Version : $Revision: 1.9 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/TestAuthenticationClientTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/TestAuthenticationClientTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -193,7 +193,9 @@ TestAuthenticationClientTest :: preferencesTest(void)
try { try {
prefValue = tac->loadPreferencesItem(sessionId, "eye_color"); prefValue = tac->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) { } catch (XmlRpcException &e) {
CPPUNIT_FAIL(e.what());
} }
// check normal save and load // check normal save and load
@ -260,7 +262,9 @@ TestAuthenticationClientTest :: preferencesTest(void)
try { try {
newPrefValue = tac->loadPreferencesItem(sessionId, "hour"); newPrefValue = tac->loadPreferencesItem(sessionId, "hour");
CPPUNIT_FAIL("Allowed to load preference after it was deleted"); CPPUNIT_FAIL("Allowed to load preference after it was deleted");
} catch (std::invalid_argument &e) {
} catch (XmlRpcException &e) { } catch (XmlRpcException &e) {
CPPUNIT_FAIL(e.what());
} }
// and log out // and log out

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $ Author : $Author: fgerlits $
Version : $Revision: 1.11 $ Version : $Revision: 1.12 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/WebAuthenticationClient.cxx,v $ 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"; 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 */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~ authentication server constants: resetStorage */
@ -423,7 +433,8 @@ Ptr<Glib::ustring>::Ref
WebAuthenticationClient :: loadPreferencesItem( WebAuthenticationClient :: loadPreferencesItem(
Ptr<SessionId>::Ref sessionId, Ptr<SessionId>::Ref sessionId,
const Glib::ustring & key) const Glib::ustring & key)
throw (XmlRpcException) throw (XmlRpcException,
std::invalid_argument)
{ {
if (!sessionId) { if (!sessionId) {
throw Core::XmlRpcInvalidArgumentException("Missing session ID."); throw Core::XmlRpcInvalidArgumentException("Missing session ID.");
@ -447,14 +458,22 @@ WebAuthenticationClient :: loadPreferencesItem(
"Could not execute XML-RPC method."); "Could not execute XML-RPC method.");
} }
xmlRpcClient.close(); xmlRpcClient.close();
if (xmlRpcClient.isFault()) { if (xmlRpcClient.isFault()) {
std::stringstream eMsg; std::stringstream eMsg;
eMsg << "XML-RPC method " eMsg << "XML-RPC method "
<< loadPreferencesMethodName << loadPreferencesMethodName
<< " returned fault response:\n" << " returned fault response:\n"
<< result; << result;
throw Core::XmlRpcMethodFaultException(eMsg.str()); 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) if (! result.hasMember(preferencesValueParamName)

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $ Author : $Author: fgerlits $
Version : $Revision: 1.7 $ Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/WebAuthenticationClient.h,v $ 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; * &lt;!ATTLIST location path CDATA #REQUIRED &gt;
* </code></pre> * </code></pre>
* *
* @author $Author: maroy $ * @author $Author: fgerlits $
* @version $Revision: 1.7 $ * @version $Revision: 1.8 $
*/ */
class WebAuthenticationClient : class WebAuthenticationClient :
virtual public Configurable, virtual public Configurable,
@ -212,6 +212,8 @@ class WebAuthenticationClient :
* @param sessionId the ID of the current session (from login()) * @param sessionId the ID of the current session (from login())
* @param key the name of the item * @param key the name of the item
* *
* @exception std::invalid_argument
* no such preference key found
* @exception XmlRpcInvalidArgumentException * @exception XmlRpcInvalidArgumentException
* bad sessionId argument * bad sessionId argument
* @exception XmlRpcCommunicationException * @exception XmlRpcCommunicationException
@ -224,7 +226,8 @@ class WebAuthenticationClient :
virtual Ptr<Glib::ustring>::Ref virtual Ptr<Glib::ustring>::Ref
loadPreferencesItem(Ptr<SessionId>::Ref sessionId, loadPreferencesItem(Ptr<SessionId>::Ref sessionId,
const Glib::ustring & key) const Glib::ustring & key)
throw (XmlRpcException); throw (XmlRpcException,
std::invalid_argument);
/** /**
* Store a `user preferences' item on the server. * 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 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $ Author : $Author: fgerlits $
Version : $Revision: 1.11 $ Version : $Revision: 1.12 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/authentication/src/WebAuthenticationClientTest.cxx,v $ 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 // check "no such key" error
try { try {
prefValue = wac->loadPreferencesItem(sessionId, "eye_color"); 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) { } catch (XmlRpcException &e) {
CPPUNIT_FAIL(e.what());
} }
// check normal save and load // check normal save and load
@ -264,7 +266,9 @@ WebAuthenticationClientTest :: preferencesTest(void)
try { try {
newPrefValue = wac->loadPreferencesItem(sessionId, "hour"); newPrefValue = wac->loadPreferencesItem(sessionId, "hour");
CPPUNIT_FAIL("Allowed to load preference after it was deleted"); CPPUNIT_FAIL("Allowed to load preference after it was deleted");
} catch (std::invalid_argument &e) {
} catch (XmlRpcException &e) { } catch (XmlRpcException &e) {
CPPUNIT_FAIL(e.what());
} }
// and log out // and log out

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ 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 $ 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::cerr << "error loading user preferences: " << e.what()
<< std::endl; << std::endl;
return; 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 // just store this as a space-delimited list of ids
std::istringstream prefsString(prefsUstring->raw()); std::istringstream prefsString(prefsUstring->raw());
Ptr<Playable>::Ref playable; Ptr<Playable>::Ref playable;