tests: Add simple testing portal backend and wire it up to the tests

This only supports the AccessDialog call, and always just allows
everything. Still, it tests the entire codepath for authentication.
This commit is contained in:
Alexander Larsson 2019-10-01 11:35:52 +02:00 committed by Alexander Larsson
parent a95cf667a1
commit 91d9fe9c60
6 changed files with 175 additions and 2 deletions

1
.gitignore vendored
View File

@ -59,6 +59,7 @@ common/flatpak-enum-types.h
test-libflatpak
httpcache
test-update-portal
test-portal-impl
revokefs-fuse
revokefs-demo
Flatpak-1.0.*

View File

@ -74,6 +74,12 @@ tests_test_update_portal_SOURCES = \
tests/test-update-portal.c \
portal/flatpak-portal-dbus.c
tests_test_portal_impl_CFLAGS = $(AM_CFLAGS) $(BASE_CFLAGS) \
-DFLATPAK_COMPILATION \
-DLOCALEDIR=\"$(localedir)\"
tests_test_portal_impl_LDADD = $(AM_LDADD) $(BASE_LIBS)
tests_test_portal_impl_SOURCES = tests/test-portal-impl.c
tests/services/org.freedesktop.Flatpak.service: session-helper/org.freedesktop.Flatpak.service.in
mkdir -p tests/services
$(AM_V_GEN) $(SED) -e "s|\@libexecdir\@|$(abs_top_builddir)|" $< > $@
@ -86,13 +92,25 @@ tests/services/org.freedesktop.Flatpak.SystemHelper.service: system-helper/org.f
mkdir -p tests/services
$(AM_V_GEN) $(SED) -e "s|\@libexecdir\@|$(abs_top_builddir)|" -e "s|\@extraargs\@| --session --no-idle-exit|" $< > $@
tests/libtest.sh: tests/services/org.freedesktop.Flatpak.service tests/services/org.freedesktop.Flatpak.SystemHelper.service tests/services/org.freedesktop.portal.Flatpak.service
tests/services/org.freedesktop.impl.portal.desktop.test.service: tests/org.freedesktop.impl.portal.desktop.test.service.in
mkdir -p tests/services
$(AM_V_GEN) $(SED) -e "s|\@libexecdir\@|$(abs_top_builddir)/tests|" $< > $@
tests/share/xdg-desktop-portal/portals/test.portal: tests/test.portal.in
mkdir -p tests/share/xdg-desktop-portal/portals
$(AM_V_GEN) install $< $@
tests/libtest.sh: tests/services/org.freedesktop.Flatpak.service tests/services/org.freedesktop.Flatpak.SystemHelper.service tests/services/org.freedesktop.portal.Flatpak.service tests/share/xdg-desktop-portal/portals/test.portal tests/services/org.freedesktop.impl.portal.desktop.test.service
install-test-data-hook:
if ENABLE_INSTALLED_TESTS
mkdir -p $(DESTDIR)$(installed_testdir)/services
ln -sf $(dbus_servicedir)/org.freedesktop.Flatpak.service $(DESTDIR)$(installed_testdir)/services/
$(AM_V_GEN) $(SED) -e "s|\@libexecdir\@|$(libexecdir)|" -e "s|\@extraargs\@| --poll-timeout=1|" $(top_srcdir)/portal/org.freedesktop.portal.Flatpak.service.in > $(DESTDIR)$(installed_testdir)/services/org.freedesktop.portal.Flatpak.service
$(AM_V_GEN) $(SED) -e "s|\@libexecdir\@|$(libexecdir)|" -e "s|\@extraargs\@| --session --no-idle-exit|" $(top_srcdir)/system-helper/org.freedesktop.Flatpak.SystemHelper.service.in > $(DESTDIR)$(installed_testdir)/services/org.freedesktop.Flatpak.SystemHelper.service
$(AM_V_GEN) $(SED) -e "s|\@libexecdir\@|$(installed_testdir)|" tests/org.freedesktop.impl.portal.desktop.test.service.in > $(DESTDIR)$(installed_testdir)/services/org.freedesktop.impl.portal.desktop.test.service
mkdir -p $(DESTDIR)$(installed_testdir)/share/xdg-desktop-portal/portals
install tests/test.portal.in $(DESTDIR)$(installed_testdir)/share/xdg-desktop-portal/portals/test.portal
endif
tests/package_version.txt: Makefile
@ -180,7 +198,7 @@ dist_test_scripts = ${TEST_MATRIX_DIST}
dist_installed_test_extra_scripts += ${TEST_MATRIX_EXTRA_DIST}
test_programs = testlibrary testcommon
test_extra_programs = tests/httpcache tests/test-update-portal
test_extra_programs = tests/httpcache tests/test-update-portal tests/test-portal-impl
@VALGRIND_CHECK_RULES@
VALGRIND_SUPPRESSIONS_FILES=tests/flatpak.supp tests/glib.supp

View File

