summaryrefslogtreecommitdiff
path: root/test/test-utils-glib.c
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2017-07-06 15:58:48 +0100
committerSimon McVittie <smcv@collabora.com>2017-11-06 16:41:13 +0000
commit25c54a79a74b6e582f6114157882e5df47a1af95 (patch)
treea6f4af5a61ddf58de791e502f6d25c870201ff4f /test/test-utils-glib.c
parent2a7290366115e74c2d9fbc400461f9778d50a31b (diff)
downloaddbus-25c54a79a74b6e582f6114157882e5df47a1af95.tar.gz
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 <smcv@collabora.com> Reviewed-by: Philip Withnall <withnall@endlessm.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
Diffstat (limited to 'test/test-utils-glib.c')
-rw-r--r--test/test-utils-glib.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c
index 2caef25f..ccf87699 100644
--- a/test/test-utils-glib.c
+++ b/test/test-utils-glib.c
@@ -473,6 +473,30 @@ test_try_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, error))
+ 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,