From b0c7f1b1bdf1f4ddb9f01c531e6e5f38b4491f46 Mon Sep 17 00:00:00 2001 From: Alban Crequy Date: Mon, 11 Aug 2014 15:16:41 +0100 Subject: [PATCH 3/3] new tests: max_connections_per_user, max_connections_per_systemd_unit Similar to the previous test max_connections_per_process. - max_connections_per_user: check we can reach the limit but not go over. - max_connections_per_systemd_unit: since we don't know whether "make check" will be run in a system unit or not, the test is very basic. v3: - change max_connections_per_cgroup to max_connections_per_systemd_unit https://bugs.freedesktop.org/show_bug.cgi?id=81469 --- configure.ac | 2 + test/Makefile.am | 2 + test/data/valid-config-files/.gitignore | 2 + .../max-connections-per-systemd-unit.conf.in | 18 ++++++ .../max-connections-per-user.conf.in | 18 ++++++ test/dbus-daemon.c | 66 ++++++++++++++-------- 6 files changed, 85 insertions(+), 23 deletions(-) create mode 100644 test/data/valid-config-files/max-connections-per-systemd-unit.conf.in create mode 100644 test/data/valid-config-files/max-connections-per-user.conf.in diff --git a/configure.ac b/configure.ac index f748566..8269ae8 100644 --- a/configure.ac +++ b/configure.ac @@ -1779,6 +1779,8 @@ 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-connections-per-user.conf +test/data/valid-config-files/max-connections-per-systemd-unit.conf test/data/valid-config-files/max-connections-per-process.conf test/data/valid-config-files-system/debug-allow-all-pass.conf test/data/valid-config-files-system/debug-allow-all-fail.conf diff --git a/test/Makefile.am b/test/Makefile.am index d499b1d..d90c65a 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -250,6 +250,8 @@ 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-connections-per-user.conf.in \ + data/valid-config-files/max-connections-per-systemd-unit.conf.in \ data/valid-config-files/max-connections-per-process.conf.in \ data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoExec.service.in \ data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoService.service.in \ diff --git a/test/data/valid-config-files/.gitignore b/test/data/valid-config-files/.gitignore index acef7c7..fc81d7d 100644 --- a/test/data/valid-config-files/.gitignore +++ b/test/data/valid-config-files/.gitignore @@ -1,6 +1,8 @@ debug-allow-all.conf debug-allow-all-sha1.conf incoming-limit.conf +max-connections-per-user.conf +max-connections-per-systemd-unit.conf max-connections-per-process.conf session.conf system.conf diff --git a/test/data/valid-config-files/max-connections-per-systemd-unit.conf.in b/test/data/valid-config-files/max-connections-per-systemd-unit.conf.in new file mode 100644 index 0000000..2fea230 --- /dev/null +++ b/test/data/valid-config-files/max-connections-per-systemd-unit.conf.in @@ -0,0 +1,18 @@ + + + + session + @TEST_LISTEN@ + + + + + + + + + + + 3 + diff --git a/test/data/valid-config-files/max-connections-per-user.conf.in b/test/data/valid-config-files/max-connections-per-user.conf.in new file mode 100644 index 0000000..5394557 --- /dev/null +++ b/test/data/valid-config-files/max-connections-per-user.conf.in @@ -0,0 +1,18 @@ + + + + session + @TEST_LISTEN@ + + + + + + + + + + + 3 + diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c index 153fbd7..17c0ba4 100644 --- a/test/dbus-daemon.c +++ b/test/dbus-daemon.c @@ -182,6 +182,22 @@ typedef struct { const char *config_file; } Config; +static Config limited_config = { + "34393", 10000, "valid-config-files/incoming-limit.conf" +}; + +static Config max_connections_per_process_config = { + "82346", 0, "valid-config-files/max-connections-per-process.conf" +}; + +static Config max_connections_per_user_config = { + "82346", 0, "valid-config-files/max-connections-per-user.conf" +}; + +static Config max_connections_per_systemd_unit_config = { + "81469", 0, "valid-config-files/max-connections-per-systemd-unit.conf" +}; + static void setup (Fixture *f, gconstpointer context) @@ -457,9 +473,10 @@ test_creds (Fixture *f, } static void -test_max_connections_per_process (Fixture *f, - gconstpointer context) +test_max_connections (Fixture *f, gconstpointer context) { + const Config *config = context; + DBusConnection *conn3, *conn4; DBusError error = DBUS_ERROR_INIT; dbus_bool_t ok; @@ -468,18 +485,23 @@ test_max_connections_per_process (Fixture *f, 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); + /* "make check" is probably not run as a system service, so it is not + * restricted by max_connections_per_systemd_unit ... */ + if (config != &max_connections_per_systemd_unit_config) + { + /* 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); @@ -530,14 +552,6 @@ teardown (Fixture *f, test_main_context_unref (f->ctx); } -static Config limited_config = { - "34393", 10000, "valid-config-files/incoming-limit.conf" -}; - -static Config max_connections_per_process_config = { - "82346", 0, "valid-config-files/max-connections-per-process.conf" -}; - int main (int argc, char **argv) @@ -551,7 +565,13 @@ main (int argc, g_test_add ("/creds", Fixture, NULL, setup, test_creds, teardown); g_test_add ("/limit/max_connections_per_process", Fixture, &max_connections_per_process_config, setup, - test_max_connections_per_process, teardown); + test_max_connections, teardown); + g_test_add ("/limit/max_connections_per_user", Fixture, + &max_connections_per_user_config, setup, + test_max_connections, teardown); + g_test_add ("/limit/max_connections_per_systemd_unit", Fixture, + &max_connections_per_systemd_unit_config, setup, + test_max_connections, teardown); return g_test_run (); } -- 1.8.5.3