From 614e5aa8723484d351005b4bbbeed9b4ef8332ee Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 5 Feb 2015 18:30:36 +0000 Subject: Add a regression test for connecting to XDG_RUNTIME_DIR/bus by default This test requires the unix:runtime=yes sub-transport from Bug #61303. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=61301 Reviewed-by: Philip Withnall --- test/Makefile.am | 1 + .../valid-config-files/listen-unix-runtime.conf | 11 +++ test/dbus-daemon.c | 81 +++++++++++++++++++++- 3 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 test/data/valid-config-files/listen-unix-runtime.conf (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index c816b24b..f3848599 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -349,6 +349,7 @@ static_data = \ data/valid-config-files/basic.conf \ data/valid-config-files/basic.d/basic.conf \ data/valid-config-files/entities.conf \ + data/valid-config-files/listen-unix-runtime.conf \ data/valid-config-files/many-rules.conf \ data/valid-config-files/system.d/test.conf \ data/valid-messages/array-of-array-of-uint32.message \ diff --git a/test/data/valid-config-files/listen-unix-runtime.conf b/test/data/valid-config-files/listen-unix-runtime.conf new file mode 100644 index 00000000..169de2cb --- /dev/null +++ b/test/data/valid-config-files/listen-unix-runtime.conf @@ -0,0 +1,11 @@ + + + session + unix:runtime=yes + + + + + + diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c index 26786fc2..6f1aa064 100644 --- a/test/dbus-daemon.c +++ b/test/dbus-daemon.c @@ -2,6 +2,7 @@ * * Author: Simon McVittie * Copyright © 2010-2011 Nokia Corporation + * Copyright © 2015 Collabora Ltd. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation files @@ -26,6 +27,14 @@ #include +#include +#include + +#include + +#include +#include + #include "test-utils-glib.h" #include @@ -75,6 +84,9 @@ typedef struct { DBusConnection *right_conn; gboolean right_conn_echo; gboolean wait_forever_called; + + gchar *tmp_runtime_dir; + gchar *saved_runtime_dir; } Fixture; static DBusHandlerResult @@ -112,6 +124,7 @@ typedef struct { const char *bug_ref; guint min_messages; const char *config_file; + enum { SPECIFY_ADDRESS = 0, RELY_ON_DEFAULT } connect_mode; } Config; static void @@ -125,6 +138,17 @@ setup (Fixture *f, f->ge = NULL; dbus_error_init (&f->e); + if (config != NULL && config->connect_mode == RELY_ON_DEFAULT) + { + /* this is chosen to be something needing escaping */ + f->tmp_runtime_dir = g_dir_make_tmp ("dbus=daemon=test.XXXXXX", &f->ge); + g_assert_no_error (f->ge); + + /* we're relying on being single-threaded for this to be safe */ + f->saved_runtime_dir = g_strdup (g_getenv ("XDG_RUNTIME_DIR")); + g_setenv ("XDG_RUNTIME_DIR", f->tmp_runtime_dir, TRUE); + } + address = test_get_dbus_daemon (config ? config->config_file : NULL, TEST_USER_ME, &f->daemon_pid); @@ -136,7 +160,22 @@ setup (Fixture *f, } f->left_conn = test_connect_to_bus (f->ctx, address); - f->right_conn = test_connect_to_bus (f->ctx, address); + + if (config != NULL && config->connect_mode == RELY_ON_DEFAULT) + { + /* use the default bus for the echo service ("right"), to check that + * it ends up on the same bus as the client ("left") */ + f->right_conn = dbus_bus_get_private (DBUS_BUS_SESSION, &f->e); + test_assert_no_error (&f->e); + + if (!test_connection_setup (f->ctx, f->right_conn)) + g_error ("OOM"); + } + else + { + f->right_conn = test_connect_to_bus (f->ctx, address); + } + g_free (address); } @@ -637,17 +676,46 @@ teardown (Fixture *f, f->daemon_pid = 0; } + if (f->tmp_runtime_dir != NULL) + { + gchar *path; + + /* the socket may exist */ + path = g_strdup_printf ("%s/bus", f->tmp_runtime_dir); + g_assert (g_remove (path) == 0 || errno == ENOENT); + g_free (path); + /* there shouldn't be anything else in there */ + g_assert_cmpint (g_rmdir (f->tmp_runtime_dir), ==, 0); + + /* we're relying on being single-threaded for this to be safe */ + if (f->saved_runtime_dir != NULL) + g_setenv ("XDG_RUNTIME_DIR", f->saved_runtime_dir, TRUE); + else + g_unsetenv ("XDG_RUNTIME_DIR"); + g_free (f->saved_runtime_dir); + g_free (f->tmp_runtime_dir); + } + test_main_context_unref (f->ctx); } static Config limited_config = { - "34393", 10000, "valid-config-files/incoming-limit.conf" + "34393", 10000, "valid-config-files/incoming-limit.conf", + SPECIFY_ADDRESS }; static Config finite_timeout_config = { - NULL, 1, "valid-config-files/finite-timeout.conf" + NULL, 1, "valid-config-files/finite-timeout.conf", + SPECIFY_ADDRESS }; +#ifdef DBUS_UNIX +static Config listen_unix_runtime_config = { + "61303", 1, "valid-config-files/listen-unix-runtime.conf", + RELY_ON_DEFAULT +}; +#endif + int main (int argc, char **argv) @@ -665,6 +733,13 @@ main (int argc, g_test_add ("/processid", Fixture, NULL, setup, test_processid, teardown); g_test_add ("/canonical-path/uae", Fixture, NULL, setup, test_canonical_path_uae, teardown); +#ifdef DBUS_UNIX + /* We can't test this in loopback.c with the rest of unix:runtime=yes, + * because dbus_bus_get[_private] is the only way to use the default, + * and that blocks on a round-trip to the dbus-daemon */ + g_test_add ("/unix-runtime-is-default", Fixture, &listen_unix_runtime_config, + setup, test_echo, teardown); +#endif return g_test_run (); } -- cgit v1.2.1