From 125d6ceb64c732968fab6440554f9accbf9a9015 Mon Sep 17 00:00:00 2001 From: fgerlits Date: Fri, 6 May 2005 11:36:17 +0000 Subject: [PATCH] fixed bug #916 (AuthenticationClientInterface::loadPreferences() now throws std::invalid_argument if the only problem is "key not found") --- .../AuthenticationClientInterface.h | 13 ++++--- .../src/AuthenticationClientFactoryTest.cxx | 8 +++-- .../src/TestAuthenticationClient.cxx | 11 +++--- .../src/TestAuthenticationClient.h | 15 ++++---- .../src/TestAuthenticationClientTest.cxx | 8 +++-- .../src/WebAuthenticationClient.cxx | 35 ++++++++++++++----- .../src/WebAuthenticationClient.h | 13 ++++--- .../src/WebAuthenticationClientTest.cxx | 10 ++++-- .../gLiveSupport/src/GLiveSupport.cxx | 7 ++-- 9 files changed, 81 insertions(+), 39 deletions(-) diff --git a/livesupport/modules/authentication/include/LiveSupport/Authentication/AuthenticationClientInterface.h b/livesupport/modules/authentication/include/LiveSupport/Authentication/AuthenticationClientInterface.h index 645cb067a..c7601d280 100644 --- a/livesupport/modules/authentication/include/LiveSupport/Authentication/AuthenticationClientInterface.h +++ b/livesupport/modules/authentication/include/LiveSupport/Authentication/AuthenticationClientInterface.h @@ -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::Ref loadPreferencesItem(Ptr::Ref sessionId, const Glib::ustring & key) - throw (XmlRpcException) + throw (XmlRpcException, + std::invalid_argument) = 0; /** diff --git a/livesupport/modules/authentication/src/AuthenticationClientFactoryTest.cxx b/livesupport/modules/authentication/src/AuthenticationClientFactoryTest.cxx index 56740b840..792113782 100644 --- a/livesupport/modules/authentication/src/AuthenticationClientFactoryTest.cxx +++ b/livesupport/modules/authentication/src/AuthenticationClientFactoryTest.cxx @@ -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 diff --git a/livesupport/modules/authentication/src/TestAuthenticationClient.cxx b/livesupport/modules/authentication/src/TestAuthenticationClient.cxx index e1d92de16..4ac874d4b 100644 --- a/livesupport/modules/authentication/src/TestAuthenticationClient.cxx +++ b/livesupport/modules/authentication/src/TestAuthenticationClient.cxx @@ -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::Ref TestAuthenticationClient :: loadPreferencesItem( Ptr::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::Ref value(new Glib::ustring(*it->second)); - return value; } diff --git a/livesupport/modules/authentication/src/TestAuthenticationClient.h b/livesupport/modules/authentication/src/TestAuthenticationClient.h index ecc3e89a3..605a1c71c 100644 --- a/livesupport/modules/authentication/src/TestAuthenticationClient.h +++ b/livesupport/modules/authentication/src/TestAuthenticationClient.h @@ -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; * <!ATTLIST user password CDATA #REQUIRED > * * - * @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::Ref loadPreferencesItem(Ptr::Ref sessionId, const Glib::ustring & key) - throw (XmlRpcException); + throw (XmlRpcException, + std::invalid_argument); /** * Store a `user preferences' item on the server. diff --git a/livesupport/modules/authentication/src/TestAuthenticationClientTest.cxx b/livesupport/modules/authentication/src/TestAuthenticationClientTest.cxx index 29b12a2d9..837aab5eb 100644 --- a/livesupport/modules/authentication/src/TestAuthenticationClientTest.cxx +++ b/livesupport/modules/authentication/src/TestAuthenticationClientTest.cxx @@ -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 diff --git a/livesupport/modules/authentication/src/WebAuthenticationClient.cxx b/livesupport/modules/authentication/src/WebAuthenticationClient.cxx index 5ebc26197..f8535f8e1 100644 --- a/livesupport/modules/authentication/src/WebAuthenticationClient.cxx +++ b/livesupport/modules/authentication/src/WebAuthenticationClient.cxx @@ -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::Ref WebAuthenticationClient :: loadPreferencesItem( Ptr::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) diff --git a/livesupport/modules/authentication/src/WebAuthenticationClient.h b/livesupport/modules/authentication/src/WebAuthenticationClient.h index a0d6382c4..5a6ea5478 100644 --- a/livesupport/modules/authentication/src/WebAuthenticationClient.h +++ b/livesupport/modules/authentication/src/WebAuthenticationClient.h @@ -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; * <!ATTLIST location path CDATA #REQUIRED > * * - * @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::Ref loadPreferencesItem(Ptr::Ref sessionId, const Glib::ustring & key) - throw (XmlRpcException); + throw (XmlRpcException, + std::invalid_argument); /** * Store a `user preferences' item on the server. diff --git a/livesupport/modules/authentication/src/WebAuthenticationClientTest.cxx b/livesupport/modules/authentication/src/WebAuthenticationClientTest.cxx index e3e82ab7c..c96beb928 100644 --- a/livesupport/modules/authentication/src/WebAuthenticationClientTest.cxx +++ b/livesupport/modules/authentication/src/WebAuthenticationClientTest.cxx @@ -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 diff --git a/livesupport/products/gLiveSupport/src/GLiveSupport.cxx b/livesupport/products/gLiveSupport/src/GLiveSupport.cxx index 803a159f9..3898b92ba 100644 --- a/livesupport/products/gLiveSupport/src/GLiveSupport.cxx +++ b/livesupport/products/gLiveSupport/src/GLiveSupport.cxx @@ -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::Ref playable;