From d9acee829aa28256ef8c1f494b580ca5ee9585e9 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 13 Mar 2019 13:17:43 +0000 Subject: [PATCH] tests: Use gdbus-codegen to drop hand-coded interface definitions Bump our GLib dependency to 2.60 so we can use `gdbus-codegen --interface-info-{body,header}` to generate interface definitions dynamically rather than hand-coding them. We actually need to depend on 2.60.1 so we get https://gitlab.gnome.org/GNOME/glib/merge_requests/721. Signed-off-by: Philip Withnall --- libmalcontent/tests/accounts-service-iface.h | 138 ---------- libmalcontent/tests/app-filter.c | 5 +- ...om.endlessm.ParentalControls.AppFilter.xml | 51 ++++ libmalcontent/tests/meson.build | 49 +++- .../tests/org.freedesktop.Accounts.xml | 257 ++++++++++++++++++ 5 files changed, 358 insertions(+), 142 deletions(-) delete mode 100644 libmalcontent/tests/accounts-service-iface.h create mode 100644 libmalcontent/tests/com.endlessm.ParentalControls.AppFilter.xml create mode 100644 libmalcontent/tests/org.freedesktop.Accounts.xml diff --git a/libmalcontent/tests/accounts-service-iface.h b/libmalcontent/tests/accounts-service-iface.h deleted file mode 100644 index e139996..0000000 --- a/libmalcontent/tests/accounts-service-iface.h +++ /dev/null @@ -1,138 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- - * - * Copyright © 2018 Endless Mobile, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: - * - Philip Withnall - */ - -#pragma once - -#include -#include -#include - -G_BEGIN_DECLS - -/* Static definition of the AppFilter interface on org.freedesktop.Accounts. - * FIXME: Once we can depend on a new enough version of GLib, generate this - * from introspection XML using `gdbus-codegen --interface-info-{header,body}`. */ -static const GDBusPropertyInfo app_filter_property_app_filter = -{ - .ref_count = -1, /* static */ - .name = (gchar *) "AppFilter", - .signature = (gchar *) "(bas)", - .flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, - .annotations = NULL, -}; - -static const GDBusPropertyInfo app_filter_property_oars_filter = -{ - .ref_count = -1, /* static */ - .name = (gchar *) "OarsFilter", - .signature = (gchar *) "(sa{ss})", - .flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, - .annotations = NULL, -}; - -static const GDBusPropertyInfo app_filter_property_allow_user_installation = -{ - .ref_count = -1, /* static */ - .name = (gchar *) "AllowUserInstallation", - .signature = (gchar *) "b", - .flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, - .annotations = NULL, -}; - -static const GDBusPropertyInfo app_filter_property_allow_system_installation = -{ - .ref_count = -1, /* static */ - .name = (gchar *) "AllowSystemInstallation", - .signature = (gchar *) "b", - .flags = G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, - .annotations = NULL, -}; - -static const GDBusPropertyInfo *app_filter_properties[] = -{ - (GDBusPropertyInfo *) &app_filter_property_app_filter, - (GDBusPropertyInfo *) &app_filter_property_oars_filter, - (GDBusPropertyInfo *) &app_filter_property_allow_user_installation, - (GDBusPropertyInfo *) &app_filter_property_allow_system_installation, - NULL, -}; - -static const GDBusInterfaceInfo app_filter_interface_info = -{ - .ref_count = -1, /* static */ - .name = (gchar *) "com.endlessm.ParentalControls.AppFilter", - .methods = NULL, - .signals = NULL, - .properties = (GDBusPropertyInfo **) &app_filter_properties, - .annotations = NULL, -}; - -static const GDBusArgInfo accounts_method_find_user_by_id_arg_user_id = -{ - .ref_count = -1, /* static */ - .name = (gchar *) "UserId", - .signature = (gchar *) "x", - .annotations = NULL, -}; -static const GDBusArgInfo accounts_method_find_user_by_id_arg_object_path = -{ - .ref_count = -1, /* static */ - .name = (gchar *) "ObjectPath", - .signature = (gchar *) "o", - .annotations = NULL, -}; -static const GDBusArgInfo *accounts_method_find_user_by_id_in_args[] = -{ - (GDBusArgInfo *) &accounts_method_find_user_by_id_arg_user_id, - NULL, -}; -static const GDBusArgInfo *accounts_method_find_user_by_id_out_args[] = -{ - (GDBusArgInfo *) &accounts_method_find_user_by_id_arg_object_path, - NULL, -}; -static const GDBusMethodInfo accounts_method_find_user_by_id = -{ - .ref_count = -1, /* static */ - .name = (gchar *) "FindUserById", - .in_args = (GDBusArgInfo **) &accounts_method_find_user_by_id_in_args, - .out_args = (GDBusArgInfo **) &accounts_method_find_user_by_id_out_args, - .annotations = NULL, -}; - -static const GDBusMethodInfo *accounts_methods[] = -{ - (GDBusMethodInfo *) &accounts_method_find_user_by_id, - NULL, -}; - -static const GDBusInterfaceInfo accounts_interface_info = -{ - .ref_count = -1, /* static */ - .name = (gchar *) "org.freedesktop.Accounts", - .methods = (GDBusMethodInfo **) &accounts_methods, - .signals = NULL, - .properties = NULL, - .annotations = NULL, -}; - -G_END_DECLS diff --git a/libmalcontent/tests/app-filter.c b/libmalcontent/tests/app-filter.c index 1ab4433..0372fba 100644 --- a/libmalcontent/tests/app-filter.c +++ b/libmalcontent/tests/app-filter.c @@ -31,6 +31,7 @@ #include #include #include "accounts-service-iface.h" +#include "accounts-service-extension-iface.h" /* Check two arrays contain exactly the same items in the same order. */ @@ -445,13 +446,13 @@ bus_set_up (BusFixture *fixture, object_path = g_strdup_printf ("/org/freedesktop/Accounts/User%u", fixture->valid_uid); gt_dbus_queue_export_object (fixture->queue, object_path, - (GDBusInterfaceInfo *) &app_filter_interface_info, + (GDBusInterfaceInfo *) &com_endlessm_parental_controls_app_filter_interface, &local_error); g_assert_no_error (local_error); gt_dbus_queue_export_object (fixture->queue, "/org/freedesktop/Accounts", - (GDBusInterfaceInfo *) &accounts_interface_info, + (GDBusInterfaceInfo *) &org_freedesktop_accounts_interface, &local_error); g_assert_no_error (local_error); diff --git a/libmalcontent/tests/com.endlessm.ParentalControls.AppFilter.xml b/libmalcontent/tests/com.endlessm.ParentalControls.AppFilter.xml new file mode 100644 index 0000000..095f1a4 --- /dev/null +++ b/libmalcontent/tests/com.endlessm.ParentalControls.AppFilter.xml @@ -0,0 +1,51 @@ + + + + + + + + List of applications to allow (boolean is True) or deny + (boolean is False) access to. + + + + + + + + + + Restriction levels for different OARS categories, preventing + installation of apps which exceed those levels. The first string is + the OARS version (for example, `oars-1.1`), followed by a dictionary + mapping OARS categories to values. + + + + + + + + + + Whether to allow installation of apps to the user flatpak + repository. + + + + + + + + + + Whether to allow installation of apps to the system flatpak + repository. + + + + + + + diff --git a/libmalcontent/tests/meson.build b/libmalcontent/tests/meson.build index a139da6..39a000c 100644 --- a/libmalcontent/tests/meson.build +++ b/libmalcontent/tests/meson.build @@ -1,5 +1,5 @@ deps = [ - dependency('gio-2.0', version: '>= 2.44'), + dependency('gio-2.0', version: '>= 2.60.1'), dependency('gio-unix-2.0', version: '>= 2.44'), dependency('glib-2.0', version: '>= 2.54.2'), dependency('gobject-2.0', version: '>= 2.44'), @@ -12,8 +12,53 @@ envs = test_env + [ 'G_TEST_BUILDDIR=' + meson.current_build_dir(), ] +gdbus_codegen = find_program('gdbus-codegen') + +accounts_service_iface_h = custom_target( + 'accounts-service-iface.h', + input: ['org.freedesktop.Accounts.xml'], + output: ['accounts-service-iface.h'], + command: [gdbus_codegen, + '--interface-info-header', + '--output', '@OUTPUT@', + '@INPUT@'], +) +accounts_service_iface_c = custom_target( + 'accounts-service-iface.c', + input: ['org.freedesktop.Accounts.xml'], + output: ['accounts-service-iface.c'], + command: [gdbus_codegen, + '--interface-info-body', + '--output', '@OUTPUT@', + '@INPUT@'], +) + +accounts_service_extension_iface_h = custom_target( + 'accounts-service-extension-iface.h', + input: ['com.endlessm.ParentalControls.AppFilter.xml'], + output: ['accounts-service-extension-iface.h'], + command: [gdbus_codegen, + '--interface-info-header', + '--output', '@OUTPUT@', + '@INPUT@'], +) +accounts_service_extension_iface_c = custom_target( + 'accounts-service-extension-iface.c', + input: ['com.endlessm.ParentalControls.AppFilter.xml'], + output: ['accounts-service-extension-iface.c'], + command: [gdbus_codegen, + '--interface-info-body', + '--output', '@OUTPUT@', + '@INPUT@'], +) + test_programs = [ - ['app-filter', ['accounts-service-iface.h'], deps], + ['app-filter', [ + accounts_service_iface_h, + accounts_service_iface_c, + accounts_service_extension_iface_h, + accounts_service_extension_iface_c, + ], deps], ] installed_tests_metadir = join_paths(datadir, 'installed-tests', diff --git a/libmalcontent/tests/org.freedesktop.Accounts.xml b/libmalcontent/tests/org.freedesktop.Accounts.xml new file mode 100644 index 0000000..4612c5d --- /dev/null +++ b/libmalcontent/tests/org.freedesktop.Accounts.xml @@ -0,0 +1,257 @@ + + + + + + + + + + Object paths of cached users + + + + + + Lists users which have logged into the system locally before. + This is not meant to return an exhaustive list of all users. + It is possible for FindUserByName() + to return a user that's not on the list. + + + + + + + + + The uid to look up + + + Object path of user + + + + + + Finds a user by uid. + + + + if no user with the given uid exists + + + + + + + + The username to look up + + + Object path of user + + + + + + Finds a user by its username. + + + + if no user with the given username exists + + + + + + + + The username for the new user + + + The real name for the new user + + + Object path of the new user + + + + The account type, encoded as an integer + + + + + + Creates a new user account. + + + The accountType argument can take the following values: + + + + 0 + Standard user + + + 1 + Administrator + + + + + The caller needs the org.freedesktop.accounts.user-administration PolicyKit authorization. + + + if the caller lacks the appropriate PolicyKit authorization + if the operation failed + + + + + + + + The username for the user + + + Object path of user + + + + + + Caches a user account, so that it shows up in ListCachedUsers() output. + The user name may be a remote user, but the system must be able to lookup + the user name and resolve the user information. + + + + The caller needs the org.freedesktop.accounts.user-administration PolicyKit authorization. + + + if the caller lacks the appropriate PolicyKit authorization + if the user name cannot be resolved + + + + + + + + The username for the user + + + + + + Releases all metadata about a user account, including icon, language and session. If the user account is + from a remote server and the user has never logged in before, then that account will no longer show up + in ListCachedUsers() output. + + + + The caller needs the org.freedesktop.accounts.user-administration PolicyKit authorization. + + + if the caller lacks the appropriate PolicyKit authorization + if the user name cannot be resolved + + + + + + + + The uid to delete + + + Whether to remove the users files + + + + + + Deletes a user account. + + + + The caller needs the org.freedesktop.accounts.user-administration PolicyKit authorization. + + + if the caller lacks the appropriate PolicyKit authorization + if the operation failed + + + + + + + Object path of the user that was added. + + + + + Emitted when a user is added. + + + + + + + + Object path of the user that was deleted. + + + + + Emitted when a user is deleted. + + + + + + + + + + The version of the running daemon. + + + + + + + + + + Whether or not the system has no users + + + + + + + + + + Whether or not the system has multiple users + + + + + + + + + + Users to automatically log in as + + + + + + +