From 39ba753275ece8d65075c32cf34272bcfe4d6e0f Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 6 Jul 2017 15:58:48 +0100 Subject: [PATCH] test-utils-glib: Add function to connect with GDBus as another uid This will be used in a test for connecting to container servers as the wrong uid. Signed-off-by: Simon McVittie https://bugs.freedesktop.org/show_bug.cgi?id=101354 --- test/test-utils-glib.c | 27 +++++++++++++++++++++++++++ test/test-utils-glib.h | 4 ++++ 2 files changed, 31 insertions(+) diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c index b5352056..2eb2b6f6 100644 --- a/test/test-utils-glib.c +++ b/test/test-utils-glib.c @@ -445,6 +445,33 @@ test_connect_to_bus_as_user (TestMainContext *ctx, return conn; } +/* + * Raise G_IO_ERROR_NOT_SUPPORTED if the requested user is impossible. + */ +GDBusConnection * +test_try_connect_gdbus_as_user (const char *address, + TestUser user, + GError **error) +{ + GDBusConnection *conn; + + if (user != TEST_USER_ME && !become_other_user (user)) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Test skipped"); + return NULL; + } + + conn = g_dbus_connection_new_for_address_sync (address, + (G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION | + G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT), + NULL, NULL, error); + + if (user != TEST_USER_ME) + back_to_root (); + + return conn; +} + static void pid_died (GPid pid, gint status, diff --git a/test/test-utils-glib.h b/test/test-utils-glib.h index 52d66b91..85b09492 100644 --- a/test/test-utils-glib.h +++ b/test/test-utils-glib.h @@ -29,6 +29,7 @@ #include +#include #include #include "test-utils.h" @@ -77,6 +78,9 @@ DBusConnection *test_connect_to_bus (TestMainContext *ctx, DBusConnection *test_connect_to_bus_as_user (TestMainContext *ctx, const char *address, TestUser user); +GDBusConnection *test_try_connect_gdbus_as_user (const char *address, + TestUser user, + GError **error); void test_kill_pid (GPid pid); -- 2.13.3