@ -85,6 +85,9 @@ export XDG_CONFIG_HOME=${TEST_DATA_DIR}/home/config
export XDG_DATA_HOME=${TEST_DATA_DIR}/home/share
export XDG_RUNTIME_DIR=${TEST_DATA_DIR}/runtime
export XDG_DESKTOP_PORTAL_DIR=${test_builddir}/share/xdg-desktop-portal/portals
export XDG_CURRENT_DESKTOP=test
export USERDIR=${TEST_DATA_DIR}/home/share/flatpak
export SYSTEMDIR=${TEST_DATA_DIR}/system
export ARCH=`flatpak --default-arch`

View File

@ -0,0 +1,3 @@
[D-BUS Service]
Name=org.freedesktop.impl.portal.desktop.test
Exec=@libexecdir@/test-portal-impl

144
tests/test-portal-impl.c Normal file
View File

@ -0,0 +1,144 @@
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <gio/gio.h>
static guint name_owner_id = 0;
static GMainLoop *main_loop;
static void
access_method_call (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *method_name,
GVariant *parameters,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
if (g_strcmp0 (method_name, "AccessDialog") == 0)
{
GVariantBuilder res_builder;
/* Always allow */
g_variant_builder_init (&res_builder, G_VARIANT_TYPE_VARDICT);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(u@a{sv})",
0,
g_variant_builder_end (&res_builder)));
}
else
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD,
"Method %s is not implemented on interface %s",
method_name, interface_name);
}
static const GDBusArgInfo access_dialog_IN_ARG_handle = { -1, (gchar *) "handle", (gchar *) "o", NULL };
static const GDBusArgInfo access_dialog_IN_ARG_app_id = { -1, (gchar *) "app_id", (gchar *) "s", NULL };
static const GDBusArgInfo access_dialog_IN_ARG_parent_window = { -1, (gchar *) "parent_window", (gchar *) "s", NULL };
static const GDBusArgInfo access_dialog_IN_ARG_title = { -1, (gchar *) "title", (gchar *) "s", NULL };
static const GDBusArgInfo access_dialog_IN_ARG_subtitle = { -1, (gchar *) "subtitle", (gchar *) "s", NULL };
static const GDBusArgInfo access_dialog_IN_ARG_body = { -1, (gchar *) "body", (gchar *) "s", NULL };
static const GDBusArgInfo access_dialog_IN_ARG_options = { -1, (gchar *) "options", (gchar *) "a{sv}", NULL };
static const GDBusArgInfo * const access_dialog_IN_ARG_pointers[] = {
&access_dialog_IN_ARG_handle,
&access_dialog_IN_ARG_app_id,
&access_dialog_IN_ARG_parent_window,
&access_dialog_IN_ARG_title,
&access_dialog_IN_ARG_subtitle,
&access_dialog_IN_ARG_body,
&access_dialog_IN_ARG_options,
NULL
};
static const GDBusArgInfo access_dialog_OUT_ARG_response = { -1, (gchar *) "response", (gchar *) "u", NULL };
static const GDBusArgInfo access_dialog_OUT_ARG_results = { -1, (gchar *) "results", (gchar *) "a{sv}", NULL };
static const GDBusArgInfo * const access_dialog_OUT_ARG_pointers[] = {
&access_dialog_OUT_ARG_response,
&access_dialog_OUT_ARG_results,
NULL
};
static const GDBusMethodInfo access_dialog = {
-1,
(gchar *) "AccessDialog",
(GDBusArgInfo **) &access_dialog_IN_ARG_pointers,
(GDBusArgInfo **) &access_dialog_OUT_ARG_pointers,
NULL
};
static const GDBusMethodInfo * const access_dialog_methods[] = {
&access_dialog,
NULL
};
static const GDBusInterfaceInfo access_interface_info = {
-1,
"org.freedesktop.impl.portal.Access",
(GDBusMethodInfo **) &access_dialog_methods,
(GDBusSignalInfo **) NULL,
(GDBusPropertyInfo **) NULL,
NULL,
};
static const GDBusInterfaceVTable access_vtable = {
access_method_call, /* _method_call */
NULL, /* _get_property */
NULL /* _set_property */
};
static void
on_bus_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
GError *error = NULL;
guint registration_id;
g_debug ("Bus acquired, creating skeleton");
registration_id = g_dbus_connection_register_object (connection,
"/org/freedesktop/portal/desktop",
(GDBusInterfaceInfo *) &access_interface_info,
&access_vtable,
NULL, NULL, &error);
g_assert (registration_id != 0);
}
static void
on_name_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
g_debug ("Name acquired");
}
static void
on_name_lost (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
g_debug ("Name lost");
}
int
main (int argc, char *argv[])
{
name_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
"org.freedesktop.impl.portal.desktop.test",
G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
on_bus_acquired,
on_name_acquired,
on_name_lost,
NULL,
NULL);
main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (main_loop);
return 0;
}

4
tests/test.portal.in Normal file
View File

@ -0,0 +1,4 @@
[portal]
DBusName=org.freedesktop.impl.portal.desktop.test
Interfaces=org.freedesktop.impl.portal.Access
UseIn=test