aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2018-05-16 11:22:51 +0200
committerMichael Albinus2018-05-16 11:22:51 +0200
commit01120ec3d2eecd11e23f008feed020def7ea0e88 (patch)
tree0019f45ca3f7d35d8131abb6733a729e26cf08e9
parent4c3cd27df9c0735d907813a8c16a87acc54b9edc (diff)
downloademacs-01120ec3d2eecd11e23f008feed020def7ea0e88.tar.gz
emacs-01120ec3d2eecd11e23f008feed020def7ea0e88.zip
Fix creation of Secret Service items in auth-source
* 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.
-rw-r--r--lisp/auth-source.el5
-rw-r--r--lisp/net/secrets.el3
-rw-r--r--test/lisp/auth-source-tests.el10
-rw-r--r--test/lisp/net/secrets-tests.el11
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:
1733 (secret (plist-get artificial :secret)) 1733 (secret (plist-get artificial :secret))
1734 (secret (if (functionp secret) (funcall secret) secret))) 1734 (secret (if (functionp secret) (funcall secret) secret)))
1735 (lambda () 1735 (lambda ()
1736 (apply 'auth-source-secrets-saver collection item secret args)))) 1736 (auth-source-secrets-saver collection item secret args))))
1737 1737
1738 (list artificial))) 1738 (list artificial)))
1739 1739
@@ -1742,8 +1742,9 @@ authentication tokens:
1742Respects `auth-source-save-behavior'." 1742Respects `auth-source-save-behavior'."
1743 (let ((prompt (format "Save auth info to secrets collection %s? " collection)) 1743 (let ((prompt (format "Save auth info to secrets collection %s? " collection))
1744 (done (not (eq auth-source-save-behavior 'ask))) 1744 (done (not (eq auth-source-save-behavior 'ask)))
1745 (doit (eq auth-source-save-behavior t))
1745 (bufname "*auth-source Help*") 1746 (bufname "*auth-source Help*")
1746 doit k) 1747 k)
1747 (while (not done) 1748 (while (not done)
1748 (setq k (auth-source-read-char-choice prompt '(?y ?n ?N ??))) 1749 (setq k (auth-source-read-char-choice prompt '(?y ?n ?N ??)))
1749 (cl-case k 1750 (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."
575(defun secrets-get-items (collection-path) 575(defun secrets-get-items (collection-path)
576 "Return the object paths of all available items in COLLECTION-PATH." 576 "Return the object paths of all available items in COLLECTION-PATH."
577 (unless (secrets-empty-path collection-path) 577 (unless (secrets-empty-path collection-path)
578 (secrets-open-session)
579 (dbus-get-property 578 (dbus-get-property
580 :session secrets-service collection-path 579 :session secrets-service collection-path
581 secrets-interface-collection "Items"))) 580 secrets-interface-collection "Items")))
@@ -911,6 +910,8 @@ to their attributes."
911 910
912(when (dbus-ping :session secrets-service 100) 911(when (dbus-ping :session secrets-service 100)
913 912
913 (secrets-open-session)
914
914 ;; We must reset all variables, when there is a new instance of the 915 ;; We must reset all variables, when there is a new instance of the
915 ;; "org.freedesktop.secrets" service. 916 ;; "org.freedesktop.secrets" service.
916 (dbus-register-signal 917 (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 @@
292 ;; The "session" collection is temporary for the lifetime of the 292 ;; The "session" collection is temporary for the lifetime of the
293 ;; Emacs process. Therefore, we don't care to delete it. 293 ;; Emacs process. Therefore, we don't care to delete it.
294 (let ((auth-sources '((:source (:secrets "session")))) 294 (let ((auth-sources '((:source (:secrets "session"))))
295 (auth-source-save-behavior t)
295 (host (md5 (concat (prin1-to-string process-environment) 296 (host (md5 (concat (prin1-to-string process-environment)
296 (current-time-string)))) 297 (current-time-string))))
297 (passwd (md5 (concat (prin1-to-string process-environment) 298 (passwd (md5 (concat (prin1-to-string process-environment)
@@ -315,7 +316,14 @@
315 (funcall auth-passwd) 316 (funcall auth-passwd)
316 auth-passwd)) 317 auth-passwd))
317 (should (string-equal (plist-get auth-info :user) (user-login-name))) 318 (should (string-equal (plist-get auth-info :user) (user-login-name)))
318 (should (string-equal auth-passwd passwd)))) 319 (should (string-equal (plist-get auth-info :host) host))
320 (should (string-equal auth-passwd passwd))
321
322 ;; Cleanup.
323 ;; Should use `auth-source-delete' when implemented for :secrets backend.
324 (secrets-delete-item
325 "session"
326 (format "%s@%s" (plist-get auth-info :user) (plist-get auth-info :host)))))
319 327
320(provide 'auth-source-tests) 328(provide 'auth-source-tests)
321;;; auth-source-tests.el ends here 329;;; 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 @@
31 :expected-result (if secrets-enabled :passed :failed) 31 :expected-result (if secrets-enabled :passed :failed)
32 (should secrets-enabled) 32 (should secrets-enabled)
33 (should (dbus-ping :session secrets-service)) 33 (should (dbus-ping :session secrets-service))
34 ;; We do not test when there's an open session. 34
35 (should (secrets-empty-path secrets-session-path))) 35 ;; Exit.
36 (secrets--test-close-all-sessions))
36 37
37(defun secrets--test-get-all-sessions () 38(defun secrets--test-get-all-sessions ()
38 "Return all object paths for existing secrets sessions." 39 "Return all object paths for existing secrets sessions."
@@ -88,6 +89,8 @@
88 89
89 (unwind-protect 90 (unwind-protect
90 (progn 91 (progn
92 (should (secrets-open-session))
93
91 ;; There must be at least the collections "Login" and "session". 94 ;; There must be at least the collections "Login" and "session".
92 (should (member "Login" (secrets-list-collections))) 95 (should (member "Login" (secrets-list-collections)))
93 (should (member "session" (secrets-list-collections))) 96 (should (member "session" (secrets-list-collections)))
@@ -149,6 +152,8 @@
149 152
150 (unwind-protect 153 (unwind-protect
151 (let (item-path) 154 (let (item-path)
155 (should (secrets-open-session))
156
152 ;; There shall be no items in the "session" collection. 157 ;; There shall be no items in the "session" collection.
153 (should-not (secrets-list-items "session")) 158 (should-not (secrets-list-items "session"))
154 ;; There shall be items in the "Login" collection. 159 ;; There shall be items in the "Login" collection.
@@ -208,6 +213,8 @@
208 213
209 (unwind-protect 214 (unwind-protect
210 (progn 215 (progn
216 (should (secrets-open-session))
217
211 ;; There shall be no items in the "session" collection. 218 ;; There shall be no items in the "session" collection.
212 (should-not (secrets-list-items "session")) 219 (should-not (secrets-list-items "session"))
213 220