Merge pull request #18 from endlessm/T24004-unit-tests

T24004 Comprehensive unit tests
This commit is contained in:
Philip Withnall 2018-12-20 13:02:24 +00:00 committed by GitHub
commit 58fc42f805
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1229 additions and 23 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "subprojects/libglib-testing"]
path = subprojects/libglib-testing
url = https://gitlab.gnome.org/pwithnall/libglib-testing.git

View File

@ -16,7 +16,7 @@
value="com.endlessm.ParentalControls.AppFilter.ReadAny"/>
<!--
app-filter:
AppFilter:
A filter for which applications and binaries the user can run. This is
intended to be set by administrators and read by users, rather than being
@ -27,13 +27,13 @@
slash). The boolean value indicates whether this is a whitelist (true) or
blacklist (false).
-->
<property name="app-filter" type="(bas)" access="readwrite">
<property name="AppFilter" type="(bas)" access="readwrite">
<annotation name="org.freedesktop.Accounts.DefaultValue"
value="(false, [])"/>
</property>
<!--
oars-filter:
OarsFilter:
A filter for which applications the user can see in app lists and install.
This is intended to be set by administrators and read by users, rather
@ -55,38 +55,38 @@
in AppStream data:
https://www.freedesktop.org/software/appstream/docs/chap-Metadata.html#tag-content_rating.
-->
<property name="oars-filter" type="(sa{ss})" access="readwrite">
<property name="OarsFilter" type="(sa{ss})" access="readwrite">
<annotation name="org.freedesktop.Accounts.DefaultValue"
value="('oars-1.1', @a{ss} {})"/>
</property>
<!--
allow-user-installation:
AllowUserInstallation:
Whether this user is allowed to install to their flatpak user repository.
If this is true, and if the polkit check for allowing app installation
succeeds, and if the oars-filter does not restrict this app, app
succeeds, and if the OarsFilter does not restrict this app, app
installation can proceed.
If this is false, the user is not allowed to install any apps or runtimes
to their flatpak user repository.
-->
<property name="allow-user-installation" type="b" access="readwrite">
<property name="AllowUserInstallation" type="b" access="readwrite">
<annotation name="org.freedesktop.Accounts.DefaultValue" value="true"/>
</property>
<!--
allow-system-installation:
AllowSystemInstallation:
Whether this user is allowed to install to the flatpak system repository.
If this is true, and if the polkit check for allowing app installation
succeeds, and if the oars-filter does not restrict this app, app
succeeds, and if the OarsFilter does not restrict this app, app
installation can proceed.
If this is false, the user is not allowed to install any apps or runtimes
to the flatpak system repository.
-->
<property name="allow-system-installation" type="b" access="readwrite">
<property name="AllowSystemInstallation" type="b" access="readwrite">
<annotation name="org.freedesktop.Accounts.DefaultValue" value="false"/>
</property>
</interface>

View File

