]> git.eshelyaron.com Git - emacs.git/commitdiff
Use 'auth-info-password' in tests
authorSam Steingold <sds@gnu.org>
Sun, 9 Jan 2022 23:30:25 +0000 (18:30 -0500)
committerSam Steingold <sds@gnu.org>
Tue, 11 Jan 2022 01:52:20 +0000 (20:52 -0500)
* test/lisp/auth-source-tests.el (auth-source-test-searches):
  (auth-source-test-secrets-create-secret):
  (auth-source-test-netrc-create-secret, auth-source-delete):
  Use 'auth-info-password' instead of ad hoc code.

test/lisp/auth-source-tests.el

index 7060d9570eb2193e2bf02f5527a390b6a3c62979..41f8b6d8c9dad6e0f33953435209a514a206f322 100644 (file)
             (setq found (apply #'auth-source-search parameters))
             (when (listp found)
               (dolist (f found)
-                (setf f (plist-put f :secret
-                                   (let ((secret (plist-get f :secret)))
-                                     (if (functionp secret)
-                                         (funcall secret)
-                                       secret))))))
+                (setf f (plist-put f :secret (auth-info-password f)))))
 
             (setq found-as-string (format "%s: %S" testname found))
             ;; (message "With parameters %S found: [%s] needed: [%s]"
                   auth-info
                   (car (auth-source-search
                         :max 1 :host host :require '(:user :secret) :create t))
-                 auth-passwd (plist-get auth-info :secret)
-                 auth-passwd (if (functionp auth-passwd)
-                                 (funcall auth-passwd)
-                               auth-passwd))
+                 auth-passwd (auth-info-password auth-info))
             (should (string-equal (plist-get auth-info :user) (user-login-name)))
             (should (string-equal (plist-get auth-info :host) host))
             (should (equal auth-passwd passwd))
             ;; 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))
+                 auth-passwd (auth-info-password auth-info))
             (if (zerop (length passwd))
                 (progn
                   (should-not (plist-get auth-info :user))
                 auth-info
                 (car (auth-source-search
                       :max 1 :host host :require '(:user :secret) :create t))
-                auth-passwd (plist-get auth-info :secret)
-                auth-passwd (if (functionp auth-passwd)
-                                (funcall auth-passwd)
-                              auth-passwd))
+                auth-passwd (auth-info-password auth-info))
           (should (string-equal (plist-get auth-info :user) (user-login-name)))
           (should (string-equal (plist-get auth-info :host) host))
           (should (equal auth-passwd passwd))
           (auth-source-forget+ :host t)
           (setq auth-source-netrc-cache nil)
           (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))
+                auth-passwd (auth-info-password auth-info))
           (with-temp-buffer
             (insert-file-contents netrc-file)
             (if (zerop (length passwd))
@@ -421,9 +405,7 @@ machine c1 port c2 user c3 password c4\n"
            (parameters '(:max 1 :host t))
            (found (apply #'auth-source-delete parameters)))
       (dolist (f found)
-        (let ((s (plist-get f :secret)))
-          (setf f (plist-put f :secret
-                             (if (functionp s) (funcall s) s)))))
+        (setf f (plist-put f :secret (auth-info-password f))))
       ;; Note: The netrc backend doesn't delete anything, so
       ;; this is actually the same as `auth-source-search'.
       (should (equal found expected)))))