[glib: 4/5] tests: Add a basic test for require-same-user D-Bus auth flag




commit 2f91caf77e7e13222373f0c5e8aec617b8e1cffa
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Jan 14 18:03:35 2021 +0000

    tests: Add a basic test for require-same-user D-Bus auth flag
    
    It’s not feasible to test that the require-same-user flag can cause
    authentication to fail, as that would require the build environment to
    have two users available. We can, however, test that it passes when
    authenticating a client and server running under the same user account.
    
    I have manually tested that the new flag works, by running the following
    as user A:
    ```
    `$prefix/gdbus-daemon --print-env &`
    gdbus call --session --dest org.freedesktop.DBus --object-path /org/freedesktop/DBus --method 
org.freedesktop.DBus.ListNames
    ```
    
    And then running the `gdbus call` command again as user B (with the same
    value for `DBUS_SESSION_BUS_ADDRESS` in the environment), which
    produces:
    ```
    Error connecting: Unexpected lack of content trying to read a line
    ```
    (an authentication rejection)
    
    Commenting out the use of
    `G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER` from
    `gdbusdaemon.c`, the `gdbus call` command succeeds for both users.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 gio/tests/gdbus-server-auth.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
---
diff --git a/gio/tests/gdbus-server-auth.c b/gio/tests/gdbus-server-auth.c
index b3ee8aab2..bd1443eb1 100644
--- a/gio/tests/gdbus-server-auth.c
+++ b/gio/tests/gdbus-server-auth.c
@@ -37,6 +37,7 @@ typedef enum
   INTEROP_FLAGS_TCP = (1 << 3),
   INTEROP_FLAGS_LIBDBUS = (1 << 4),
   INTEROP_FLAGS_ABSTRACT = (1 << 5),
+  INTEROP_FLAGS_REQUIRE_SAME_USER = (1 << 6),
   INTEROP_FLAGS_NONE = 0
 } InteropFlags;
 
@@ -325,6 +326,8 @@ do_test_server_auth (InteropFlags flags)
 
   if (flags & INTEROP_FLAGS_ANONYMOUS)
     server_flags |= G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS;
+  if (flags & INTEROP_FLAGS_REQUIRE_SAME_USER)
+    server_flags |= G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER;
 
   observer = g_dbus_auth_observer_new ();
 
@@ -513,6 +516,12 @@ test_server_auth_external (void)
   do_test_server_auth (INTEROP_FLAGS_EXTERNAL);
 }
 
+static void
+test_server_auth_external_require_same_user (void)
+{
+  do_test_server_auth (INTEROP_FLAGS_EXTERNAL | INTEROP_FLAGS_REQUIRE_SAME_USER);
+}
+
 static void
 test_server_auth_sha1 (void)
 {
@@ -537,6 +546,7 @@ main (int   argc,
   g_test_add_func ("/gdbus/server-auth/anonymous", test_server_auth_anonymous);
   g_test_add_func ("/gdbus/server-auth/anonymous/tcp", test_server_auth_anonymous_tcp);
   g_test_add_func ("/gdbus/server-auth/external", test_server_auth_external);
+  g_test_add_func ("/gdbus/server-auth/external/require-same-user", 
test_server_auth_external_require_same_user);
   g_test_add_func ("/gdbus/server-auth/sha1", test_server_auth_sha1);
   g_test_add_func ("/gdbus/server-auth/sha1/tcp", test_server_auth_sha1_tcp);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]