From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Damien Cassou Newsgroups: gmane.emacs.bugs Subject: bug#31639: 26.1; [PATCH] Update auth-source-pass Date: Tue, 29 May 2018 14:31:19 +0200 Message-ID: <871sduskx4.fsf@cassou.me> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1527597200 26064 195.159.176.226 (29 May 2018 12:33:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 29 May 2018 12:33:20 +0000 (UTC) To: 31639@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue May 29 14:33:15 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fNdoR-0006a4-4i for geb-bug-gnu-emacs@m.gmane.org; Tue, 29 May 2018 14:33:15 +0200 Original-Received: from localhost ([::1]:60907 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNdqW-0006FP-El for geb-bug-gnu-emacs@m.gmane.org; Tue, 29 May 2018 08:35:24 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37601) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNdoJ-0004mF-6t for bug-gnu-emacs@gnu.org; Tue, 29 May 2018 08:33:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNdoF-0006vy-4t for bug-gnu-emacs@gnu.org; Tue, 29 May 2018 08:33:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45360) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fNdoE-0006vr-RF for bug-gnu-emacs@gnu.org; Tue, 29 May 2018 08:33:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fNdoE-0003b4-IG for bug-gnu-emacs@gnu.org; Tue, 29 May 2018 08:33:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Damien Cassou Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 29 May 2018 12:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 31639 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.152759713713769 (code B ref -1); Tue, 29 May 2018 12:33:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 May 2018 12:32:17 +0000 Original-Received: from localhost ([127.0.0.1]:53257 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fNdnM-0003YZ-9E for submit@debbugs.gnu.org; Tue, 29 May 2018 08:32:17 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:46381) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fNdnC-0003Lf-Fu for submit@debbugs.gnu.org; Tue, 29 May 2018 08:32:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNdn3-0006Lj-3X for submit@debbugs.gnu.org; Tue, 29 May 2018 08:31:53 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:60931) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fNdn2-0006Lb-Qh for submit@debbugs.gnu.org; Tue, 29 May 2018 08:31:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNdmx-00045k-R6 for bug-gnu-emacs@gnu.org; Tue, 29 May 2018 08:31:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNdmo-0006HH-Ss for bug-gnu-emacs@gnu.org; Tue, 29 May 2018 08:31:43 -0400 Original-Received: from mail.choca.pics ([62.210.108.126]:44806) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fNdmn-0006GU-OY for bug-gnu-emacs@gnu.org; Tue, 29 May 2018 08:31:34 -0400 Original-Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id A63EA2332151 for ; Tue, 29 May 2018 14:31:31 +0200 (CEST) Original-Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id QX_lF7xAXtds for ; Tue, 29 May 2018 14:31:24 +0200 (CEST) Original-Received: from localhost (localhost.localdomain [IPv6:::1]) by mail.choca.pics (Postfix) with ESMTP id 6DD922332152 for ; Tue, 29 May 2018 14:31:24 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.choca.pics 6DD922332152 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cassou.me; s=9EA44F5C-DEF4-11E6-A83F-A08DF322D8FB; t=1527597084; bh=CLzNmZNwRsSGofTztHtwQPdnidmulhesiO27qE6ogh8=; h=From:To:Date:Message-ID:MIME-Version; b=Mzmydi6dDHaAE6Q21DuJP4E+W3zTwZGmY2MOLJ2MJZOpDt6bKgdxeMmp4bh0mEbdq 4HtU9pLlk9/6uVMdRyMffgWZxLGXjcs5dSomkRmeL6IMcAtUmvUuKX1TYYqidBcqHM Mx8piPriiVhGtQlzGy49qljD1EldqjtlulnsVXvBJQ0nyCebZjtUpKDn5WoFfV/qvV oNRKWbcXFqCWXimceGLtVYixghoWgUeiUOY7IaI7QelT/ly0cfZVWPfHFkp8YO5yYm c9tJqY1PDTbG7Z7e2vyf0hoDitjvV94fdPavb42ONHHs2jG20O1iFH32yL72x9cQ+t cUxnwIIYaJvOA== X-Virus-Scanned: amavisd-new at choca.pics Original-Received: from mail.choca.pics ([IPv6:::1]) by localhost (mail.choca.pics [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id h1cyaHtOgOcg for ; Tue, 29 May 2018 14:31:23 +0200 (CEST) Original-Received: from luz4 (20-44-190-109.dsl.ovh.fr [109.190.44.20]) by mail.choca.pics (Postfix) with ESMTPSA id 269262332151 for ; Tue, 29 May 2018 14:31:23 +0200 (CEST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:146692 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable This series of patches update auth-source-pass to its latest version. Alex Branham (1): Silence byte compiler warning in auth-source-pass Damien Cassou (11): * lisp/auth-source-pass.el: Fix headers. Fix indentation in auth-source-pass-tests.el Add a test to auth-source-pass-tests.el Add missing test cases to auth-source-pass-tests.el auth-source-pass: Take care of matching hosts when port is provided * lisp/auth-source-pass.el: Update version to 3.0.0 Fix prefix messages of auth-source-pass debug messages * lisp/auth-source-pass.el: Update version to 4.0.0 Make sure auth-source-pass is compatible with Emacs 25 Test checking that auth-source-pass backend is correctly installed * lisp/auth-source-pass.el: Update version to 4.0.1 Edison Iba=C3=B1ez (1): * test/lisp/auth-source-pass-tests.el: Add assertions for host:port Jelle Licht (1): Fix auth-source-pass.el to properly handle special inputs lisp/auth-source-pass.el | 94 +++++++++++++++-------------- test/lisp/auth-source-pass-tests.el | 84 +++++++++++++++++--------- 2 files changed, 102 insertions(+), 76 deletions(-) --=20 Damien Cassou http://damiencassou.seasidehosting.st "Success is the ability to go from one failure to another without losing enthusiasm." --Winston Churchill --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-auth-source-pass.el-Fix-headers.patch >From f6db365f62fc9e02c89098f68524c82ec535852c Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Thu, 22 Feb 2018 17:58:07 +0100 Subject: [PATCH 01/14] * lisp/auth-source-pass.el: Fix headers. --- lisp/auth-source-pass.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index 3e6a9cccbc..1785ca3255 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -5,9 +5,9 @@ ;; Author: Damien Cassou , ;; Nicolas Petton ;; Version: 2.0.0 -;; Package-Requires: ((emacs "24.4") +;; Package-Requires: ((emacs "25")) +;; Url: https://github.com/DamienCassou/auth-password-store ;; Created: 07 Jun 2015 -;; Keywords: pass password-store auth-source username password login ;; This file is part of GNU Emacs. -- 2.17.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-test-lisp-auth-source-pass-tests.el-Add-assertions-f.patch >From 4f5cd8ce6d6784c941450e00d8c3b91838071d61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edison=20Iba=C3=B1ez?= Date: Tue, 7 Nov 2017 09:00:43 +0100 Subject: [PATCH 02/14] * test/lisp/auth-source-pass-tests.el: Add assertions for host:port --- test/lisp/auth-source-pass-tests.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index 86f59e5166..557a34ff59 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -166,11 +166,13 @@ auth-source-pass--with-store "host.com")))) (ert-deftest auth-source-pass-hostname () + (should (equal (auth-source-pass--hostname "https://foo.bar:443") "foo.bar")) (should (equal (auth-source-pass--hostname "https://foo.bar") "foo.bar")) (should (equal (auth-source-pass--hostname "http://foo.bar") "foo.bar")) (should (equal (auth-source-pass--hostname "https://SomeUser@foo.bar") "foo.bar"))) (ert-deftest auth-source-pass-hostname-with-user () + (should (equal (auth-source-pass--hostname-with-user "https://foo.bar:443") "foo.bar")) (should (equal (auth-source-pass--hostname-with-user "https://foo.bar") "foo.bar")) (should (equal (auth-source-pass--hostname-with-user "http://foo.bar") "foo.bar")) (should (equal (auth-source-pass--hostname-with-user "https://SomeUser@foo.bar") "SomeUser@foo.bar"))) -- 2.17.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0003-Fix-indentation-in-auth-source-pass-tests.el.patch >From 68eac649d8deaf02219ce4d5c3896ec98b62edb1 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Tue, 7 Nov 2017 09:33:22 +0100 Subject: [PATCH 03/14] Fix indentation in auth-source-pass-tests.el * test/lisp/auth-source-pass-tests.el (auth-source-pass-only-return-entries-that-can-be-open): Fix indentation. --- test/lisp/auth-source-pass-tests.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index 557a34ff59..adb0b5d93f 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -206,12 +206,10 @@ auth-source-pass--with-store-find-foo (ert-deftest auth-source-pass-only-return-entries-that-can-be-open () (cl-letf (((symbol-function 'auth-source-pass-entries) - (lambda () '("foo.site.com" "bar.site.com" - "mail/baz.site.com/scott"))) + (lambda () '("foo.site.com" "bar.site.com" "mail/baz.site.com/scott"))) ((symbol-function 'auth-source-pass--entry-valid-p) ;; only foo.site.com and "mail/baz.site.com/scott" are valid - (lambda (entry) (member entry '("foo.site.com" - "mail/baz.site.com/scott"))))) + (lambda (entry) (member entry '("foo.site.com" "mail/baz.site.com/scott"))))) (should (equal (auth-source-pass--find-all-by-entry-name "foo.site.com" "someuser") '("foo.site.com"))) (should (equal (auth-source-pass--find-all-by-entry-name "bar.site.com" "someuser") -- 2.17.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0004-Add-a-test-to-auth-source-pass-tests.el.patch >From a1bc5d5db43018da2c3954c9207536095475bb00 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Tue, 7 Nov 2017 09:32:30 +0100 Subject: [PATCH 04/14] Add a test to auth-source-pass-tests.el * test/lisp/auth-source-pass-tests.el (auth-source-pass-build-result-passes-full-host-to-find-match): Add test making sure find-match is called with full host. --- test/lisp/auth-source-pass-tests.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index adb0b5d93f..2ddbcab233 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -204,6 +204,13 @@ auth-source-pass--with-store-find-foo (should (equal (plist-get result :port) 512)) (should (equal (plist-get result :user) "anuser"))))) +(ert-deftest auth-source-pass-build-result-passes-full-host-to-find-match () + (let (passed-host) + (cl-letf (((symbol-function 'auth-source-pass--find-match) + (lambda (host _user) (setq passed-host host)))) + (auth-source-pass--build-result "https://user@host.com:123" nil nil) + (should (equal passed-host "https://user@host.com:123"))))) + (ert-deftest auth-source-pass-only-return-entries-that-can-be-open () (cl-letf (((symbol-function 'auth-source-pass-entries) (lambda () '("foo.site.com" "bar.site.com" "mail/baz.site.com/scott"))) -- 2.17.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0005-Add-missing-test-cases-to-auth-source-pass-tests.el.patch >From 5ee76ac04967f311c329af6867dd569dbfb6888f Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Tue, 7 Nov 2017 09:48:50 +0100 Subject: [PATCH 05/14] Add missing test cases to auth-source-pass-tests.el * test/lisp/auth-source-pass-tests.el (auth-source-pass-build-result-passes-full-host-to-find-match): Add missing test cases. --- test/lisp/auth-source-pass-tests.el | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index 2ddbcab233..6d471f4e34 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -209,7 +209,13 @@ auth-source-pass--with-store-find-foo (cl-letf (((symbol-function 'auth-source-pass--find-match) (lambda (host _user) (setq passed-host host)))) (auth-source-pass--build-result "https://user@host.com:123" nil nil) - (should (equal passed-host "https://user@host.com:123"))))) + (should (equal passed-host "https://user@host.com:123")) + (auth-source-pass--build-result "https://user@host.com" nil nil) + (should (equal passed-host "https://user@host.com")) + (auth-source-pass--build-result "user@host.com" nil nil) + (should (equal passed-host "user@host.com")) + (auth-source-pass--build-result "user@host.com:443" nil nil) + (should (equal passed-host "user@host.com:443"))))) (ert-deftest auth-source-pass-only-return-entries-that-can-be-open () (cl-letf (((symbol-function 'auth-source-pass-entries) -- 2.17.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0006-auth-source-pass-Take-care-of-matching-hosts-when-po.patch >From 82a1f5229fb2314105b7c5e67c5519408f6bdb8d Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Thu, 9 Nov 2017 10:40:19 +0100 Subject: [PATCH 06/14] auth-source-pass: Take care of matching hosts when port is provided * lisp/auth-source-pass.el (auth-source-pass--find-match): Add PORT parameter and reorganize code by extracting `find-match-unambiguous'. (auth-source-pass--find-match-unambiguous): New function. (auth-source-pass--build-result): Fix the call to `find-match'. (auth-source-pass--hostname, auth-source-pass--hostname-with-user, auth-source-pass--user): Remove functions. * test/lisp/auth-source-pass-tests.el: Fix the calls to `find-match'. (auth-source-pass-find-host-without-port) Add corresponding test. --- lisp/auth-source-pass.el | 68 +++++++++++++---------------- test/lisp/auth-source-pass-tests.el | 51 ++++++++++------------ 2 files changed, 52 insertions(+), 67 deletions(-) diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index 1785ca3255..96aefc8dd7 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -52,7 +52,7 @@ (defun auth-source-pass--build-result (host port user) "Build auth-source-pass entry matching HOST, PORT and USER." - (let ((entry (auth-source-pass--find-match host user))) + (let ((entry (auth-source-pass--find-match host user port))) (when entry (let ((retval (list :host host @@ -139,26 +139,6 @@ auth-source-pass--parse-data (mapconcat #'identity (cdr pair) ":"))))) (cdr lines))))) -(defun auth-source-pass--hostname (host) - "Extract hostname from HOST." - (let ((url (url-generic-parse-url host))) - (or (url-host url) host))) - -(defun auth-source-pass--hostname-with-user (host) - "Extract hostname and user from HOST." - (let* ((url (url-generic-parse-url host)) - (user (url-user url)) - (hostname (url-host url))) - (cond - ((and user hostname) (format "%s@%s" user hostname)) - (hostname hostname) - (t host)))) - -(defun auth-source-pass--user (host) - "Extract user from HOST and return it. -Return nil if no match was found." - (url-user (url-generic-parse-url host))) - (defun auth-source-pass--do-debug (&rest msg) "Call `auth-source-do-debug` with MSG and a prefix." (apply #'auth-source-do-debug @@ -230,27 +210,39 @@ auth-source-pass--find-one-by-entry-name (car matching-entries)) (_ (auth-source-pass--select-one-entry matching-entries user))))) -(defun auth-source-pass--find-match (host user) - "Return a password-store entry name matching HOST and USER. -If many matches are found, return the first one. If no match is -found, return nil." +(defun auth-source-pass--find-match (host user port) + "Return a password-store entry name matching HOST, USER and PORT. + +Disambiguate between user provided inside HOST (e.g., user@server.com) and +inside USER by giving priority to USER. Same for PORT." + (let* ((url (url-generic-parse-url (if (string-match-p ".*://" host) + host + (format "https://%s" host))))) + (auth-source-pass--find-match-unambiguous + (or (url-host url) host) + (or user (url-user url)) + ;; url-port returns 443 (because of the https:// above) by default + (or port (number-to-string (url-port url)))))) + +(defun auth-source-pass--find-match-unambiguous (hostname user port) + "Return a password-store entry name matching HOSTNAME, USER and PORT. +If many matches are found, return the first one. If no match is found, +return nil. + +HOSTNAME should not contain any username or port number." (or - (if (auth-source-pass--user host) - ;; if HOST contains a user (e.g., "user@host.com"), - (auth-source-pass--find-one-by-entry-name (auth-source-pass--hostname-with-user host) user) - ;; otherwise, if USER is provided, search for @ - (when (stringp user) - (auth-source-pass--find-one-by-entry-name (concat user "@" (auth-source-pass--hostname host)) user))) - ;; if that didn't work, search for HOST without its user component, if any - (auth-source-pass--find-one-by-entry-name (auth-source-pass--hostname host) user) - ;; if that didn't work, search for HOST with user extracted from it - (auth-source-pass--find-one-by-entry-name - (auth-source-pass--hostname host) (auth-source-pass--user host)) + (and user port (auth-source-pass--find-one-by-entry-name (format "%s@%s:%s" user hostname port) user)) + (and user (auth-source-pass--find-one-by-entry-name (format "%s@%s" user hostname) user)) + (and port (auth-source-pass--find-one-by-entry-name (format "%s:%s" hostname port) nil)) + (auth-source-pass--find-one-by-entry-name hostname user) ;; if that didn't work, remove subdomain: foo.bar.com -> bar.com - (let ((components (split-string host "\\."))) + (let ((components (split-string hostname "\\."))) (when (= (length components) 3) ;; start from scratch - (auth-source-pass--find-match (mapconcat 'identity (cdr components) ".") user))))) + (auth-source-pass--find-match-unambiguous + (mapconcat 'identity (cdr components) ".") + user + port))))) (provide 'auth-source-pass) ;;; auth-source-pass.el ends here diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index 6d471f4e34..0f072592d0 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -75,107 +75,100 @@ auth-source-pass--with-store (ert-deftest auth-source-pass-find-match-matching-at-entry-name () (auth-source-pass--with-store '(("foo")) - (should (equal (auth-source-pass--find-match "foo" nil) + (should (equal (auth-source-pass--find-match "foo" nil nil) "foo")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-part () (auth-source-pass--with-store '(("foo")) - (should (equal (auth-source-pass--find-match "https://foo" nil) + (should (equal (auth-source-pass--find-match "https://foo" nil nil) "foo")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-ignoring-user () (auth-source-pass--with-store '(("foo")) - (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil) + (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil nil) "foo")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-with-user () (auth-source-pass--with-store '(("SomeUser@foo")) - (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil) + (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil nil) "SomeUser@foo")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-prefer-full () (auth-source-pass--with-store '(("SomeUser@foo") ("foo")) - (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil) + (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil nil) "SomeUser@foo")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-prefer-full-reversed () (auth-source-pass--with-store '(("foo") ("SomeUser@foo")) - (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil) + (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil nil) "SomeUser@foo")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain () (auth-source-pass--with-store '(("bar.com")) - (should (equal (auth-source-pass--find-match "foo.bar.com" nil) + (should (equal (auth-source-pass--find-match "foo.bar.com" nil nil) "bar.com")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-with-user () (auth-source-pass--with-store '(("someone@bar.com")) - (should (equal (auth-source-pass--find-match "foo.bar.com" "someone") + (should (equal (auth-source-pass--find-match "foo.bar.com" "someone" nil) "someone@bar.com")))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-with-bad-user () (auth-source-pass--with-store '(("someoneelse@bar.com")) - (should (equal (auth-source-pass--find-match "foo.bar.com" "someone") + (should (equal (auth-source-pass--find-match "foo.bar.com" "someone" nil) nil)))) (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-prefer-full () (auth-source-pass--with-store '(("bar.com") ("foo.bar.com")) - (should (equal (auth-source-pass--find-match "foo.bar.com" nil) + (should (equal (auth-source-pass--find-match "foo.bar.com" nil nil) "foo.bar.com")))) (ert-deftest auth-source-pass-dont-match-at-folder-name () (auth-source-pass--with-store '(("foo.bar.com/foo")) - (should (equal (auth-source-pass--find-match "foo.bar.com" nil) + (should (equal (auth-source-pass--find-match "foo.bar.com" nil nil) nil)))) (ert-deftest auth-source-pass-find-match-matching-extracting-user-from-host () (auth-source-pass--with-store '(("foo.com/bar")) - (should (equal (auth-source-pass--find-match "https://bar@foo.com" nil) + (should (equal (auth-source-pass--find-match "https://bar@foo.com" nil nil) "foo.com/bar")))) (ert-deftest auth-source-pass-search-with-user-first () (auth-source-pass--with-store '(("foo") ("user@foo")) - (should (equal (auth-source-pass--find-match "foo" "user") + (should (equal (auth-source-pass--find-match "foo" "user" nil) "user@foo")) (auth-source-pass--should-have-message-containing "Found 1 match"))) (ert-deftest auth-source-pass-give-priority-to-desired-user () (auth-source-pass--with-store '(("foo") ("subdir/foo" ("user" . "someone"))) - (should (equal (auth-source-pass--find-match "foo" "someone") + (should (equal (auth-source-pass--find-match "foo" "someone" nil) "subdir/foo")) (auth-source-pass--should-have-message-containing "Found 2 matches") (auth-source-pass--should-have-message-containing "matching user field"))) (ert-deftest auth-source-pass-give-priority-to-desired-user-reversed () (auth-source-pass--with-store '(("foo" ("user" . "someone")) ("subdir/foo")) - (should (equal (auth-source-pass--find-match "foo" "someone") + (should (equal (auth-source-pass--find-match "foo" "someone" nil) "foo")) (auth-source-pass--should-have-message-containing "Found 2 matches") (auth-source-pass--should-have-message-containing "matching user field"))) (ert-deftest auth-source-pass-return-first-when-several-matches () (auth-source-pass--with-store '(("foo") ("subdir/foo")) - (should (equal (auth-source-pass--find-match "foo" nil) + (should (equal (auth-source-pass--find-match "foo" nil nil) "foo")) (auth-source-pass--should-have-message-containing "Found 2 matches") (auth-source-pass--should-have-message-containing "the first one"))) (ert-deftest auth-source-pass-make-divansantana-happy () (auth-source-pass--with-store '(("host.com")) - (should (equal (auth-source-pass--find-match "smtp.host.com" "myusername@host.co.za") + (should (equal (auth-source-pass--find-match "smtp.host.com" "myusername@host.co.za" nil) "host.com")))) -(ert-deftest auth-source-pass-hostname () - (should (equal (auth-source-pass--hostname "https://foo.bar:443") "foo.bar")) - (should (equal (auth-source-pass--hostname "https://foo.bar") "foo.bar")) - (should (equal (auth-source-pass--hostname "http://foo.bar") "foo.bar")) - (should (equal (auth-source-pass--hostname "https://SomeUser@foo.bar") "foo.bar"))) - -(ert-deftest auth-source-pass-hostname-with-user () - (should (equal (auth-source-pass--hostname-with-user "https://foo.bar:443") "foo.bar")) - (should (equal (auth-source-pass--hostname-with-user "https://foo.bar") "foo.bar")) - (should (equal (auth-source-pass--hostname-with-user "http://foo.bar") "foo.bar")) - (should (equal (auth-source-pass--hostname-with-user "https://SomeUser@foo.bar") "SomeUser@foo.bar"))) +(ert-deftest auth-source-pass-find-host-without-port () + (auth-source-pass--with-store '(("host.com")) + (should (equal (auth-source-pass--find-match "host.com:8888" "someuser" nil) + "host.com")))) (defmacro auth-source-pass--with-store-find-foo (store &rest body) "Use STORE while executing BODY. \"foo\" is the matched entry." @@ -207,7 +200,7 @@ auth-source-pass--with-store-find-foo (ert-deftest auth-source-pass-build-result-passes-full-host-to-find-match () (let (passed-host) (cl-letf (((symbol-function 'auth-source-pass--find-match) - (lambda (host _user) (setq passed-host host)))) + (lambda (host _user _port) (setq passed-host host)))) (auth-source-pass--build-result "https://user@host.com:123" nil nil) (should (equal passed-host "https://user@host.com:123")) (auth-source-pass--build-result "https://user@host.com" nil nil) -- 2.17.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0007-Fix-auth-source-pass.el-to-properly-handle-special-i.patch >From 5218790e76c665b070730b892ad2196edf42defe Mon Sep 17 00:00:00 2001 From: Jelle Licht Date: Mon, 8 Jan 2018 17:34:38 +0100 Subject: [PATCH 07/14] Fix auth-source-pass.el to properly handle special inputs * lisp/auth-source-pass.el (auth-source-pass-search): Warn when passing multiple hosts in SPEC. Early return and warn when passing a wildcard as host in SPEC. Early return when host is nil. * test/lisp/auth-source-pass-tests.el (auth-source-pass-any-host, auth-source-pass-undefined-host): Add corresponding tests. --- lisp/auth-source-pass.el | 12 ++++++++++-- test/lisp/auth-source-pass-tests.el | 11 +++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index 96aefc8dd7..461cba02dd 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -45,10 +45,18 @@ See `auth-source-search' for details on SPEC." (cl-assert (or (null type) (eq type (oref backend type))) t "Invalid password-store search: %s %s") - (when (listp host) + (when (consp host) + (warn "auth-source-pass ignores all but first host in spec.") ;; Take the first non-nil item of the list of hosts (setq host (seq-find #'identity host))) - (list (auth-source-pass--build-result host port user))) + (cond ((eq host t) + (warn "auth-source-pass does not handle host wildcards.") + nil) + ((null host) + ;; Do not build a result, as none will match when HOST is nil + nil) + (t + (list (auth-source-pass--build-result host port user))))) (defun auth-source-pass--build-result (host port user) "Build auth-source-pass entry matching HOST, PORT and USER." diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index 0f072592d0..431e4e411d 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -73,6 +73,17 @@ auth-source-pass--with-store (auth-source-pass--debug-log nil)) ,@body))) +(ert-deftest auth-source-pass-any-host () + (auth-source-pass--with-store '(("foo" ("port" . "foo-port") ("host" . "foo-user")) + ("bar")) + (should-not (auth-source-pass-search :host t)))) + +(ert-deftest auth-source-pass-undefined-host () + (auth-source-pass--with-store '(("foo" ("port" . "foo-port") ("host" . "foo-user")) + ("bar")) + (should-not (auth-source-pass-search :host nil)))) + + (ert-deftest auth-source-pass-find-match-matching-at-entry-name () (auth-source-pass--with-store '(("foo")) (should (equal (auth-source-pass--find-match "foo" nil nil) -- 2.17.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0008-Silence-byte-compiler-warning-in-auth-source-pass.patch >From b361ce235589208ee26d13f3c4ace3927ac54599 Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Mon, 12 Feb 2018 13:28:20 -0600 Subject: [PATCH 08/14] Silence byte compiler warning in auth-source-pass * lisp/auth-source-pass.el (auth-source-pass-backend): Silence byte compiler warning by only passing a parameter to `auth-source-backend' in Emacs <= 25. --- lisp/auth-source-pass.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index 461cba02dd..ec0fe8c432 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -81,7 +81,7 @@ auth-source-pass-enable (defvar auth-source-pass-backend (auth-source-backend - (format "Password store") + (when (<= emacs-major-version 25) "password-store") :source "." ;; not used :type 'password-store :search-function #'auth-source-pass-search) -- 2.17.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0009-lisp-auth-source-pass.el-Update-version-to-3.0.0.patch >From 24755e95ce19aa925580ac90d826c3d3a5e194d0 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Wed, 14 Feb 2018 14:51:25 +0100 Subject: [PATCH 09/14] * lisp/auth-source-pass.el: Update version to 3.0.0 --- lisp/auth-source-pass.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index ec0fe8c432..c8722a5579 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -4,7 +4,7 @@ ;; Author: Damien Cassou , ;; Nicolas Petton -;; Version: 2.0.0 +;; Version: 3.0.0 ;; Package-Requires: ((emacs "25")) ;; Url: https://github.com/DamienCassou/auth-password-store ;; Created: 07 Jun 2015 -- 2.17.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0010-Fix-prefix-messages-of-auth-source-pass-debug-messag.patch >From d26168ea8ba7007dbfb203daebbabfb46e2fbfc5 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Fri, 23 Mar 2018 09:16:25 +0100 Subject: [PATCH 10/14] Fix prefix messages of auth-source-pass debug messages * lisp/auth-source-pass.el (auth-source-pass--do-debug): Fix message prefix. --- lisp/auth-source-pass.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index c8722a5579..42c0344756 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -150,7 +150,7 @@ auth-source-pass--parse-data (defun auth-source-pass--do-debug (&rest msg) "Call `auth-source-do-debug` with MSG and a prefix." (apply #'auth-source-do-debug - (cons (concat "auth-source-password-store: " (car msg)) + (cons (concat "auth-source-pass: " (car msg)) (cdr msg)))) (defun auth-source-pass--select-one-entry (entries user) -- 2.17.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0011-lisp-auth-source-pass.el-Update-version-to-4.0.0.patch >From eedf0078f204ebb43659777dcb57596f708453f1 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Fri, 23 Mar 2018 09:18:54 +0100 Subject: [PATCH 11/14] * lisp/auth-source-pass.el: Update version to 4.0.0 --- lisp/auth-source-pass.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index 42c0344756..1193d67954 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -4,7 +4,7 @@ ;; Author: Damien Cassou , ;; Nicolas Petton -;; Version: 3.0.0 +;; Version: 4.0.0 ;; Package-Requires: ((emacs "25")) ;; Url: https://github.com/DamienCassou/auth-password-store ;; Created: 07 Jun 2015 -- 2.17.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0012-Make-sure-auth-source-pass-is-compatible-with-Emacs-.patch >From 178f50ff72a52521d9ff2f2b7ca75b335c907090 Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Mon, 26 Mar 2018 06:28:17 +0200 Subject: [PATCH 12/14] Make sure auth-source-pass is compatible with Emacs 25 * lisp/auth-source-pass.el: Use `advice-add' for Emacs 25 users as `auth-source-backend-parser-functions' does not exist there. --- lisp/auth-source-pass.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index 1193d67954..d5c6139814 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -92,7 +92,9 @@ auth-source-pass-backend-parse (when (eq entry 'password-store) (auth-source-backend-parse-parameters entry auth-source-pass-backend))) -(add-hook 'auth-source-backend-parser-functions #'auth-source-pass-backend-parse) +(if (boundp 'auth-source-backend-parser-functions) + (add-hook 'auth-source-backend-parser-functions #'auth-source-pass-backend-parse) + (advice-add 'auth-source-backend-parse :before-until #'auth-source-pass-backend-parse)) (defun auth-source-pass-get (key entry) -- 2.17.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0013-Test-checking-that-auth-source-pass-backend-is-corre.patch >From 7f3da2e0ab258aabeb952a5aa71199855ea3691d Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Mon, 26 Mar 2018 08:56:16 +0200 Subject: [PATCH 13/14] Test checking that auth-source-pass backend is correctly installed * test/lisp/auth-source-pass-tests.el (auth-source-pass-can-start-from-auth-source-search): Add test. --- test/lisp/auth-source-pass-tests.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index 431e4e411d..b30419f44b 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el @@ -244,6 +244,13 @@ auth-source-pass--with-store-find-foo (should (auth-source-pass--entry-valid-p "foo")) (should-not (auth-source-pass--entry-valid-p "bar")))) +(ert-deftest auth-source-pass-can-start-from-auth-source-search () + (auth-source-pass--with-store '(("gitlab.com" ("user" . "someone"))) + (auth-source-pass-enable) + (let ((result (car (auth-source-search :host "gitlab.com")))) + (should (equal (plist-get result :user) "someone")) + (should (equal (plist-get result :host) "gitlab.com"))))) + (provide 'auth-source-pass-tests) ;;; auth-source-pass-tests.el ends here -- 2.17.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0014-lisp-auth-source-pass.el-Update-version-to-4.0.1.patch >From c3f44365dad279521f42232a60f26f3694c6fceb Mon Sep 17 00:00:00 2001 From: Damien Cassou Date: Mon, 26 Mar 2018 09:04:36 +0200 Subject: [PATCH 14/14] * lisp/auth-source-pass.el: Update version to 4.0.1 --- lisp/auth-source-pass.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el index d5c6139814..cebe8c2666 100644 --- a/lisp/auth-source-pass.el +++ b/lisp/auth-source-pass.el @@ -4,7 +4,7 @@ ;; Author: Damien Cassou , ;; Nicolas Petton -;; Version: 4.0.0 +;; Version: 4.0.1 ;; Package-Requires: ((emacs "25")) ;; Url: https://github.com/DamienCassou/auth-password-store ;; Created: 07 Jun 2015 -- 2.17.0 --=-=-=--