[tracker/wip/carlosg/more-tests: 6/12] portal: Add testing envvar to override .flatpak-info
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/more-tests: 6/12] portal: Add testing envvar to override .flatpak-info
- Date: Tue, 29 Sep 2020 13:56:30 +0000 (UTC)
commit 8cf90cb7148d04abc42dd12b0fd0347f71f94a1d
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Sep 9 13:55:10 2020 +0200
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.
src/libtracker-sparql/bus/tracker-bus.vala | 51 +++++++++++++++---------------
src/portal/tracker-portal.c | 23 +++++++++++---
2 files changed, 45 insertions(+), 29 deletions(-)
---
diff --git a/src/libtracker-sparql/bus/tracker-bus.vala b/src/libtracker-sparql/bus/tracker-bus.vala
index e3cd3b2f7..86ac76089 100644
--- a/src/libtracker-sparql/bus/tracker-bus.vala
+++ b/src/libtracker-sparql/bus/tracker-bus.vala
@@ -49,37 +49,38 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
// ensure that error domain is registered with GDBus
new Sparql.Error.INTERNAL ("");
- var message = new DBusMessage.method_call (dbus_name, object_path, DBUS_PEER_IFACE, "Ping");
+ if (Environment.get_variable("TRACKER_TEST_PORTAL_FLATPAK_INFO") == null) {
+ var message = new DBusMessage.method_call (dbus_name, object_path, DBUS_PEER_IFACE,
"Ping");
- try {
- this.bus.send_message_with_reply_sync (message, 0, timeout, null).to_gerror();
- this.dbus_name = dbus_name;
- this.object_path = object_path;
- } catch (GLib.Error e) {
- if (GLib.FileUtils.test ("/.flatpak-info", GLib.FileTest.EXISTS)) {
- /* We are in a flatpak sandbox, check going through the portal */
-
- if (object_path == "/org/freedesktop/Tracker3/Endpoint")
- object_path = null;
+ try {
+ this.bus.send_message_with_reply_sync (message, 0, timeout, null).to_gerror();
+ this.dbus_name = dbus_name;
+ this.object_path = object_path;
+ return;
+ } catch (GLib.Error e) {
+ if (!GLib.FileUtils.test ("/.flatpak-info", GLib.FileTest.EXISTS)) {
+ throw e;
+ }
+ }
+ }
- string uri = Tracker.util_build_dbus_uri (GLib.BusType.SESSION, dbus_name,
object_path);
- message = new DBusMessage.method_call (PORTAL_NAME, PORTAL_PATH,
PORTAL_IFACE, "CreateSession");
- message.set_body (new Variant ("(s)", uri));
+ /* We are in a flatpak sandbox, check going through the portal */
+ if (object_path == "/org/freedesktop/Tracker3/Endpoint")
+ object_path = null;
- var reply = this.bus.send_message_with_reply_sync (message, 0, timeout, null);
+ string uri = Tracker.util_build_dbus_uri (GLib.BusType.SESSION, dbus_name, object_path);
+ var message = new DBusMessage.method_call (PORTAL_NAME, PORTAL_PATH, PORTAL_IFACE,
"CreateSession");
+ message.set_body (new Variant ("(s)", uri));
- reply.to_gerror();
+ var reply = this.bus.send_message_with_reply_sync (message, 0, timeout, null);
+ reply.to_gerror();
- var variant = reply.get_body ();
- variant.get_child(0, "o", out object_path);
+ var variant = reply.get_body ();
+ variant.get_child(0, "o", out object_path);
- this.dbus_name = PORTAL_NAME;
- this.object_path = object_path;
- this.sandboxed = true;
- } else {
- throw e;
- }
- }
+ this.dbus_name = PORTAL_NAME;
+ this.object_path = object_path;
+ this.sandboxed = true;
}
static void pipe (out UnixInputStream input, out UnixOutputStream output) throws IOError {
diff --git a/src/portal/tracker-portal.c b/src/portal/tracker-portal.c
index 2e58a7228..10165a0af 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,8 @@ tracker_portal_init (TrackerPortal *portal)
{
portal->sessions = g_array_new (FALSE, TRUE, sizeof (TrackerSession));
g_array_set_clear_func (portal->sessions, clear_session);
+ portal->test_flatpak_info = g_strdup (g_getenv ("TRACKER_TEST_PORTAL_FLATPAK_INFO"));
+ unsetenv ("TRACKER_TEST_PORTAL_FLATPAK_INFO");
}
static void
@@ -196,7 +200,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 +209,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 +290,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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]