test/monitor: Assert that BecomeMonitor() on wrong object path fails
authorSimon McVittie <smcv@collabora.com>
Wed, 31 May 2017 17:00:40 +0000 (18:00 +0100)
committerSimon McVittie <smcv@collabora.com>
Fri, 2 Jun 2017 09:38:30 +0000 (10:38 +0100)
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101256

test/monitor.c

index 0402d4a..71ae2ae 100644 (file)
@@ -601,6 +601,49 @@ test_invalid (Fixture *f,
   g_assert_cmpstr (dbus_message_get_error_name (m), ==,
       DBUS_ERROR_INVALID_ARGS);
 
+  /* Try to become a monitor but use the wrong object path - not allowed
+   * (security hardening against inappropriate XML policy rules) */
+
+  dbus_pending_call_unref (pc);
+  dbus_message_unref (m);
+
+  m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
+      "/", DBUS_INTERFACE_MONITORING, "BecomeMonitor");
+
+  if (m == NULL)
+    g_error ("OOM");
+
+  dbus_message_iter_init_append (m, &appender);
+
+  if (!dbus_message_iter_open_container (&appender, DBUS_TYPE_ARRAY, "s",
+        &array_appender))
+    g_error ("OOM");
+
+  if (!dbus_message_iter_close_container (&appender, &array_appender) ||
+      !dbus_message_iter_append_basic (&appender, DBUS_TYPE_UINT32, &zero))
+    g_error ("OOM");
+
+  if (!dbus_connection_send_with_reply (f->monitor, m, &pc,
+        DBUS_TIMEOUT_USE_DEFAULT) ||
+      pc == NULL)
+    g_error ("OOM");
+
+  dbus_message_unref (m);
+  m = NULL;
+
+  if (dbus_pending_call_get_completed (pc))
+    test_pending_call_store_reply (pc, &m);
+  else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
+        &m, NULL))
+    g_error ("OOM");
+
+  while (m == NULL)
+    test_main_context_iterate (f->ctx, TRUE);
+
+  g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_ERROR);
+  g_assert_cmpstr (dbus_message_get_error_name (m), ==,
+      DBUS_ERROR_ACCESS_DENIED);
+
   /* Try to become a monitor but specify a bad match rule -
    * also not allowed */