Fix Bug#30246

* lisp/auth-source.el (auth-source-secrets-search): Do not
suppress creation.
(auth-source-secrets-create): Implement it.  (Bug#30246)

* lisp/net/secrets.el (secrets-debug): Set default to nil.

* test/lisp/auth-source-tests.el (secrets): Require it.
(auth-source-test-secrets-create-secret): New test.
This commit is contained in:
Michael Albinus 2018-04-13 15:21:24 +02:00
parent 9822a6a570
commit 1f31c1348c
3 changed files with 192 additions and 11 deletions

View file

@ -29,9 +29,7 @@
(require 'ert)
(require 'cl-lib)
(require 'auth-source)
(defvar secrets-enabled t
"Enable the secrets backend to test its features.")
(require 'secrets)
(defun auth-source-ensure-ignored-backend (source)
(auth-source-validate-backend source '((:source . "")
@ -289,5 +287,35 @@
(should (equal found-as-string (concat testname ": " needed)))))
(delete-file netrc-file)))
(ert-deftest auth-source-test-secrets-create-secret ()
(skip-unless secrets-enabled)
;; 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"))))
(host (md5 (concat (prin1-to-string process-environment)
(current-time-string))))
(passwd (md5 (concat (prin1-to-string process-environment)
(current-time-string) (current-time-string))))
auth-info auth-passwd)
;; Redefine `read-*' in order to avoid interactive input.
(cl-letf (((symbol-function 'read-passwd) (lambda (_) passwd))
((symbol-function 'read-string)
(lambda (_prompt _initial _history default) default)))
(setq auth-info
(car (auth-source-search
:max 1 :host host :require '(:user :secret) :create t))))
(should (functionp (plist-get auth-info :save-function)))
(funcall (plist-get auth-info :save-function))
;; Check, that the item has been created indeed.
(auth-source-forget+ :host t)
(setq auth-info (car (auth-source-search :host host))
auth-passwd (plist-get auth-info :secret)
auth-passwd (if (functionp auth-passwd)
(funcall auth-passwd)
auth-passwd))
(should (string-equal (plist-get auth-info :user) (user-login-name)))
(should (string-equal auth-passwd passwd))))
(provide 'auth-source-tests)
;;; auth-source-tests.el ends here