From: Alberto Mardegan Date: Thu, 22 Nov 2012 10:48:21 +0000 (+0200) Subject: Set ID before invoking the client callback X-Git-Tag: 1.8~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=484d663c6665c7d71d583fca9e385ce4077c42cf;p=platform%2Fupstream%2Flibgsignon-glib.git Set ID before invoking the client callback This change makes SignonIdentity process the results from store_credentials() before invoking the client callback. This is important because otherwise any SignonAuthSession created by the client from within the callback would not be bound to the identity. Also, add a unit test to catch any regressions. Fixes: http://code.google.com/p/accounts-sso/issues/detail?id=132 --- diff --git a/libsignon-glib/signon-identity.c b/libsignon-glib/signon-identity.c index b30ca12..cdf7dca 100644 --- a/libsignon-glib/signon-identity.c +++ b/libsignon-glib/signon-identity.c @@ -817,11 +817,6 @@ identity_store_credentials_reply (GObject *object, GAsyncResult *res, sso_identity_call_store_finish (proxy, &id, res, &error); SIGNON_RETURN_IF_CANCELLED (error); - if (cb_data->cb) - { - (cb_data->cb) (cb_data->self, id, error, cb_data->user_data); - } - if (error == NULL) { g_return_if_fail (priv->identity_info == NULL); @@ -845,6 +840,11 @@ identity_store_credentials_reply (GObject *object, GAsyncResult *res, priv->removed = FALSE; } + if (cb_data->cb) + { + (cb_data->cb) (cb_data->self, id, error, cb_data->user_data); + } + g_clear_error(&error); g_slice_free (IdentityStoreCredentialsCbData, cb_data); } diff --git a/tests/check_signon.c b/tests/check_signon.c index a8284ff..957db3d 100644 --- a/tests/check_signon.c +++ b/tests/check_signon.c @@ -522,6 +522,104 @@ START_TEST(test_auth_session_process) } END_TEST +static void +test_auth_session_process_after_store_cb (SignonAuthSession *self, + GHashTable *reply, + const GError *error, + gpointer user_data) +{ + GValue *v_username; + + if (error != NULL) + { + fail("Got error: %s", error->message); + g_main_loop_quit (main_loop); + return; + } + + fail_unless (reply != NULL, "The result is empty"); + + v_username = g_hash_table_lookup(reply, + SIGNON_SESSION_DATA_USERNAME); + + fail_unless (g_strcmp0 (g_value_get_string (v_username), "Nice user") == 0, + "Wrong value of username"); + + g_hash_table_unref (reply); + g_object_unref (self); + + g_main_loop_quit (main_loop); +} + +static void +test_auth_session_process_after_store_start_session(SignonIdentity *self, + guint32 id, + const GError *error, + gpointer user_data) +{ + GError *err = NULL; + + if (error != NULL) + { + g_warning ("%s %d: %s", G_STRFUNC, __LINE__, error->message); + fail(); + g_main_loop_quit (main_loop); + return; + } + + fail_unless (id > 0); + + SignonAuthSession *auth_session = + signon_identity_create_session (self, + "ssotest", + &err); + + fail_unless (auth_session != NULL, "Cannot create AuthSession object"); + if (err != NULL) + { + fail ("Got error: %s", err->message); + g_clear_error (&err); + } + + GHashTable *session_data = g_hash_table_new (g_str_hash, + g_str_equal); + + signon_auth_session_process (auth_session, + session_data, + "mech1", + test_auth_session_process_after_store_cb, + NULL); +} + +START_TEST(test_auth_session_process_after_store) +{ + SignonIdentityInfo *info; + SignonIdentity *identity; + + g_debug("%s", G_STRFUNC); + + g_type_init(); + main_loop = g_main_loop_new (NULL, FALSE); + + identity = signon_identity_new (); + fail_unless (SIGNON_IS_IDENTITY (identity), + "Failed to initialize the Identity."); + + info = signon_identity_info_new (); + signon_identity_info_set_username (info, "Nice user"); + + signon_identity_store_credentials_with_info (identity, + info, + test_auth_session_process_after_store_start_session, + NULL); + g_main_loop_run (main_loop); + + g_object_unref (identity); + + end_test (); +} +END_TEST + static GHashTable *create_methods_hashtable() { gchar *mechanisms[] = { @@ -1297,6 +1395,7 @@ signon_suite(void) tcase_add_test (tc_core, test_auth_session_query_mechanisms); tcase_add_test (tc_core, test_auth_session_query_mechanisms_nonexisting); tcase_add_test (tc_core, test_auth_session_process); + tcase_add_test (tc_core, test_auth_session_process_after_store); tcase_add_test (tc_core, test_store_credentials_identity); tcase_add_test (tc_core, test_verify_secret_identity); tcase_add_test (tc_core, test_remove_identity);