From e0c6120457b6ccf920a6974ce42ececc67468463 Mon Sep 17 00:00:00 2001 From: Jussi Laako Date: Thu, 23 May 2013 18:13:35 +0300 Subject: [PATCH] Update and fix queryIdentities method and add test case for it --- ....AccountsSSO.gSingleSignOn.AuthService.xml | 3 +- libsignon-glib/signon-auth-service.c | 26 ++++++---- libsignon-glib/signon-auth-service.h | 9 ++-- tests/check_signon.c | 49 +++++++++++++++++++ 4 files changed, 73 insertions(+), 14 deletions(-) diff --git a/libsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthService.xml b/libsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthService.xml index 7d85456..9fc893c 100644 --- a/libsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthService.xml +++ b/libsignon-glib/interfaces/com.google.code.AccountsSSO.gSingleSignOn.AuthService.xml @@ -19,8 +19,9 @@ - + + diff --git a/libsignon-glib/signon-auth-service.c b/libsignon-glib/signon-auth-service.c index 599080c..bfa171d 100644 --- a/libsignon-glib/signon-auth-service.c +++ b/libsignon-glib/signon-auth-service.c @@ -276,7 +276,7 @@ auth_query_identities_cb (GObject *object, GAsyncResult *res, GError *error = NULL; GVariantIter iter; GVariant *identity_var; - IdentityList *identity_list; + SignonIdentityList *identity_list = NULL; g_return_if_fail (data != NULL); @@ -285,14 +285,16 @@ auth_query_identities_cb (GObject *object, GAsyncResult *res, res, &error); - identity_list = g_list_alloc (); - g_variant_iter_init (&iter, value); - while (g_variant_iter_next (&iter, "@a{sv}", &identity_var)) + if (value && !error) { - identity_list = - g_list_append (identity_list, - signon_identity_info_new_from_variant (identity_var)); - g_variant_unref (identity_var); + g_variant_iter_init (&iter, value); + while (g_variant_iter_next (&iter, "@a{sv}", &identity_var)) + { + identity_list = + g_list_append (identity_list, + signon_identity_info_new_from_variant (identity_var)); + g_variant_unref (identity_var); + } } (data->cb) (data->service, identity_list, error, data->userdata); @@ -315,12 +317,14 @@ auth_query_identities_cb (GObject *object, GAsyncResult *res, * signon_auth_service_query_identities: * @auth_service: the #SignonAuthService. * @filter: filter variant dictionary based on #GHashTable. + * @application_context: application security context, can be %NULL. * @cb: (scope async): callback to be invoked. * @user_data: user data. */ void signon_auth_service_query_identities (SignonAuthService *auth_service, - IdentityFilter *filter, + SignonIdentityFilter *filter, + const gchar *application_context, SignonQueryIdentitiesCb cb, gpointer user_data) { @@ -352,8 +356,12 @@ signon_auth_service_query_identities (SignonAuthService *auth_service, } filter_var = g_variant_builder_end (&builder); + if (!application_context) + application_context = ""; + sso_auth_service_call_query_identities (priv->proxy, filter_var, + application_context, priv->cancellable, auth_query_identities_cb, cb_data); diff --git a/libsignon-glib/signon-auth-service.h b/libsignon-glib/signon-auth-service.h index 47a061b..8c68aad 100644 --- a/libsignon-glib/signon-auth-service.h +++ b/libsignon-glib/signon-auth-service.h @@ -74,11 +74,11 @@ typedef void (*SignonQueryMechanismCb) (SignonAuthService *auth_service, const GError *error, gpointer user_data); -typedef GList IdentityList; -typedef GHashTable IdentityFilter; +typedef GList SignonIdentityList; +typedef GHashTable SignonIdentityFilter; typedef void (*SignonQueryIdentitiesCb) (SignonAuthService *auth_service, - IdentityList *identities, + SignonIdentityList *identities, const GError *error, gpointer user_data); @@ -94,7 +94,8 @@ void signon_auth_service_query_mechanisms (SignonAuthService *auth_service, gpointer user_data); void signon_auth_service_query_identities (SignonAuthService *auth_service, - IdentityFilter *filter, + SignonIdentityFilter *filter, + const gchar *application_context, SignonQueryIdentitiesCb cb, gpointer user_data); diff --git a/tests/check_signon.c b/tests/check_signon.c index 6df9cf7..dc11236 100644 --- a/tests/check_signon.c +++ b/tests/check_signon.c @@ -1332,6 +1332,53 @@ START_TEST(test_unregistered_auth_session) } END_TEST +void free_identity_info_cb (gpointer data) +{ + SignonIdentityInfo *info; + + signon_identity_info_free (info); +} + +void query_identities_cb (SignonAuthService *auth_service, + SignonIdentityList *identity_list, const GError *error, gpointer user_data) +{ + SignonIdentityList *iter = identity_list; + + while (iter && !error) + { + SignonIdentityInfo *info = (SignonIdentityInfo *) iter->data; + const gchar *caption = signon_identity_info_get_caption (info); + + g_print ("\tid=%d caption='%s'\n", + signon_identity_info_get_id (info), + caption); + + fail_unless (g_strcmp0 (caption, "MI-6") == 0, + "Wrong caption in identity"); + + iter = g_list_next (iter); + } + g_list_free_full (identity_list, free_identity_info_cb); + + fail_unless (error == NULL, "There should be no error in callback"); + _stop_mainloop (); +} + +START_TEST(test_query_identities) +{ + g_debug("%s", G_STRFUNC); + + SignonAuthService *asrv = signon_auth_service_new (); + + signon_auth_service_query_identities (asrv, NULL, NULL, query_identities_cb, NULL); + + g_timeout_add_seconds (5, test_quit_main_loop_cb, main_loop); + _run_mainloop (); + + g_object_unref (asrv); +} +END_TEST + static void test_regression_unref_process_cb (SignonAuthSession *self, GHashTable *reply, @@ -1435,6 +1482,8 @@ signon_suite(void) tcase_add_test (tc_core, test_remove_identity); tcase_add_test (tc_core, test_info_identity); + tcase_add_test (tc_core, test_query_identities); + tcase_add_test (tc_core, test_signout_identity); tcase_add_test (tc_core, test_unregistered_identity); tcase_add_test (tc_core, test_unregistered_auth_session); -- 2.34.1