From 7c2b58b6224621dfde4658f3a43df9905245ed00 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Wed, 10 Jul 2024 09:50:09 +0200 Subject: [PATCH] Extend dbus-test04-call-method-authorizable * test/lisp/net/dbus-tests.el (dbus--test-method-authorizable-handler): New defun. (dbus-test04-call-method-authorizable): Extend test. (cherry picked from commit a29a385ee5ea938ed17d94622c7bfd0a10e84830) --- test/lisp/net/dbus-tests.el | 99 ++++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 23 deletions(-) diff --git a/test/lisp/net/dbus-tests.el b/test/lisp/net/dbus-tests.el index 054e1333b60..eb6fc5c28cf 100644 --- a/test/lisp/net/dbus-tests.el +++ b/test/lisp/net/dbus-tests.el @@ -732,37 +732,90 @@ is in progress." ;; Cleanup. (dbus-unregister-service :session dbus--test-service))) +(defun dbus--test-method-authorizable-handler (&rest args) + "Method handler for `dbus-test04-call-method-authorizable'. +Returns the respective error." + `(:error ,dbus-error-interactive-authorization-required + "Interactive authentication required.")) + (ert-deftest dbus-test04-call-method-authorizable () "Verify `dbus-call-method' request authorizable." :tags '(:expensive-test) (skip-unless dbus--test-enabled-session-bus) - (skip-unless - (dbus-ignore-errors - (dbus-call-method - :session dbus-service-dbus dbus-path-dbus - dbus-interface-dbus "ListNames"))) + (dbus-ignore-errors (dbus-unregister-service :session dbus--test-service)) + (dbus-register-service :session dbus--test-service) - (should - (dbus-call-method - :session dbus-service-dbus dbus-path-dbus - dbus-interface-dbus "ListNames" :authorizable t)) + (unwind-protect + (let ((method "Method") + (handler #'dbus--test-method-authorizable-handler) + registered) - (should - (dbus-call-method - :session dbus-service-dbus dbus-path-dbus - dbus-interface-dbus "ListNames" :authorizable nil)) + ;; Register. + (should + (equal + (setq + registered + (dbus-register-method + :session dbus--test-service dbus--test-path + dbus--test-interface method handler)) + `((:method :session ,dbus--test-interface ,method) + (,dbus--test-service ,dbus--test-path ,handler)))) - (should - (dbus-call-method - :session dbus-service-dbus dbus-path-dbus - dbus-interface-dbus "ListNames" :authorizable 'something)) + ;; The error isn't seen, because it is transformed into a + ;; warning. So we check, whether a warning has arrived in the + ;; respective buffer. + (ignore-errors (kill-buffer "*Warnings*")) + (should-not + (dbus-call-method + :session dbus--test-service dbus--test-path + dbus--test-interface method "foo")) + (should (get-buffer "*Warnings*")) - ;; Only method calls are allowed for :authorizable. - (should-error - (dbus-send-signal - :session dbus--test-service dbus--test-path - dbus--test-interface "Foo" :authorizable t "foo") - :type 'dbus-error)) + ;; The same for asynchronous calls. + (ignore-errors (kill-buffer "*Warnings*")) + (dbus-call-method-asynchronously + :session dbus--test-service dbus--test-path + dbus--test-interface method #'ignore "foo") + (with-timeout (1 (dbus--test-timeout-handler)) + (while (null (get-buffer "*Warnings*")) + (read-event nil nil 0.1))) + (should (get-buffer "*Warnings*")) + + ;; Unregister method. + (should (dbus-unregister-object registered)) + (should-not (dbus-unregister-object registered))) + + ;; Cleanup. + (ignore-errors (kill-buffer "*Warnings*")) + (dbus-unregister-service :session dbus--test-service)) + + ;; Check parsing. "org.freedesktop.DBus.ListNames" is agnostic to + ;; :authorizable, so we can use it as test method. + (unless (dbus-ignore-errors + (dbus-call-method + :session dbus-service-dbus dbus-path-dbus + dbus-interface-dbus "ListNames")) + (should + (dbus-call-method + :session dbus-service-dbus dbus-path-dbus + dbus-interface-dbus "ListNames" :authorizable t)) + + (should + (dbus-call-method + :session dbus-service-dbus dbus-path-dbus + dbus-interface-dbus "ListNames" :authorizable nil)) + + (should + (dbus-call-method + :session dbus-service-dbus dbus-path-dbus + dbus-interface-dbus "ListNames" :authorizable 'something)) + + ;; Only method calls are allowed for :authorizable. + (should-error + (dbus-send-signal + :session dbus--test-service dbus--test-path + dbus--test-interface "Foo" :authorizable t "foo") + :type 'dbus-error))) (defvar dbus--test-event-expected nil "The expected event in `dbus--test-signal-handler'.") -- 2.39.2