From 89ec2fd5ba7d3d276cb18d1d256080aff9f2ab77 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Fri, 18 Nov 2022 19:59:11 -0800 Subject: [PATCH 0/1] *** NOT A PATCH *** *** BLURB HERE *** F. Jason Park (1): [POC] Allow subdomain matching in auth-source-pass--find-match-many doc/misc/auth.texi | 11 ++--- etc/NEWS | 3 +- lisp/auth-source-pass.el | 20 ++++++--- test/lisp/auth-source-pass-tests.el | 67 +++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 11 deletions(-) Interdiff: diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index d0b7acb931..2501a1ca85 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -65,8 +65,10 @@ auth-source-pass-extra-query-keywords filtering unless given an applicable `:require' argument. When this option is nil, do none of that, and enact the narrowing behavior described toward the bottom of the Info node `(auth) The -Unix password store'." - :type 'boolean +Unix password store'. With a value of `match-domains', this +option behaves as it does when set to t except that subdomain +matching is enabled." + :type '(choice (const nil) (const t) (const match-domains)) :version "29.1") (cl-defun auth-source-pass-search (&rest spec @@ -278,13 +280,11 @@ auth-source-pass--match-parts (or (not value) (not mv) (equal mv value))))) (defun auth-source-pass--match-host (search-param matched-path) - (pcase search-param - ((rx "." (+ (not ".")) "." (>= 2 alpha) eot) - (string-suffix-p matched-path search-param)) - (_ (equal matched-path search-param)))) - -(defvar auth-source-pass--match-host-function #'equal - "An escape hatch for alternate host-matching behavior.") + (if (and (eq auth-source-pass-extra-query-keywords 'match-domains) + (string-match (rx "." (+ (not ".")) "." (>= 2 alpha) eot) + search-param)) + (string-suffix-p matched-path search-param) + (equal matched-path search-param))) (defun auth-source-pass--find-match-many (hosts users ports require max) "Return plists for valid combinations of HOSTS, USERS, PORTS." @@ -302,8 +302,7 @@ auth-source-pass--find-match-many (when-let* ((m (or (gethash e seen) (auth-source-pass--retrieve-parsed seen e (integerp port)))) - ((funcall auth-source-pass--match-host-function - host (plist-get m :host))) + ((auth-source-pass--match-host host (plist-get m :host))) ((auth-source-pass--match-parts m :port port require)) ((auth-source-pass--match-parts m :user user require)) (parsed (auth-source-pass-parse-entry e)) diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index dd694c72f6..cca203d790 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -785,12 +785,11 @@ auth-source-pass-extra-query-keywords--subdomain-miss ;; But we could offer optional legacy matching behavior -(ert-deftest auth-source-pass-extra-query-keywords--subdomain-compat-hit () +(ert-deftest auth-source-pass-extra-query-keywords--match-domains () (auth-source-pass--with-store '(("open-news-network.org" (secret . "a")) ("onn6:nope" (secret . "b"))) (auth-source-pass-enable) - (let* ((auth-source-pass-extra-query-keywords t) - (auth-source-pass--match-host-function #'auth-source-pass--match-host) + (let* ((auth-source-pass-extra-query-keywords 'match-domains) (results (auth-source-search :max 1 :host '("news6.open-news-network.org" "onn6") -- 2.38.1