[glib] GDBus: Add test case for the ANONYMOUS authentication method
- From: David Zeuthen <davidz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GDBus: Add test case for the ANONYMOUS authentication method
- Date: Wed, 13 Apr 2011 22:23:53 +0000 (UTC)
commit 3b997d92c13217db78fcc774bff6d6c0fcd919e6
Author: David Zeuthen <davidz redhat com>
Date: Wed Apr 13 18:21:16 2011 -0400
GDBus: Add test case for the ANONYMOUS authentication method
Signed-off-by: David Zeuthen <davidz redhat com>
gio/tests/gdbus-peer.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 92 insertions(+), 0 deletions(-)
---
diff --git a/gio/tests/gdbus-peer.c b/gio/tests/gdbus-peer.c
index e304618..b6a9b67 100644
--- a/gio/tests/gdbus-peer.c
+++ b/gio/tests/gdbus-peer.c
@@ -1438,6 +1438,97 @@ test_overflow (void)
/* ---------------------------------------------------------------------------------------------------- */
+#ifdef BUG_631379_FIXED
+static gboolean
+tcp_anonymous_on_new_connection (GDBusServer *server,
+ GDBusConnection *connection,
+ gpointer user_data)
+{
+ gboolean *seen_connection = user_data;
+ *seen_connection = TRUE;
+ return TRUE;
+}
+
+static gpointer
+tcp_anonymous_service_thread_func (gpointer user_data)
+{
+ gboolean *seen_connection = user_data;
+ GMainContext *service_context;
+ GError *error;
+
+ service_context = g_main_context_new ();
+ g_main_context_push_thread_default (service_context);
+
+ error = NULL;
+ server = g_dbus_server_new_sync ("tcp:",
+ G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS,
+ test_guid,
+ NULL, /* GDBusObserver* */
+ NULL, /* GCancellable* */
+ &error);
+ g_assert_no_error (error);
+
+ g_signal_connect (server,
+ "new-connection",
+ G_CALLBACK (tcp_anonymous_on_new_connection),
+ seen_connection);
+
+ g_dbus_server_start (server);
+
+ service_loop = g_main_loop_new (service_context, FALSE);
+ g_main_loop_run (service_loop);
+
+ g_main_context_pop_thread_default (service_context);
+
+ g_main_loop_unref (service_loop);
+ g_main_context_unref (service_context);
+
+ return NULL;
+}
+
+static void
+test_tcp_anonymous (void)
+{
+ gboolean seen_connection;
+ GThread *service_thread;
+ GDBusConnection *connection;
+ GError *error;
+
+ seen_connection = FALSE;
+ service_loop = NULL;
+ service_thread = g_thread_create (tcp_anonymous_service_thread_func,
+ &seen_connection, /* user_data */
+ TRUE, /* joinable */
+ &error);
+ while (service_loop == NULL)
+ g_thread_yield ();
+ g_assert (server != NULL);
+
+ error = NULL;
+ connection = g_dbus_connection_new_for_address_sync (g_dbus_server_get_client_address (server),
+ G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
+ NULL, /* GDBusAuthObserver* */
+ NULL, /* GCancellable */
+ &error);
+ g_assert_no_error (error);
+ g_assert (connection != NULL);
+
+ while (!seen_connection)
+ g_thread_yield ();
+
+ g_object_unref (connection);
+
+ g_main_loop_quit (service_loop);
+ g_dbus_server_stop (server);
+ g_object_unref (server);
+ server = NULL;
+
+ g_thread_join (service_thread);
+}
+#endif
+
+/* ---------------------------------------------------------------------------------------------------- */
+
int
main (int argc,
char *argv[])
@@ -1462,6 +1553,7 @@ main (int argc,
g_test_add_func ("/gdbus/delayed-message-processing", delayed_message_processing);
#ifdef BUG_631379_FIXED
g_test_add_func ("/gdbus/nonce-tcp", test_nonce_tcp);
+ g_test_add_func ("/gdbus/tcp-anonymous", test_tcp_anonymous);
#endif
g_test_add_func ("/gdbus/credentials", test_credentials);
g_test_add_func ("/gdbus/overflow", test_overflow);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]