diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2020-09-09 13:55:10 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2020-09-30 13:07:37 +0200 |
commit | 9342ed84b9ba6ba61049e3b245fd3f6fa68636b2 (patch) | |
tree | 6db264ea27cb647761597d69c870337077a196aa /src/portal | |
parent | 39da84662c0b41884f9c684fdc561d4880a25504 (diff) | |
download | tracker-9342ed84b9ba6ba61049e3b245fd3f6fa68636b2.tar.gz |
portal: Add testing envvar to override .flatpak-info
This will be used by our functional test suite to test portal workings.
Likewise, use this envvar presence to force the use of the Tracker portal
in the bus TrackerSparqlConnection.
Diffstat (limited to 'src/portal')
-rw-r--r-- | src/portal/tracker-portal.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/portal/tracker-portal.c b/src/portal/tracker-portal.c index 2e58a7228..ff67967c1 100644 --- a/src/portal/tracker-portal.c +++ b/src/portal/tracker-portal.c @@ -48,6 +48,7 @@ struct _TrackerPortal GCancellable *cancellable; GArray *sessions; guint64 session_ids; + gchar *test_flatpak_info; }; enum @@ -130,6 +131,7 @@ tracker_portal_finalize (GObject *object) portal->register_id = 0; } + g_clear_pointer (&portal->test_flatpak_info, g_free); g_clear_object (&portal->dbus_connection); g_clear_pointer (&portal->node_info, g_dbus_node_info_unref); @@ -174,6 +176,15 @@ tracker_portal_init (TrackerPortal *portal) { portal->sessions = g_array_new (FALSE, TRUE, sizeof (TrackerSession)); g_array_set_clear_func (portal->sessions, clear_session); + + /* This envvar is used for testing purposes. We do not count on it + * being set on real sessions, as the portal is an autostart service + * and inherits the session environment. If someone could change the + * session environment for malicious intents, this seems a smaller + * concern. + */ + portal->test_flatpak_info = g_strdup (g_getenv ("TRACKER_TEST_PORTAL_FLATPAK_INFO")); + unsetenv ("TRACKER_TEST_PORTAL_FLATPAK_INFO"); } static void @@ -196,7 +207,8 @@ endpoint_closed_cb (TrackerPortalEndpoint *endpoint, } static GStrv -load_client_configuration (GDBusMethodInvocation *invocation, +load_client_configuration (TrackerPortal *portal, + GDBusMethodInvocation *invocation, const gchar *service_uri, GError **error) { @@ -204,8 +216,18 @@ load_client_configuration (GDBusMethodInvocation *invocation, GError *inner_error = NULL; GStrv graphs; - flatpak_info = tracker_invocation_lookup_app_info_sync (invocation, - NULL, &inner_error); + if (portal->test_flatpak_info) { + flatpak_info = g_key_file_new (); + if (!g_key_file_load_from_file (flatpak_info, + portal->test_flatpak_info, + G_KEY_FILE_NONE, + &inner_error)) + g_clear_pointer (&flatpak_info, g_key_file_unref); + } else { + flatpak_info = tracker_invocation_lookup_app_info_sync (invocation, + NULL, &inner_error); + } + if (!flatpak_info) { GStrv default_graphs = { NULL }; @@ -275,7 +297,7 @@ portal_iface_method_call (GDBusConnection *connection, g_variant_get (parameters, "(s)", &uri); g_debug ("Creating session for service URI '%s'", uri); - graphs = load_client_configuration (invocation, uri, &error); + graphs = load_client_configuration (portal, invocation, uri, &error); if (!graphs) { g_debug ("Session rejected by policy"); g_dbus_method_invocation_return_gerror (invocation, error); |