@ -303,7 +303,7 @@ epc_app_filter_is_appinfo_allowed (EpcAppFilter *filter,
for (gsize i = 0; old_flatpak_apps[i] != NULL; i++)
{
gchar *old_flatpak_app = g_strstrip (old_flatpak_app);
gchar *old_flatpak_app = g_strstrip (old_flatpak_apps[i]);
if (g_str_has_suffix (old_flatpak_app, ".desktop"))
old_flatpak_app[strlen (old_flatpak_app) - strlen (".desktop")] = '\0';
@ -509,7 +509,8 @@ bus_error_to_app_filter_error (const GError *bus_error,
return g_error_new (EPC_APP_FILTER_ERROR, EPC_APP_FILTER_ERROR_PERMISSION_DENIED,
_("Not allowed to query app filter data for user %u"),
user_id);
else if (g_error_matches (bus_error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD))
else if (g_error_matches (bus_error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD) ||
bus_remote_error_matches (bus_error, "org.freedesktop.Accounts.Error.Failed"))
return g_error_new (EPC_APP_FILTER_ERROR, EPC_APP_FILTER_ERROR_INVALID_USER,
_("User %u does not exist"), user_id);
else
@ -632,7 +633,7 @@ epc_get_app_filter (GDBusConnection *connection,
/* Extract the properties we care about. They may be silently omitted from the
* results if we dont have permission to access them. */
properties = g_variant_get_child_value (result_variant, 0);
if (!g_variant_lookup (properties, "app-filter", "(b^as)",
if (!g_variant_lookup (properties, "AppFilter", "(b^as)",
&is_whitelist, &app_list))
{
g_set_error (error, EPC_APP_FILTER_ERROR,
@ -642,12 +643,12 @@ epc_get_app_filter (GDBusConnection *connection,
return NULL;
}
if (!g_variant_lookup (properties, "oars-filter", "(&s@a{ss})",
if (!g_variant_lookup (properties, "OarsFilter", "(&s@a{ss})",
&content_rating_kind, &oars_variant))
{
/* Default value. */
content_rating_kind = "oars-1.1";
oars_variant = g_variant_new ("@a{ss} {}");
oars_variant = g_variant_new ("a{ss}", NULL);
}
/* Check that the OARS filter is in a format we support. Currently, thats
@ -662,14 +663,14 @@ epc_get_app_filter (GDBusConnection *connection,
return NULL;
}
if (!g_variant_lookup (properties, "allow-user-installation", "b",
if (!g_variant_lookup (properties, "AllowUserInstallation", "b",
&allow_user_installation))
{
/* Default value. */
allow_user_installation = TRUE;
}
if (!g_variant_lookup (properties, "allow-system-installation", "b",
if (!g_variant_lookup (properties, "AllowSystemInstallation", "b",
&allow_system_installation))
{
/* Default value. */
@ -869,7 +870,7 @@ epc_set_app_filter (GDBusConnection *connection,
"Set",
g_variant_new ("(ssv)",
"com.endlessm.ParentalControls.AppFilter",
"app-filter",
"AppFilter",
g_steal_pointer (&app_filter_variant)),
G_VARIANT_TYPE ("()"),
allow_interactive_authorization
@ -892,7 +893,7 @@ epc_set_app_filter (GDBusConnection *connection,
"Set",
g_variant_new ("(ssv)",
"com.endlessm.ParentalControls.AppFilter",
"oars-filter",
"OarsFilter",
g_steal_pointer (&oars_filter_variant)),
G_VARIANT_TYPE ("()"),
allow_interactive_authorization
@ -915,7 +916,7 @@ epc_set_app_filter (GDBusConnection *connection,
"Set",
g_variant_new ("(ssv)",
"com.endlessm.ParentalControls.AppFilter",
"allow-user-installation",
"AllowUserInstallation",
g_steal_pointer (&allow_user_installation_variant)),
G_VARIANT_TYPE ("()"),
allow_interactive_authorization
@ -938,7 +939,7 @@ epc_set_app_filter (GDBusConnection *connection,
"Set",
g_variant_new ("(ssv)",
"com.endlessm.ParentalControls.AppFilter",
"allow-system-installation",
"AllowSystemInstallation",
g_steal_pointer (&allow_system_installation_variant)),
G_VARIANT_TYPE ("()"),
allow_interactive_authorization
@ -1024,6 +1025,7 @@ epc_set_app_filter_async (GDBusConnection *connection,
g_task_set_source_tag (task, epc_set_app_filter_async);
data = g_new0 (SetAppFilterData, 1);
data->connection = (connection != NULL) ? g_object_ref (connection) : NULL;
data->user_id = user_id;
data->app_filter = epc_app_filter_ref (app_filter);
data->allow_interactive_authorization = allow_interactive_authorization;

View File

@ -0,0 +1,138 @@
/* -*- 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 <withnall@endlessm.com>
*/
#pragma once
#include <gio/gio.h>
#include <glib.h>
#include <glib-object.h>
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

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,10 @@
deps = [
dependency('gio-2.0', version: '>= 2.44'),
dependency('gio-unix-2.0', version: '>= 2.44'),
dependency('glib-2.0', version: '>= 2.54.2'),
dependency('gobject-2.0', version: '>= 2.44'),
libeos_parental_controls_dep,
libglib_testing_dep,
]
envs = test_env + [
@ -11,7 +13,7 @@ envs = test_env + [
]
test_programs = [
['app-filter', [], deps],
['app-filter', ['accounts-service-iface.h'], deps],
]
installed_tests_metadir = join_paths(datadir, 'installed-tests',

View File

@ -33,6 +33,9 @@ polkit_gobject = dependency('polkit-gobject-1')
polkitpolicydir = polkit_gobject.get_pkgconfig_variable('policydir',
define_variable: ['prefix', prefix])
libglib_testing = subproject('libglib-testing')
libglib_testing_dep = libglib_testing.get_variable('libglib_testing_dep')
config_h = configuration_data()
config_h.set_quoted('GETTEXT_PACKAGE', meson.project_name())
configure_file(
@ -52,6 +55,7 @@ test_c_args = [
'-Wcast-align',
'-Wclobbered',
'-Wno-declaration-after-statement',
'-Wdiscarded-qualifiers',
'-Wduplicated-branches',
'-Wduplicated-cond',
'-Wempty-body',
@ -75,7 +79,6 @@ test_c_args = [
'-Wmissing-prototypes',
'-Wnested-externs',
'-Wno-error=cpp',
'-Wno-discarded-qualifiers',
'-Wno-missing-field-initializers',
'-Wno-suggest-attribute=format',
'-Wno-unused-parameter',

@ -0,0 +1 @@
Subproject commit a2ec2038047588fe5fe722e5e27e9551c1c6d753