From 01120ec3d2eecd11e23f008feed020def7ea0e88 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Wed, 16 May 2018 11:22:51 +0200 Subject: [PATCH] Fix creation of Secret Service items in auth-source MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * lisp/auth-source.el (auth-source-secrets-create): Use ´apply'. (auth-source-secrets-saver): Handle `auth-source-save-behavior' equal t. * lisp/net/secrets.el (secrets-get-items): Do not call `secrets-open-session' here ... (top): ... but here. * test/lisp/auth-source-tests.el (auth-source-test-secrets-create-secret): Bind `auth-source-save-behavior' to t. Cleanup. * test/lisp/net/secrets-tests.el (secrets-test00-availability): After loading secets.el, a session is already opened. (secrets-test02-collections, secrets-test03-items) (secrets-test04-search): Open a new session. --- lisp/auth-source.el | 5 +++-- lisp/net/secrets.el | 3 ++- test/lisp/auth-source-tests.el | 10 +++++++++- test/lisp/net/secrets-tests.el | 11 +++++++++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lisp/auth-source.el b/lisp/auth-source.el index 8b54c8118d2..918d785eaef 100644 --- a/lisp/auth-source.el +++ b/lisp/auth-source.el @@ -1733,7 +1733,7 @@ authentication tokens: (secret (plist-get artificial :secret)) (secret (if (functionp secret) (funcall secret) secret))) (lambda () - (apply 'auth-source-secrets-saver collection item secret args)))) + (auth-source-secrets-saver collection item secret args)))) (list artificial))) @@ -1742,8 +1742,9 @@ authentication tokens: Respects `auth-source-save-behavior'." (let ((prompt (format "Save auth info to secrets collection %s? " collection)) (done (not (eq auth-source-save-behavior 'ask))) + (doit (eq auth-source-save-behavior t)) (bufname "*auth-source Help*") - doit k) + k) (while (not done) (setq k (auth-source-read-char-choice prompt '(?y ?n ?N ??))) (cl-case k diff --git a/lisp/net/secrets.el b/lisp/net/secrets.el index 22a4e8c7b0a..45c98cae60d 100644 --- a/lisp/net/secrets.el +++ b/lisp/net/secrets.el @@ -575,7 +575,6 @@ If successful, return the object path of the collection." (defun secrets-get-items (collection-path) "Return the object paths of all available items in COLLECTION-PATH." (unless (secrets-empty-path collection-path) - (secrets-open-session) (dbus-get-property :session secrets-service collection-path secrets-interface-collection "Items"))) @@ -911,6 +910,8 @@ to their attributes." (when (dbus-ping :session secrets-service 100) + (secrets-open-session) + ;; We must reset all variables, when there is a new instance of the ;; "org.freedesktop.secrets" service. (dbus-register-signal diff --git a/test/lisp/auth-source-tests.el b/test/lisp/auth-source-tests.el index 2f5a9320b17..1f6737cb7c8 100644 --- a/test/lisp/auth-source-tests.el +++ b/test/lisp/auth-source-tests.el @@ -292,6 +292,7 @@ ;; The "session" collection is temporary for the lifetime of the ;; Emacs process. Therefore, we don't care to delete it. (let ((auth-sources '((:source (:secrets "session")))) + (auth-source-save-behavior t) (host (md5 (concat (prin1-to-string process-environment) (current-time-string)))) (passwd (md5 (concat (prin1-to-string process-environment) @@ -315,7 +316,14 @@ (funcall auth-passwd) auth-passwd)) (should (string-equal (plist-get auth-info :user) (user-login-name))) - (should (string-equal auth-passwd passwd)))) + (should (string-equal (plist-get auth-info :host) host)) + (should (string-equal auth-passwd passwd)) + + ;; Cleanup. + ;; Should use `auth-source-delete' when implemented for :secrets backend. + (secrets-delete-item + "session" + (format "%s@%s" (plist-get auth-info :user) (plist-get auth-info :host))))) (provide 'auth-source-tests) ;;; auth-source-tests.el ends here diff --git a/test/lisp/net/secrets-tests.el b/test/lisp/net/secrets-tests.el index fcc3a2d3e6e..9a61bca4351 100644 --- a/test/lisp/net/secrets-tests.el +++ b/test/lisp/net/secrets-tests.el @@ -31,8 +31,9 @@ :expected-result (if secrets-enabled :passed :failed) (should secrets-enabled) (should (dbus-ping :session secrets-service)) - ;; We do not test when there's an open session. - (should (secrets-empty-path secrets-session-path))) + + ;; Exit. + (secrets--test-close-all-sessions)) (defun secrets--test-get-all-sessions () "Return all object paths for existing secrets sessions." @@ -88,6 +89,8 @@ (unwind-protect (progn + (should (secrets-open-session)) + ;; There must be at least the collections "Login" and "session". (should (member "Login" (secrets-list-collections))) (should (member "session" (secrets-list-collections))) @@ -149,6 +152,8 @@ (unwind-protect (let (item-path) + (should (secrets-open-session)) + ;; There shall be no items in the "session" collection. (should-not (secrets-list-items "session")) ;; There shall be items in the "Login" collection. @@ -208,6 +213,8 @@ (unwind-protect (progn + (should (secrets-open-session)) + ;; There shall be no items in the "session" collection. (should-not (secrets-list-items "session")) -- 2.39.5