From ae36f7e7f4b1237ba581132eb847975cf31a4d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?= =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= Date: Sun, 22 Jan 2017 16:01:26 +0000 Subject: [PATCH] Add a test-auth test program This version of test-auth is just a normal glib-assisted testcase that runs a test dbus daemon instance with a given config and tries to connect a client to it. https://bugs.freedesktop.org/show_bug.cgi?id=96577 --- test/Makefile.am | 8 ++ .../valid-config-files/debug-auth-sspi.conf.in | 13 +++ test/test-auth.c | 114 +++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100755 test/data/valid-config-files/debug-auth-sspi.conf.in create mode 100755 test/test-auth.c diff --git a/test/Makefile.am b/test/Makefile.am index b293069..e7889c9 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -158,6 +158,7 @@ if DBUS_WITH_GLIB installable_tests += \ test-corrupt \ test-dbus-daemon \ + test-auth \ test-dbus-daemon-eavesdrop \ test-fdpass \ test-monitor \ @@ -231,6 +232,12 @@ manual_authz_LDADD = \ $(GLIB_LIBS) \ $(NULL) +test_auth_SOURCES = test-auth.c +test_auth_LDADD = \ + libdbus-testutils.la \ + $(GLIB_LIBS) \ + $(NULL) + test_corrupt_SOURCES = corrupt.c test_corrupt_LDADD = \ libdbus-testutils.la \ @@ -346,6 +353,7 @@ in_data = \ data/valid-config-files-system/debug-allow-all-pass.conf.in \ data/valid-config-files/debug-allow-all-sha1.conf.in \ data/valid-config-files/debug-allow-all.conf.in \ + data/valid-config-files/debug-auth-sspi.conf.in \ data/valid-config-files/finite-timeout.conf.in \ data/valid-config-files/forbidding.conf.in \ data/valid-config-files/incoming-limit.conf.in \ diff --git a/test/data/valid-config-files/debug-auth-sspi.conf.in b/test/data/valid-config-files/debug-auth-sspi.conf.in new file mode 100755 index 0000000..351c4f2 --- /dev/null +++ b/test/data/valid-config-files/debug-auth-sspi.conf.in @@ -0,0 +1,13 @@ + + + @TEST_LISTEN@ + @DBUS_TEST_DATA@/valid-service-files + DBUS_WINDOWS_SSPI_NTLM + + + + + + + diff --git a/test/test-auth.c b/test/test-auth.c new file mode 100755 index 0000000..77419e5 --- /dev/null +++ b/test/test-auth.c @@ -0,0 +1,114 @@ +#include + +#include + +#include + +#include +#ifdef G_OS_UNIX +#include +#include +#endif + +#include "test-utils-glib.h" + +typedef struct { + gboolean skip; + DBusError e; + TestMainContext *ctx; + + GPid daemon_pid; + DBusServer *server; + + gchar *address; + + DBusConnection *left_conn; + + DBusConnection *right_conn; + +} Fixture; + +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 +setup (Fixture *f, + gconstpointer context) +{ + const Config *config = context; + + f->ctx = test_main_context_get (); + dbus_error_init (&f->e); + + f->address = test_get_dbus_daemon (config ? config->config_file : NULL, + TEST_USER_ME, + &f->daemon_pid); + + if (f->address == NULL) + { + f->skip = TRUE; + return; + } + + f->left_conn = test_connect_to_bus (f->ctx, f->address); + f->right_conn = test_connect_to_bus (f->ctx, f->address); +} + +static void +test_sspi (Fixture *f, + gconstpointer context) +{ +} + +static void +teardown (Fixture *f, + gconstpointer context G_GNUC_UNUSED) +{ + dbus_error_free (&f->e); + + if (f->left_conn != NULL) + { + dbus_connection_close (f->left_conn); + dbus_connection_unref (f->left_conn); + f->left_conn = NULL; + } + + if (f->right_conn != NULL) + { + dbus_connection_close (f->right_conn); + dbus_connection_unref (f->right_conn); + f->right_conn = NULL; + } + + if (f->daemon_pid != 0) + { + test_kill_pid (f->daemon_pid); + g_spawn_close_pid (f->daemon_pid); + f->daemon_pid = 0; + } + + test_main_context_unref (f->ctx); + g_free (f->address); +} + +static Config sspi_config = { + "96577", 1, "valid-config-files/debug-auth-sspi.conf", + SPECIFY_ADDRESS +}; + +int +main (int argc, + char **argv) +{ + test_init (&argc, &argv); + + g_test_add ("/auth/sspi", Fixture, &sspi_config, setup, test_sspi, teardown); + + return g_test_run (); + + return 0; +} -- 2.4.0