[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] feature/auth-source-pass 42f8006 3/3: auth-source-pass: En
From: |
Teodor Zlatanov |
Subject: |
[Emacs-diffs] feature/auth-source-pass 42f8006 3/3: auth-source-pass: Enable finding entries by "host/username". |
Date: |
Mon, 27 Mar 2017 13:35:36 -0400 (EDT) |
branch: feature/auth-source-pass
commit 42f8006fc802a7af2813e6b4226dc2455c147e97
Author: foudfou <address@hidden>
Commit: Damien Cassou <address@hidden>
auth-source-pass: Enable finding entries by "host/username".
---
lisp/auth-source-pass.el | 21 ++++++++++++---------
test/lisp/auth-source-pass-tests.el | 16 ++++++++++------
2 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el
index a9d61cf..e59cfa2 100644
--- a/lisp/auth-source-pass.el
+++ b/lisp/auth-source-pass.el
@@ -206,25 +206,28 @@ often."
(lambda (file) (file-name-sans-extension (file-relative-name file
store-dir)))
(directory-files-recursively store-dir "\.gpg$"))))
-(defun auth-source-pass--find-all-by-entry-name (name)
- "Search the store for all entries matching NAME.
+(defun auth-source-pass--find-all-by-entry-name (entryname user)
+ "Search the store for all entries either matching ENTRYNAME/USER or
ENTRYNAME.
Only return valid entries as of `auth-source-pass--entry-valid-p'."
(seq-filter (lambda (entry)
(and
- (string-equal
- name
- (auth-source-pass--remove-directory-name entry))
+ (or
+ (let ((components-host-user
+ (member entryname (split-string entry "/"))))
+ (and (= (length components-host-user) 2)
+ (string-equal user (cadr components-host-user))))
+ (string-equal entryname
(auth-source-pass--remove-directory-name entry)))
(auth-source-pass--entry-valid-p entry)))
(auth-source-pass-entries)))
-(defun auth-source-pass--find-one-by-entry-name (name user)
- "Search the store for an entry matching NAME.
+(defun auth-source-pass--find-one-by-entry-name (entryname user)
+ "Search the store for an entry matching ENTRYNAME.
If USER is non nil, give precedence to entries containing a user field
matching USER."
(auth-source-pass--do-debug "searching for '%s' in entry names (user: %s)"
- name
+ entryname
user)
- (let ((matching-entries (auth-source-pass--find-all-by-entry-name name)))
+ (let ((matching-entries (auth-source-pass--find-all-by-entry-name entryname
user)))
(pcase (length matching-entries)
(0 (auth-source-pass--do-debug "no match found")
nil)
diff --git a/test/lisp/auth-source-pass-tests.el
b/test/lisp/auth-source-pass-tests.el
index c3586d8..1a7c9a7 100644
--- a/test/lisp/auth-source-pass-tests.el
+++ b/test/lisp/auth-source-pass-tests.el
@@ -210,14 +210,18 @@ ease testing."
(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")))
+ (lambda () '("foo.site.com" "bar.site.com"
+ "mail/baz.site.com/scott")))
((symbol-function 'auth-source-pass--entry-valid-p)
- ;; only foo.site.com is valid
- (lambda (entry) (string-equal entry "foo.site.com"))))
- (should (equal (auth-source-pass--find-all-by-entry-name "foo.site.com")
+ ;; only foo.site.com and "mail/baz.site.com/scott" are valid
+ (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")
- '()))))
+ (should (equal (auth-source-pass--find-all-by-entry-name "bar.site.com"
"someuser")
+ '()))
+ (should (equal (auth-pass--find-all-by-entry-name "baz.site.com" "scott")
+ '("mail/baz.site.com/scott")))))
(ert-deftest auth-source-pass-entry-is-not-valid-when-unreadable ()
(cl-letf (((symbol-function 'auth-source-pass--read-entry)