Invoke the callback when errors occur
authorAlberto Mardegan <alberto.mardegan@canonical.com>
Tue, 5 Feb 2013 12:44:49 +0000 (14:44 +0200)
committerAlberto Mardegan <alberto.mardegan@canonical.com>
Tue, 5 Feb 2013 14:23:39 +0000 (16:23 +0200)
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
tests/check_signon.c

index 13ec4d9711a30c24e2268d29fc32d2fddbb97ef3..ce02e75ba51dd5e2da46adb1a9ee1c97f4ccab81 100644 (file)
@@ -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;
     }
 
index 70beed525810a16f235a296022ed2b4d42d75e15..7e79e2afc1d7a45152baf766672524122b22ca96 100644 (file)
@@ -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);