]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
tests: Skip system bus test if we are root but messagebus does not exist
authorSimon McVittie <smcv@collabora.com>
Tue, 2 Jul 2019 19:42:54 +0000 (20:42 +0100)
committerSimon McVittie <smcv@collabora.com>
Wed, 3 Jul 2019 10:11:23 +0000 (11:11 +0100)
Some CI systems do the build as root in a disposable container, and
run tests without ever having installed dbus. This means we can't
expect to be able to drop privileges from root to the DBUS_USER (usually
named messagebus or dbus) unless we have checked that the
DBUS_USER exists.

Signed-off-by: Simon McVittie <smcv@collabora.com>
test/dbus-daemon.c
test/test-utils-glib.c
test/test-utils-glib.h

index 6644795592d23aeae6ef284f13fd6c5d0a0f1ebe..e8bdace3c7623eba11f6a2005af85db5b60c17cb 100644 (file)
@@ -2653,7 +2653,7 @@ static Config as_another_user_config = {
     NULL, 1, "valid-config-files/as-another-user.conf",
     /* We start the dbus-daemon as root and drop privileges, like the
      * real system bus does */
-    TEST_USER_ROOT, SPECIFY_ADDRESS
+    TEST_USER_ROOT_DROP_TO_MESSAGEBUS, SPECIFY_ADDRESS
 };
 
 #ifdef ENABLE_TRADITIONAL_ACTIVATION
index 083c9bfcd6ef5d989c068a475db6e19bf49b1e49..7cc92bc725f3397ebfb91044540e12700729801e 100644 (file)
@@ -126,6 +126,7 @@ spawn_dbus_daemon (const gchar *binary,
           case TEST_USER_ROOT:
             break;
 
+          case TEST_USER_ROOT_DROP_TO_MESSAGEBUS:
           case TEST_USER_MESSAGEBUS:
             pwd = getpwnam (DBUS_USER);
 
@@ -139,6 +140,13 @@ spawn_dbus_daemon (const gchar *binary,
                 return NULL;
               }
 
+            if (user == TEST_USER_ROOT_DROP_TO_MESSAGEBUS)
+              {
+                /* Let the dbus-daemon start as root and drop privileges
+                 * itself */
+                pwd = NULL;
+              }
+
             break;
 
           case TEST_USER_OTHER:
@@ -399,6 +407,11 @@ become_other_user (TestUser user,
         username = DBUS_TEST_USER;
         break;
 
+      /* TEST_USER_ROOT_DROP_TO_MESSAGEBUS is only meaningful for
+       * test_get_dbus_daemon(), not as a client */
+      case TEST_USER_ROOT_DROP_TO_MESSAGEBUS:
+        g_return_val_if_reached (FALSE);
+
       case TEST_USER_ME:
       default:
         g_return_val_if_reached (FALSE);
@@ -445,6 +458,11 @@ become_other_user (TestUser user,
             "credentials-passing semantics on this platform");
         return FALSE;
 
+      /* TEST_USER_ROOT_DROP_TO_MESSAGEBUS is only meaningful for
+       * test_get_dbus_daemon(), not as a client */
+      case TEST_USER_ROOT_DROP_TO_MESSAGEBUS:
+        g_return_val_if_reached (FALSE);
+
       case TEST_USER_ME:
       default:
         g_return_val_if_reached (FALSE);
index ce8171bd19cde508d1f53aae1a7304851f8319f3..c4a2c5436f919e26e824ce4794f0fe77bdcaa937 100644 (file)
@@ -45,8 +45,8 @@
  * be run as an arbitrary non-root user, as above.
  *
  * Certain tests can usefully be run again, as root. When this is done,
- * tests using TEST_USER_ROOT, TEST_USER_MESSAGEBUS and/or TEST_USER_OTHER
- * can exercise situations that only arise when there's more than one uid.
+ * tests using a TestUser other than TEST_USER_ME can exercise situations
+ * that only arise when there's more than one uid.
  */
 typedef enum {
     /* Whatever user happens to be running the regression test;
@@ -58,6 +58,11 @@ typedef enum {
      * from configure.ac, usually 'messagebus' but perhaps 'dbus' or
      * '_dbus'. */
     TEST_USER_MESSAGEBUS,
+    /* Run as uid 0, expecting to drop privileges to the user who would
+     * normally run the system bus (so we must skip the test if that user
+     * doesn't exist). Only valid for test_get_dbus_daemon(), not for
+     * test_connect_to_bus_as_user(). */
+    TEST_USER_ROOT_DROP_TO_MESSAGEBUS,
     /* An unprivileged user who is neither root nor DBUS_USER.
      * This is DBUS_TEST_USER from configure.ac, usually 'nobody'. */
     TEST_USER_OTHER