mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-01-03 13:50:16 +01:00
test/containers: New test
So far it only exercises SupportedArguments. Signed-off-by: Simon McVittie <smcv@collabora.com> Reviewed-by: Philip Withnall <withnall@endlessm.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
This commit is contained in:
parent
b37fa3e8ca
commit
3d2028dfe0
2 changed files with 164 additions and 0 deletions
|
|
@ -181,6 +181,7 @@ installable_helpers += \
|
|||
$(NULL)
|
||||
|
||||
installable_tests += \
|
||||
test-containers \
|
||||
test-sd-activation \
|
||||
$(NULL)
|
||||
|
||||
|
|
@ -286,6 +287,12 @@ test_apparmor_activation_LDADD = \
|
|||
$(NULL)
|
||||
endif
|
||||
|
||||
test_containers_SOURCES = containers.c
|
||||
test_containers_LDADD = \
|
||||
libdbus-testutils.la \
|
||||
$(GLIB_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
test_corrupt_SOURCES = corrupt.c
|
||||
test_corrupt_LDADD = \
|
||||
libdbus-testutils.la \
|
||||
|
|
|
|||
157
test/containers.c
Normal file
157
test/containers.c
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
/* Integration tests for restricted sockets for containers
|
||||
*
|
||||
* Copyright © 2017 Collabora Ltd.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#if defined(DBUS_ENABLE_CONTAINERS) && defined(HAVE_GIO_UNIX)
|
||||
#define HAVE_CONTAINERS_TEST
|
||||
#include <gio/gunixfdlist.h>
|
||||
#include <gio/gunixsocketaddress.h>
|
||||
#endif
|
||||
|
||||
#include "test-utils-glib.h"
|
||||
|
||||
typedef struct {
|
||||
gboolean skip;
|
||||
gchar *bus_address;
|
||||
GPid daemon_pid;
|
||||
GError *error;
|
||||
|
||||
GDBusProxy *proxy;
|
||||
|
||||
GDBusConnection *unconfined_conn;
|
||||
} Fixture;
|
||||
|
||||
static void
|
||||
setup (Fixture *f,
|
||||
gconstpointer context)
|
||||
{
|
||||
f->bus_address = test_get_dbus_daemon (NULL, TEST_USER_ME, NULL,
|
||||
&f->daemon_pid);
|
||||
|
||||
if (f->bus_address == NULL)
|
||||
{
|
||||
f->skip = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
f->unconfined_conn = g_dbus_connection_new_for_address_sync (f->bus_address,
|
||||
(G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION |
|
||||
G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT),
|
||||
NULL, NULL, &f->error);
|
||||
g_assert_no_error (f->error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Assert that Get(SupportedArguments) contains what we expect it to.
|
||||
*/
|
||||
static void
|
||||
test_get_supported_arguments (Fixture *f,
|
||||
gconstpointer context)
|
||||
{
|
||||
GVariant *v;
|
||||
#ifdef DBUS_ENABLE_CONTAINERS
|
||||
const gchar **args;
|
||||
gsize len;
|
||||
#endif
|
||||
|
||||
if (f->skip)
|
||||
return;
|
||||
|
||||
f->proxy = g_dbus_proxy_new_sync (f->unconfined_conn, G_DBUS_PROXY_FLAGS_NONE,
|
||||
NULL, DBUS_SERVICE_DBUS,
|
||||
DBUS_PATH_DBUS, DBUS_INTERFACE_CONTAINERS1,
|
||||
NULL, &f->error);
|
||||
|
||||
/* This one is DBUS_ENABLE_CONTAINERS rather than HAVE_CONTAINERS_TEST
|
||||
* because we can still test whether the interface appears or not, even
|
||||
* if we were not able to detect gio-unix-2.0 */
|
||||
#ifdef DBUS_ENABLE_CONTAINERS
|
||||
g_assert_no_error (f->error);
|
||||
|
||||
v = g_dbus_proxy_get_cached_property (f->proxy, "SupportedArguments");
|
||||
g_assert_cmpstr (g_variant_get_type_string (v), ==, "as");
|
||||
args = g_variant_get_strv (v, &len);
|
||||
|
||||
/* No arguments are defined yet */
|
||||
g_assert_cmpuint (len, ==, 0);
|
||||
|
||||
g_free (args);
|
||||
g_variant_unref (v);
|
||||
#else /* !DBUS_ENABLE_CONTAINERS */
|
||||
g_assert_no_error (f->error);
|
||||
v = g_dbus_proxy_get_cached_property (f->proxy, "SupportedArguments");
|
||||
g_assert_null (v);
|
||||
#endif /* !DBUS_ENABLE_CONTAINERS */
|
||||
}
|
||||
|
||||
static void
|
||||
teardown (Fixture *f,
|
||||
gconstpointer context G_GNUC_UNUSED)
|
||||
{
|
||||
g_clear_object (&f->proxy);
|
||||
|
||||
if (f->unconfined_conn != NULL)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
g_dbus_connection_close_sync (f->unconfined_conn, NULL, &error);
|
||||
|
||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CLOSED))
|
||||
g_clear_error (&error);
|
||||
else
|
||||
g_assert_no_error (error);
|
||||
}
|
||||
|
||||
g_clear_object (&f->unconfined_conn);
|
||||
|
||||
if (f->daemon_pid != 0)
|
||||
{
|
||||
test_kill_pid (f->daemon_pid);
|
||||
g_spawn_close_pid (f->daemon_pid);
|
||||
f->daemon_pid = 0;
|
||||
}
|
||||
|
||||
g_free (f->bus_address);
|
||||
g_clear_error (&f->error);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char **argv)
|
||||
{
|
||||
test_init (&argc, &argv);
|
||||
|
||||
g_test_add ("/containers/get-supported-arguments", Fixture, NULL,
|
||||
setup, test_get_supported_arguments, teardown);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue