[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] emacs-25 9384953: Fix parsing netrc entries with ports
From: |
Eli Zaretskii |
Subject: |
[Emacs-diffs] emacs-25 9384953: Fix parsing netrc entries with ports |
Date: |
Thu, 17 Dec 2015 18:32:17 +0000 |
branch: emacs-25
commit 938495317a02b06a6c512832d0c6d9530fcd7f2b
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>
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.
---
lisp/gnus/auth-source.el | 16 +++++++-----
test/automated/auth-source-tests.el | 45 +++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+), 7 deletions(-)
diff --git a/lisp/gnus/auth-source.el b/lisp/gnus/auth-source.el
index 9d842c0..10d32d4 100644
--- a/lisp/gnus/auth-source.el
+++ b/lisp/gnus/auth-source.el
@@ -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
diff --git a/test/automated/auth-source-tests.el
b/test/automated/auth-source-tests.el
index 0b49b90..dd70d54 100644
--- a/test/automated/auth-source-tests.el
+++ b/test/automated/auth-source-tests.el
@@ -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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] emacs-25 9384953: Fix parsing netrc entries with ports,
Eli Zaretskii <=