From b88e0d4ca7e3082aefbc0f8b6b47fc738990908c Mon Sep 17 00:00:00 2001 From: Pierre Labastie Date: Wed, 7 Feb 2024 17:43:02 +0100 Subject: [PATCH 1/2] Fix test failures on non gnome-terminal in GNOME Because programs running in a non gnome-terminal belong to a .scope unit starting with app, xdg-desktop-portal assings a non empty appid to them. On the other hand, for setting permissions into the permission store, tests assume that appid is the empty string. To fix this, retrieve the appid during global setup a,d store it in a global variable. It is then available to tests, and can be passed when setting permissions. Fix 3 test failures out of 5 reported in #1278 The other failures are in python tests. Signed-off-by: Pierre Labastie --- tests/camera.c | 3 ++- tests/inhibit.c | 3 ++- tests/limited-portals.c | 7 +++++++ tests/test-portals.c | 7 +++++++ tests/wallpaper.c | 3 ++- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/camera.c b/tests/camera.c index c590af944..dafa8f964 100644 --- a/tests/camera.c +++ b/tests/camera.c @@ -14,6 +14,7 @@ static int got_info; extern XdpDbusImplPermissionStore *permission_store; extern XdpDbusImplLockdown *lockdown; +extern gchar *appid; static void set_camera_permissions (const char *permission) @@ -26,7 +27,7 @@ set_camera_permissions (const char *permission) "devices", TRUE, "camera", - "", + appid, permissions, NULL, &error); diff --git a/tests/inhibit.c b/tests/inhibit.c index 473c96441..e171eddb2 100644 --- a/tests/inhibit.c +++ b/tests/inhibit.c @@ -8,6 +8,7 @@ extern char outdir[]; extern XdpDbusImplPermissionStore *permission_store; +extern gchar *appid; static void set_inhibit_permissions (const char **permissions) @@ -18,7 +19,7 @@ set_inhibit_permissions (const char **permissions) "inhibit", TRUE, "inhibit", - "", + appid, permissions, NULL, &error); diff --git a/tests/limited-portals.c b/tests/limited-portals.c index 32deceb5e..1a9ce7103 100644 --- a/tests/limited-portals.c +++ b/tests/limited-portals.c @@ -52,6 +52,7 @@ static GDBusConnection *session_bus; static GList *test_procs = NULL; XdpDbusImplPermissionStore *permission_store; XdpDbusImplLockdown *lockdown; +gchar *appid; int xdup (int oldfd) @@ -137,6 +138,7 @@ global_setup (void) g_autofree gchar *argv0 = NULL; g_autoptr(GSubprocessLauncher) launcher = NULL; g_autoptr(GSubprocess) subprocess = NULL; + g_autoptr(XdpAppInfo) appinfo = NULL; guint name_timeout; const char *argv[4]; GQuark portal_errors G_GNUC_UNUSED; @@ -318,6 +320,10 @@ global_setup (void) &error); g_assert_no_error (error); + appinfo = xdp_get_app_info_from_pid (getpid (), &error); + g_assert_no_error (error); + appid = g_strdup (xdp_app_info_get_id (appinfo)); + /* make sure errors are registered */ portal_errors = XDG_DESKTOP_PORTAL_ERROR; } @@ -374,6 +380,7 @@ global_teardown (void) g_object_unref (lockdown); g_object_unref (permission_store); + g_free (appid); g_object_unref (session_bus); diff --git a/tests/test-portals.c b/tests/test-portals.c index 7b59064f7..40c5a95e6 100644 --- a/tests/test-portals.c +++ b/tests/test-portals.c @@ -51,6 +51,7 @@ static GDBusConnection *session_bus; static GList *test_procs = NULL; XdpDbusImplPermissionStore *permission_store; XdpDbusImplLockdown *lockdown; +gchar *appid; int xdup (int oldfd) @@ -136,6 +137,7 @@ global_setup (void) g_autofree gchar *argv0 = NULL; g_autoptr(GSubprocessLauncher) launcher = NULL; g_autoptr(GSubprocess) subprocess = NULL; + g_autoptr(XdpAppInfo) appinfo = NULL; guint name_timeout; const char *argv[4]; GQuark portal_errors G_GNUC_UNUSED; @@ -331,6 +333,10 @@ global_setup (void) &error); g_assert_no_error (error); + appinfo = xdp_get_app_info_from_pid (getpid (), &error); + g_assert_no_error (error); + appid = g_strdup (xdp_app_info_get_id (appinfo)); + /* make sure errors are registered */ portal_errors = XDG_DESKTOP_PORTAL_ERROR; } @@ -387,6 +393,7 @@ global_teardown (void) g_object_unref (lockdown); g_object_unref (permission_store); + g_free (appid); g_object_unref (session_bus); diff --git a/tests/wallpaper.c b/tests/wallpaper.c index d6fdc180c..d2ca2e140 100644 --- a/tests/wallpaper.c +++ b/tests/wallpaper.c @@ -10,6 +10,7 @@ extern char outdir[]; static int got_info = 0; extern XdpDbusImplPermissionStore *permission_store; +extern gchar *appid; static void set_wallpaper_permissions (const char *permission) @@ -22,7 +23,7 @@ set_wallpaper_permissions (const char *permission) "wallpaper", TRUE, "wallpaper", - "", + appid, permissions, NULL, &error); From fe4995af7aede787acaf7df44faed492f9d93ca8 Mon Sep 17 00:00:00 2001 From: Pierre Labastie Date: Wed, 7 Feb 2024 18:03:47 +0100 Subject: [PATCH 2/2] Fix tests running in non gnome-terminal in GNOME Python tests assume that the appid is an empty string, which may be false when running tests on GNOME in a non gnome-terminal. Therefore, asserting that the appid is empty leads to an error. To fix this, just remove the asserts. They don't test anything since there is no independant way to retrieve the appid. Fix the remaining failures reported in #1278 Signed-off-by: Pierre Labastie --- tests/test_globalshortcuts.py | 4 ++-- tests/test_remotedesktop.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_globalshortcuts.py b/tests/test_globalshortcuts.py index 56349cb66..84842c343 100644 --- a/tests/test_globalshortcuts.py +++ b/tests/test_globalshortcuts.py @@ -38,7 +38,7 @@ def test_global_shortcuts_create_close_session(self, portal_mock): assert len(method_calls) > 0 _, args = method_calls[-1] assert args[1] == session.handle - assert args[2] == "" # appid +# assert args[2] == "" # appid, not necessary empty session.close() @@ -67,7 +67,7 @@ def test_global_shortcuts_create_session_signal_closed(self, portal_mock): assert len(method_calls) > 0 _, args = method_calls[-1] assert args[1] == session.handle - assert args[2] == "" # appid +# assert args[2] == "" # appid, not necessary empty # Now expect the backend to close it diff --git a/tests/test_remotedesktop.py b/tests/test_remotedesktop.py index 49b6b1884..893e937fd 100644 --- a/tests/test_remotedesktop.py +++ b/tests/test_remotedesktop.py @@ -38,7 +38,7 @@ def test_remote_desktop_create_close_session(self, portal_mock): assert len(method_calls) > 0 _, args = method_calls[-1] assert args[1] == session.handle - assert args[2] == "" # appid +# assert args[2] == "" # appid, not necessary empty session.close() @@ -67,7 +67,7 @@ def test_remote_desktop_create_session_signal_closed(self, portal_mock): assert len(method_calls) > 0 _, args = method_calls[-1] assert args[1] == session.handle - assert args[2] == "" # appid +# assert args[2] == "" # appid, not necessary empty # Now expect the backend to close it