From d1fce4748cd5e43af8e5975287770ee9419d56d3 Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Tue, 5 Feb 2013 14:44:49 +0200 Subject: [PATCH] Invoke the callback when errors occur Fix a bug when the SignonAuthSession::process callback was not being invoked if any error occurred, and add a test case to catch future regressions. --- libsignon-glib/signon-auth-session.c | 8 +++- tests/check_signon.c | 58 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/libsignon-glib/signon-auth-session.c b/libsignon-glib/signon-auth-session.c index 13ec4d9..ce02e75 100644 --- a/libsignon-glib/signon-auth-session.c +++ b/libsignon-glib/signon-auth-session.c @@ -155,13 +155,17 @@ auth_session_process_reply (GObject *object, GAsyncResult *res, g_simple_async_result_set_op_res_gpointer (res_process, reply, (GDestroyNotify) g_variant_unref); - g_simple_async_result_complete (res_process); } else { g_simple_async_result_take_error (res_process, error); } + /* We use the idle variant in order to avoid the following critical + * message: + * g_main_context_pop_thread_default: assertion `g_queue_peek_head (stack) == context' failed + */ + g_simple_async_result_complete_in_idle (res_process); g_object_unref (self); } @@ -180,6 +184,7 @@ auth_session_process_ready_cb (gpointer object, const GError *error, gpointer us { DEBUG ("AuthSessionError: %s", error->message); g_simple_async_result_set_from_error (res, error); + g_simple_async_result_complete (res); return; } @@ -191,6 +196,7 @@ auth_session_process_ready_cb (gpointer object, const GError *error, gpointer us signon_error_quark (), SIGNON_ERROR_SESSION_CANCELED, "Authentication session was canceled"); + g_simple_async_result_complete (res); return; } diff --git a/tests/check_signon.c b/tests/check_signon.c index 70beed5..7e79e2a 100644 --- a/tests/check_signon.c +++ b/tests/check_signon.c @@ -526,6 +526,63 @@ START_TEST(test_auth_session_process) } END_TEST +static void +test_auth_session_process_failure_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + SignonAuthSession *auth_session = SIGNON_AUTH_SESSION (source_object); + GVariant *v_reply; + GError **error = user_data; + + fail_unless (SIGNON_IS_AUTH_SESSION (source_object)); + + v_reply = signon_auth_session_process_finish (auth_session, res, error); + fail_unless (v_reply == NULL); + + g_main_loop_quit (main_loop); +} + +START_TEST(test_auth_session_process_failure) +{ + SignonAuthSession *auth_session; + GVariantBuilder builder; + GVariant *session_data; + GError *error = NULL; + + g_debug("%s", G_STRFUNC); + + g_type_init (); + + auth_session = signon_auth_session_new (0, "nonexisting-method", &error); + fail_unless (auth_session != NULL, "Cannot create AuthSession object"); + fail_unless (error == NULL); + + g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); + g_variant_builder_add (&builder, "{sv}", + "key", g_variant_new_string ("value")); + + session_data = g_variant_builder_end (&builder); + + signon_auth_session_process_async (auth_session, + session_data, + "mech1", + NULL, + test_auth_session_process_failure_cb, + &error); + + main_loop = g_main_loop_new (NULL, FALSE); + g_main_loop_run (main_loop); + fail_unless (error != NULL); + fail_unless (error->domain == SIGNON_ERROR); + fail_unless (error->code == SIGNON_ERROR_METHOD_NOT_KNOWN); + + g_object_unref (auth_session); + + end_test (); +} +END_TEST + static void test_auth_session_process_after_store_cb (SignonAuthSession *self, GHashTable *reply, @@ -1403,6 +1460,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_failure); 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); -- 2.34.1