]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
test-utils-glib: Add function to connect with GDBus as another uid
authorSimon McVittie <smcv@collabora.com>
Thu, 6 Jul 2017 14:58:48 +0000 (15:58 +0100)
committerSimon McVittie <smcv@collabora.com>
Mon, 6 Nov 2017 16:41:13 +0000 (16:41 +0000)
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

test/test-utils-glib.c
test/test-utils-glib.h

index 2caef25f3fb4375c44b392ddf91def52e7db5c85..ccf8769962f22ec80da2ff5414776e0e5c5b6a6f 100644 (file)
@@ -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,
index bebd5dd66d2896793bca108dc1424158da3944c3..9822a36d8d065799c071acb9deb64f571fa3d953 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <dbus/dbus.h>
 
+#include <gio/gio.h>
 #include <glib.h>
 
 #include "test-utils.h"
@@ -81,6 +82,9 @@ DBusConnection *test_try_connect_to_bus_as_user (TestMainContext *ctx,
     const char *address,
     TestUser user,
     GError **error);
+GDBusConnection *test_try_connect_gdbus_as_user (const char *address,
+    TestUser user,
+    GError **error);
 
 void test_kill_pid (GPid pid);