(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)
(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)