diff options
| author | Eli Zaretskii | 2015-12-17 20:31:25 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2015-12-17 20:31:25 +0200 |
| commit | 938495317a02b06a6c512832d0c6d9530fcd7f2b (patch) | |
| tree | 2dad910f573e1021b12d94ad485a45d6f96aca3d | |
| parent | 85e93e626ce6d9e169cb5a5ab827092a9b48f85e (diff) | |
| download | emacs-938495317a02b06a6c512832d0c6d9530fcd7f2b.tar.gz emacs-938495317a02b06a6c512832d0c6d9530fcd7f2b.zip | |
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.
| -rw-r--r-- | lisp/gnus/auth-source.el | 16 | ||||
| -rw-r--r-- | 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 9d842c04f64..10d32d45070 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." | |||
| 919 | prompt) | 919 | prompt) |
| 920 | 920 | ||
| 921 | (defun auth-source-ensure-strings (values) | 921 | (defun auth-source-ensure-strings (values) |
| 922 | (unless (listp values) | 922 | (if (eq values t) |
| 923 | (setq values (list values))) | 923 | values |
| 924 | (mapcar (lambda (value) | 924 | (unless (listp values) |
| 925 | (if (numberp value) | 925 | (setq values (list values))) |
| 926 | (format "%s" value) | 926 | (mapcar (lambda (value) |
| 927 | value)) | 927 | (if (numberp value) |
| 928 | values)) | 928 | (format "%s" value) |
| 929 | value)) | ||
| 930 | values))) | ||
| 929 | 931 | ||
| 930 | ;;; Backend specific parsing: netrc/authinfo backend | 932 | ;;; Backend specific parsing: netrc/authinfo backend |
| 931 | 933 | ||
diff --git a/test/automated/auth-source-tests.el b/test/automated/auth-source-tests.el index 0b49b9013f7..dd70d546d5c 100644 --- a/test/automated/auth-source-tests.el +++ b/test/automated/auth-source-tests.el | |||
| @@ -174,5 +174,50 @@ | |||
| 174 | (:search-function . auth-source-secrets-search) | 174 | (:search-function . auth-source-secrets-search) |
| 175 | (:create-function . auth-source-secrets-create))))) | 175 | (:create-function . auth-source-secrets-create))))) |
| 176 | 176 | ||
| 177 | (defun auth-source--test-netrc-parse-entry (entry host user port) | ||
| 178 | "Parse a netrc entry from buffer." | ||
| 179 | (auth-source-forget-all-cached) | ||
| 180 | (setq port (auth-source-ensure-strings port)) | ||
| 181 | (with-temp-buffer | ||
| 182 | (insert entry) | ||
| 183 | (goto-char (point-min)) | ||
| 184 | (let* ((check (lambda(alist) | ||
| 185 | (and alist | ||
| 186 | (auth-source-search-collection | ||
| 187 | host | ||
| 188 | (or | ||
| 189 | (auth-source--aget alist "machine") | ||
| 190 | (auth-source--aget alist "host") | ||
| 191 | t)) | ||
| 192 | (auth-source-search-collection | ||
| 193 | user | ||
| 194 | (or | ||
| 195 | (auth-source--aget alist "login") | ||
| 196 | (auth-source--aget alist "account") | ||
| 197 | (auth-source--aget alist "user") | ||
| 198 | t)) | ||
| 199 | (auth-source-search-collection | ||
| 200 | port | ||
| 201 | (or | ||
| 202 | (auth-source--aget alist "port") | ||
| 203 | (auth-source--aget alist "protocol") | ||
| 204 | t))))) | ||
| 205 | (entries (auth-source-netrc-parse-entries check 1))) | ||
| 206 | entries))) | ||
| 207 | |||
| 208 | (ert-deftest auth-source-test-netrc-parse-entry () | ||
| 209 | (should (equal (auth-source--test-netrc-parse-entry | ||
| 210 | "machine mymachine1 login user1 password pass1\n" t t t) | ||
| 211 | '((("password" . "pass1") | ||
| 212 | ("login" . "user1") | ||
| 213 | ("machine" . "mymachine1"))))) | ||
| 214 | (should (equal (auth-source--test-netrc-parse-entry | ||
| 215 | "machine mymachine1 login user1 password pass1 port 100\n" | ||
| 216 | t t t) | ||
| 217 | '((("port" . "100") | ||
| 218 | ("password" . "pass1") | ||
| 219 | ("login" . "user1") | ||
| 220 | ("machine" . "mymachine1")))))) | ||
| 221 | |||
| 177 | (provide 'auth-source-tests) | 222 | (provide 'auth-source-tests) |
| 178 | ;;; auth-source-tests.el ends here | 223 | ;;; auth-source-tests.el ends here |