From 1922072180303d86859040a4aa2b8fe9b5df32a0 Mon Sep 17 00:00:00 2001 From: Alban Crequy Date: Fri, 8 Aug 2014 12:11:11 +0100 Subject: [PATCH 3/3] new test: max_connections_per_process This test uses a configuration file with max_connections_per_process = 3. It creates 3 connections successfully and checks that the 4th connection fails with the LimitsExceeded error. https://bugs.freedesktop.org/show_bug.cgi?id=82346 --- configure.ac | 1 + test/Makefile.am | 1 + test/data/valid-config-files/.gitignore | 1 + .../data/valid-config-files/max-conn-limit.conf.in | 18 ++++++++ test/dbus-daemon.c | 49 +++++++++++++++++++--- 5 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 test/data/valid-config-files/max-conn-limit.conf.in diff --git a/configure.ac b/configure.ac index cbaf874..62855e9 100644 --- a/configure.ac +++ b/configure.ac @@ -1779,6 +1779,7 @@ dbus-1-uninstalled.pc test/data/valid-config-files/debug-allow-all.conf test/data/valid-config-files/debug-allow-all-sha1.conf test/data/valid-config-files/incoming-limit.conf +test/data/valid-config-files/max-conn-limit.conf test/data/valid-config-files-system/debug-allow-all-pass.conf test/data/valid-config-files-system/debug-allow-all-fail.conf test/data/valid-service-files/org.freedesktop.DBus.TestSuite.PrivServer.service diff --git a/test/Makefile.am b/test/Makefile.am index cec5cda..bab536d 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -250,6 +250,7 @@ in_data = \ data/valid-config-files/debug-allow-all-sha1.conf.in \ data/valid-config-files/debug-allow-all.conf.in \ data/valid-config-files/incoming-limit.conf.in \ + data/valid-config-files/max-conn-limit.conf.in \ data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoExec.service.in \ data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoService.service.in \ data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoUser.service.in \ diff --git a/test/data/valid-config-files/.gitignore b/test/data/valid-config-files/.gitignore index 8b16257..8f52c4c 100644 --- a/test/data/valid-config-files/.gitignore +++ b/test/data/valid-config-files/.gitignore @@ -1,6 +1,7 @@ debug-allow-all.conf debug-allow-all-sha1.conf incoming-limit.conf +max-conn-limit.conf session.conf system.conf run-with-tmp-session-bus.conf diff --git a/test/data/valid-config-files/max-conn-limit.conf.in b/test/data/valid-config-files/max-conn-limit.conf.in new file mode 100644 index 0000000..fda27ed --- /dev/null +++ b/test/data/valid-config-files/max-conn-limit.conf.in @@ -0,0 +1,18 @@ + + + + session + @TEST_LISTEN@ + + + + + + + + + + + 3 + diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c index 4b3b61e..f6aca83 100644 --- a/test/dbus-daemon.c +++ b/test/dbus-daemon.c @@ -51,6 +51,7 @@ typedef struct { DBusError e; GError *ge; + gchar *address; GPid daemon_pid; DBusConnection *left_conn; @@ -188,7 +189,6 @@ setup (Fixture *f, const Config *config = context; gchar *dbus_daemon; gchar *arg; - gchar *address; f->ctx = test_main_context_get (); f->ge = NULL; @@ -239,19 +239,18 @@ setup (Fixture *f, if (g_getenv ("DBUS_TEST_DAEMON_ADDRESS") != NULL) { - address = g_strdup (g_getenv ("DBUS_TEST_DAEMON_ADDRESS")); + f->address = g_strdup (g_getenv ("DBUS_TEST_DAEMON_ADDRESS")); } else { - address = spawn_dbus_daemon (dbus_daemon, arg, &f->daemon_pid); + f->address = spawn_dbus_daemon (dbus_daemon, arg, &f->daemon_pid); } g_free (dbus_daemon); g_free (arg); - f->left_conn = connect_to_bus (f, address); - f->right_conn = connect_to_bus (f, address); - g_free (address); + f->left_conn = connect_to_bus (f, f->address); + f->right_conn = connect_to_bus (f, f->address); } static void @@ -458,12 +457,44 @@ test_creds (Fixture *f, } static void +test_max_conn (Fixture *f, + gconstpointer context) +{ + DBusConnection *conn3, *conn4; + DBusError error = DBUS_ERROR_INIT; + dbus_bool_t ok; + + /* max_connections_per_process == 3 so conn3 should work */ + conn3 = connect_to_bus (f, f->address); + g_assert (conn3 != NULL); + + /* conn4 should fail */ + conn4 = dbus_connection_open_private (f->address, &error); + assert_no_error (&error); + g_assert (conn4 != NULL); + + ok = dbus_bus_register (conn4, &error); + g_assert (dbus_error_has_name (&error, "org.freedesktop.DBus.Error.LimitsExceeded")); + g_assert (ok == FALSE); + g_assert (dbus_bus_get_unique_name (conn4) == NULL); + + dbus_connection_close (conn4); + dbus_connection_unref (conn4); + + dbus_connection_close (conn3); + dbus_connection_unref (conn3); +} + +static void teardown (Fixture *f, gconstpointer context G_GNUC_UNUSED) { dbus_error_free (&f->e); g_clear_error (&f->ge); + g_free (f->address); + f->address = NULL; + if (f->left_conn != NULL) { dbus_connection_close (f->left_conn); @@ -503,6 +534,10 @@ static Config limited_config = { "34393", 10000, "valid-config-files/incoming-limit.conf" }; +static Config max_conn_config = { + "81469", 0, "valid-config-files/max-conn-limit.conf" +}; + int main (int argc, char **argv) @@ -514,6 +549,8 @@ main (int argc, g_test_add ("/echo/limited", Fixture, &limited_config, setup, test_echo, teardown); g_test_add ("/creds", Fixture, NULL, setup, test_creds, teardown); + g_test_add ("/limit/max_connections_per_process", Fixture, &max_conn_config, + setup, test_max_conn, teardown); return g_test_run (); } -- 1.8.5.3