[glib/wip/pwithnall/1954-dbus-keyring-handling: 2/6] tests: Isolate directory access for gdbus-server-auth test



commit f8e4de7e7d0614a5927717ffeaa74a8791e82da7
Author: Philip Withnall <withnall endlessm com>
Date:   Tue May 5 15:02:07 2020 +0100

    tests: Isolate directory access for gdbus-server-auth test
    
    When multiple tests were run in parallel, this would race on its access
    to `~/.dbus-keyrings` to authenticate with the D-Bus server, since the
    keyring directory was not appropriately sandboxed to the unit test.
    
    Use `G_TEST_OPTION_ISOLATE_DIRS` to automatically isolate each unit
    test’s directory usage.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>
    
    Fixes: #1954

 gio/tests/gdbus-server-auth.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/gio/tests/gdbus-server-auth.c b/gio/tests/gdbus-server-auth.c
index e782bd3d7..2554ad6ab 100644
--- a/gio/tests/gdbus-server-auth.c
+++ b/gio/tests/gdbus-server-auth.c
@@ -398,6 +398,14 @@ do_test_server_auth (InteropFlags flags)
       LibdbusCall libdbus_call = { DBUS_ERROR_INIT, NULL, NULL, NULL };
       GTask *task;
 
+      /* The test suite uses %G_TEST_OPTION_ISOLATE_DIRS, which sets
+       * `HOME=/dev/null` and leaves g_get_home_dir() pointing to the per-test
+       * temp home directory. Unfortunately, libdbus doesn’t allow the home dir
+       * to be overridden except using the environment, so copy the per-test
+       * temp home directory back there so that libdbus uses the same
+       * `$HOME/.dbus-keyrings` path as GLib. This is not thread-safe. */
+      g_setenv ("HOME", g_get_home_dir (), TRUE);
+
       libdbus_call.conn = dbus_connection_open_private (connectable_address,
                                                         &libdbus_call.error);
       g_assert_cmpstr (libdbus_call.error.name, ==, NULL);
@@ -516,10 +524,7 @@ int
 main (int   argc,
       char *argv[])
 {
-  /* FIXME: Add debug for https://gitlab.gnome.org/GNOME/glib/issues/1954 */
-  g_setenv ("G_DBUS_DEBUG", "all", TRUE);
-
-  g_test_init (&argc, &argv, NULL);
+  g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
 
   g_test_add_func ("/gdbus/server-auth", test_server_auth);
   g_test_add_func ("/gdbus/server-auth/abstract", test_server_auth_abstract);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]