From ff9878576a6826e13567049629451d494afd8c9c Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Thu, 10 Nov 2022 19:09:38 -0800 Subject: [PATCH 0/2] *** NOT A PATCH *** *** BLURB HERE *** F. Jason Park (2): [POC] Make auth-source-pass behave more like other backends [POC] Support auth-source-pass in ERC doc/misc/auth.texi | 11 ++ doc/misc/erc.texi | 3 +- etc/NEWS | 8 ++ lisp/auth-source-pass.el | 105 +++++++++++++++- lisp/erc/erc-compat.el | 99 +++++++++++++++ lisp/erc/erc.el | 7 +- test/lisp/auth-source-pass-tests.el | 184 ++++++++++++++++++++++++++++ test/lisp/erc/erc-services-tests.el | 3 - 8 files changed, 414 insertions(+), 6 deletions(-) Interdiff: diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index 8d7241eb1a..54070e03eb 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -130,15 +130,13 @@ auth-source-pass--build-result-many require (or max 1)))) (when auth-source-debug (auth-source-pass--do-debug "final result: %S" rv)) - (if (eq auth-source-pass-extra-query-keywords '--test--) - (reverse rv) - (let (out) - (dolist (e rv out) - (when-let* ((s (plist-get e :secret)) ; s not captured by closure - (v (auth-source--obfuscate s))) - (setf (plist-get e :secret) - (lambda () (auth-source--deobfuscate v)))) - (push e out)))))) + (let (out) + (dolist (e rv out) + (when-let* ((s (plist-get e :secret)) ; s not captured by closure + (v (auth-source--obfuscate s))) + (setf (plist-get e :secret) + (lambda () (auth-source--deobfuscate v)))) + (push e out))))) ;;;###autoload (defun auth-source-pass-enable () diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index 1839801546..60903808e0 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -504,16 +504,18 @@ auth-source-pass-extra-query-keywords--wild-port-miss-netrc (auth-source-do-cache nil) (results (auth-source-search :host "x.com" :port 22 :max 2))) (dolist (result results) - (setf result (plist-put result :secret (auth-info-password result)))) + (setf (plist-get result :secret) (auth-info-password result))) (should (equal results '((:host "x.com" :secret "a"))))))) (ert-deftest auth-source-pass-extra-query-keywords--wild-port-miss () - (let ((auth-source-pass-extra-query-keywords '--test--)) - (auth-source-pass--with-store '(("x.com" (secret . "a")) - ("x.com:42" (secret . "b"))) - (auth-source-pass-enable) - (should (equal (auth-source-search :host "x.com" :port 22 :max 2) - '((:host "x.com" :secret "a"))))))) + (auth-source-pass--with-store '(("x.com" (secret . "a")) + ("x.com:42" (secret . "b"))) + (auth-source-pass-enable) + (let* ((auth-source-pass-extra-query-keywords t) + (results (auth-source-search :host "x.com" :port 22 :max 2))) + (dolist (result results) + (setf (plist-get result :secret) (auth-info-password result))) + (should (equal results '((:host "x.com" :secret "a"))))))) ;; One of two entries has the requested port, both returned @@ -527,16 +529,19 @@ auth-source-pass-extra-query-keywords--wild-port-hit-netrc (auth-source-do-cache nil) (results (auth-source-search :host "x.com" :port 42 :max 2))) (dolist (result results) - (setf result (plist-put result :secret (auth-info-password result)))) + (setf (plist-get result :secret) (auth-info-password result))) (should (equal results '((:host "x.com" :secret "a") (:host "x.com" :port "42" :secret "b"))))))) (ert-deftest auth-source-pass-extra-query-keywords--wild-port-hit () - (let ((auth-source-pass-extra-query-keywords '--test--)) - (auth-source-pass--with-store '(("x.com" (secret . "a")) - ("x.com:42" (secret . "b"))) - (auth-source-pass-enable) - (should (equal (auth-source-search :host "x.com" :port 42 :max 2) + (auth-source-pass--with-store '(("x.com" (secret . "a")) + ("x.com:42" (secret . "b"))) + (auth-source-pass-enable) + (let* ((auth-source-pass-extra-query-keywords t) + (results (auth-source-search :host "x.com" :port 42 :max 2))) + (dolist (result results) + (setf (plist-get result :secret) (auth-info-password result))) + (should (equal results '((:host "x.com" :secret "a") (:host "x.com" :port 42 :secret "b"))))))) @@ -555,7 +560,7 @@ auth-source-pass-extra-query-keywords--wild-port-req-miss-netrc (should-not results)))) (ert-deftest auth-source-pass-extra-query-keywords--wild-port-req-miss () - (let ((auth-source-pass-extra-query-keywords '--test--)) + (let ((auth-source-pass-extra-query-keywords t)) (auth-source-pass--with-store '(("x.com" (secret . "a")) ("x.com:42" (secret . "b"))) (auth-source-pass-enable) @@ -577,17 +582,20 @@ auth-source-pass-extra-query-keywords--netrc-akib (auth-source-do-cache nil) (results (auth-source-search :host "disroot.org" :max 2))) (dolist (result results) - (setf result (plist-put result :secret (auth-info-password result)))) + (setf (plist-get result :secret) (auth-info-password result))) (should (equal results '((:host "disroot.org" :user "akib" :secret "b"))))))) (ert-deftest auth-source-pass-extra-query-keywords--akib () - (let ((auth-source-pass-extra-query-keywords '--test--)) - (auth-source-pass--with-store '(("x.com" (secret . "a")) - ("akib@disroot.org" (secret . "b")) - ("z.com" (secret . "c"))) - (auth-source-pass-enable) - (should (equal (auth-source-search :host "disroot.org" :max 2) + (auth-source-pass--with-store '(("x.com" (secret . "a")) + ("akib@disroot.org" (secret . "b")) + ("z.com" (secret . "c"))) + (auth-source-pass-enable) + (let* ((auth-source-pass-extra-query-keywords t) + (results (auth-source-search :host "disroot.org" :max 2))) + (dolist (result results) + (setf (plist-get result :secret) (auth-info-password result))) + (should (equal results '((:host "disroot.org" :user "akib" :secret "b"))))))) ;; Searches for :host are case-sensitive, and a returned host isn't @@ -603,15 +611,18 @@ auth-source-pass-extra-query-keywords--netrc-host (auth-source-do-cache nil) (results (auth-source-search :host "Libera.Chat" :max 2))) (dolist (result results) - (setf result (plist-put result :secret (auth-info-password result)))) + (setf (plist-get result :secret) (auth-info-password result))) (should (equal results '((:host "Libera.Chat" :secret "b"))))))) (ert-deftest auth-source-pass-extra-query-keywords--host () - (let ((auth-source-pass-extra-query-keywords '--test--)) - (auth-source-pass--with-store '(("libera.chat" (secret . "a")) - ("Libera.Chat" (secret . "b"))) - (auth-source-pass-enable) - (should (equal (auth-source-search :host "Libera.Chat" :max 2) + (auth-source-pass--with-store '(("libera.chat" (secret . "a")) + ("Libera.Chat" (secret . "b"))) + (auth-source-pass-enable) + (let* ((auth-source-pass-extra-query-keywords t) + (results (auth-source-search :host "Libera.Chat" :max 2))) + (dolist (result results) + (setf (plist-get result :secret) (auth-info-password result))) + (should (equal results '((:host "Libera.Chat" :secret "b"))))))) @@ -619,7 +630,7 @@ auth-source-pass-extra-query-keywords--host ;; path contains port or user components (ert-deftest auth-source-pass-extra-query-keywords--baseline () - (let ((auth-source-pass-extra-query-keywords '--test--)) + (let ((auth-source-pass-extra-query-keywords t)) (auth-source-pass--with-store '(("x.com")) (auth-source-pass-enable) (should-not (auth-source-search :host "x.com"))))) @@ -627,14 +638,15 @@ auth-source-pass-extra-query-keywords--baseline ;; Output port type (int or string) matches that of input parameter (ert-deftest auth-source-pass-extra-query-keywords--port-type () - (let ((auth-source-pass-extra-query-keywords '--test--)) + (let ((auth-source-pass-extra-query-keywords t) + (f (lambda (r) (setf (plist-get r :secret) (auth-info-password r)) r))) (auth-source-pass--with-store '(("x.com:42" (secret . "a"))) (auth-source-pass-enable) - (should (equal (auth-source-search :host "x.com" :port 42) + (should (equal (mapcar f (auth-source-search :host "x.com" :port 42)) '((:host "x.com" :port 42 :secret "a"))))) (auth-source-pass--with-store '(("x.com:42" (secret . "a"))) (auth-source-pass-enable) - (should (equal (auth-source-search :host "x.com" :port "42") + (should (equal (mapcar f (auth-source-search :host "x.com" :port "42")) '((:host "x.com" :port "42" :secret "a"))))))) ;; The :host search param ordering more heavily influences the output @@ -643,14 +655,17 @@ auth-source-pass-extra-query-keywords--port-type ;; returned in the order encountered (ert-deftest auth-source-pass-extra-query-keywords--hosts-first () - (let ((auth-source-pass-extra-query-keywords '--test--)) - (auth-source-pass--with-store '(("x.com:42/bar" (secret . "a")) - ("gnu.org" (secret . "b")) - ("x.com" (secret . "c")) - ("fake.com" (secret . "d")) - ("x.com/foo" (secret . "e"))) - (auth-source-pass-enable) - (should (equal (auth-source-search :host '("x.com" "gnu.org") :max 3) + (auth-source-pass--with-store '(("x.com:42/bar" (secret . "a")) + ("gnu.org" (secret . "b")) + ("x.com" (secret . "c")) + ("fake.com" (secret . "d")) + ("x.com/foo" (secret . "e"))) + (auth-source-pass-enable) + (let* ((auth-source-pass-extra-query-keywords t) + (results (auth-source-search :host '("x.com" "gnu.org") :max 3))) + (dolist (result results) + (setf (plist-get result :secret) (auth-info-password result))) + (should (equal results ;; Notice gnu.org is never considered ^ '((:host "x.com" :user "bar" :port "42" :secret "a") (:host "x.com" :secret "c") -- 2.38.1