Fix parsing netrc entries with ports

* lisp/gnus/auth-source.el (auth-source-ensure-strings): Don't
make a list out of 't'.  (Bug#22188)

* test/automated/auth-source-tests.el
(auth-source-test-netrc-parse-entry): New test.
This commit is contained in:
Eli Zaretskii 2015-12-17 20:31:25 +02:00
parent 85e93e626c
commit 938495317a
2 changed files with 54 additions and 7 deletions

View file

@ -919,13 +919,15 @@ while \(:host t) would find all host entries."
prompt)
(defun auth-source-ensure-strings (values)
(unless (listp values)
(setq values (list values)))
(mapcar (lambda (value)
(if (numberp value)
(format "%s" value)
value))
values))
(if (eq values t)
values
(unless (listp values)
(setq values (list values)))
(mapcar (lambda (value)
(if (numberp value)
(format "%s" value)
value))
values)))
;;; Backend specific parsing: netrc/authinfo backend

View file

@ -174,5 +174,50 @@
(:search-function . auth-source-secrets-search)
(:create-function . auth-source-secrets-create)))))
(defun auth-source--test-netrc-parse-entry (entry host user port)
"Parse a netrc entry from buffer."
(auth-source-forget-all-cached)
(setq port (auth-source-ensure-strings port))
(with-temp-buffer
(insert entry)
(goto-char (point-min))
(let* ((check (lambda(alist)
(and alist
(auth-source-search-collection
host
(or
(auth-source--aget alist "machine")
(auth-source--aget alist "host")
t))
(auth-source-search-collection
user
(or
(auth-source--aget alist "login")
(auth-source--aget alist "account")
(auth-source--aget alist "user")
t))
(auth-source-search-collection
port
(or
(auth-source--aget alist "port")
(auth-source--aget alist "protocol")
t)))))
(entries (auth-source-netrc-parse-entries check 1)))
entries)))
(ert-deftest auth-source-test-netrc-parse-entry ()
(should (equal (auth-source--test-netrc-parse-entry
"machine mymachine1 login user1 password pass1\n" t t t)
'((("password" . "pass1")
("login" . "user1")
("machine" . "mymachine1")))))
(should (equal (auth-source--test-netrc-parse-entry
"machine mymachine1 login user1 password pass1 port 100\n"
t t t)
'((("port" . "100")
("password" . "pass1")
("login" . "user1")
("machine" . "mymachine1"))))))
(provide 'auth-source-tests)
;;; auth-source-tests.el ends here