diff options
| author | Damien Cassou | 2017-11-09 10:40:19 +0100 |
|---|---|---|
| committer | Nicolas Petton | 2018-06-05 15:51:14 +0200 |
| commit | b43ed61ef985e01975b90d7e0ec3cac70d0afefa (patch) | |
| tree | bc4414f8595bc6ddee73cb4822062fb34b8a9cef /test | |
| parent | a52661b58bc9cffa13cb5f0749cdb3a4c24fbf74 (diff) | |
| download | emacs-b43ed61ef985e01975b90d7e0ec3cac70d0afefa.tar.gz emacs-b43ed61ef985e01975b90d7e0ec3cac70d0afefa.zip | |
auth-source-pass: Take care of matching hosts when port is provided
* lisp/auth-source-pass.el (auth-source-pass--find-match): Add PORT
parameter and reorganize code by extracting `find-match-unambiguous'.
(auth-source-pass--find-match-unambiguous): New function.
(auth-source-pass--build-result): Fix the call to `find-match'.
(auth-source-pass--hostname, auth-source-pass--hostname-with-user,
auth-source-pass--user): Remove functions.
* test/lisp/auth-source-pass-tests.el: Fix the calls to `find-match'.
(auth-source-pass-find-host-without-port) Add corresponding test.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/auth-source-pass-tests.el | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el index 6d471f4e342..0f072592d00 100644 --- a/test/lisp/auth-source-pass-tests.el +++ b/test/lisp/auth-source-pass-tests.el | |||
| @@ -75,107 +75,100 @@ This function is intended to be set to `auth-source-debug`." | |||
| 75 | 75 | ||
| 76 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name () | 76 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name () |
| 77 | (auth-source-pass--with-store '(("foo")) | 77 | (auth-source-pass--with-store '(("foo")) |
| 78 | (should (equal (auth-source-pass--find-match "foo" nil) | 78 | (should (equal (auth-source-pass--find-match "foo" nil nil) |
| 79 | "foo")))) | 79 | "foo")))) |
| 80 | 80 | ||
| 81 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-part () | 81 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-part () |
| 82 | (auth-source-pass--with-store '(("foo")) | 82 | (auth-source-pass--with-store '(("foo")) |
| 83 | (should (equal (auth-source-pass--find-match "https://foo" nil) | 83 | (should (equal (auth-source-pass--find-match "https://foo" nil nil) |
| 84 | "foo")))) | 84 | "foo")))) |
| 85 | 85 | ||
| 86 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-ignoring-user () | 86 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-ignoring-user () |
| 87 | (auth-source-pass--with-store '(("foo")) | 87 | (auth-source-pass--with-store '(("foo")) |
| 88 | (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil) | 88 | (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil nil) |
| 89 | "foo")))) | 89 | "foo")))) |
| 90 | 90 | ||
| 91 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-with-user () | 91 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-with-user () |
| 92 | (auth-source-pass--with-store '(("SomeUser@foo")) | 92 | (auth-source-pass--with-store '(("SomeUser@foo")) |
| 93 | (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil) | 93 | (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil nil) |
| 94 | "SomeUser@foo")))) | 94 | "SomeUser@foo")))) |
| 95 | 95 | ||
| 96 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-prefer-full () | 96 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-prefer-full () |
| 97 | (auth-source-pass--with-store '(("SomeUser@foo") ("foo")) | 97 | (auth-source-pass--with-store '(("SomeUser@foo") ("foo")) |
| 98 | (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil) | 98 | (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil nil) |
| 99 | "SomeUser@foo")))) | 99 | "SomeUser@foo")))) |
| 100 | 100 | ||
| 101 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-prefer-full-reversed () | 101 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-prefer-full-reversed () |
| 102 | (auth-source-pass--with-store '(("foo") ("SomeUser@foo")) | 102 | (auth-source-pass--with-store '(("foo") ("SomeUser@foo")) |
| 103 | (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil) | 103 | (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil nil) |
| 104 | "SomeUser@foo")))) | 104 | "SomeUser@foo")))) |
| 105 | 105 | ||
| 106 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain () | 106 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain () |
| 107 | (auth-source-pass--with-store '(("bar.com")) | 107 | (auth-source-pass--with-store '(("bar.com")) |
| 108 | (should (equal (auth-source-pass--find-match "foo.bar.com" nil) | 108 | (should (equal (auth-source-pass--find-match "foo.bar.com" nil nil) |
| 109 | "bar.com")))) | 109 | "bar.com")))) |
| 110 | 110 | ||
| 111 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-with-user () | 111 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-with-user () |
| 112 | (auth-source-pass--with-store '(("someone@bar.com")) | 112 | (auth-source-pass--with-store '(("someone@bar.com")) |
| 113 | (should (equal (auth-source-pass--find-match "foo.bar.com" "someone") | 113 | (should (equal (auth-source-pass--find-match "foo.bar.com" "someone" nil) |
| 114 | "someone@bar.com")))) | 114 | "someone@bar.com")))) |
| 115 | 115 | ||
| 116 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-with-bad-user () | 116 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-with-bad-user () |
| 117 | (auth-source-pass--with-store '(("someoneelse@bar.com")) | 117 | (auth-source-pass--with-store '(("someoneelse@bar.com")) |
| 118 | (should (equal (auth-source-pass--find-match "foo.bar.com" "someone") | 118 | (should (equal (auth-source-pass--find-match "foo.bar.com" "someone" nil) |
| 119 | nil)))) | 119 | nil)))) |
| 120 | 120 | ||
| 121 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-prefer-full () | 121 | (ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-prefer-full () |
| 122 | (auth-source-pass--with-store '(("bar.com") ("foo.bar.com")) | 122 | (auth-source-pass--with-store '(("bar.com") ("foo.bar.com")) |
| 123 | (should (equal (auth-source-pass--find-match "foo.bar.com" nil) | 123 | (should (equal (auth-source-pass--find-match "foo.bar.com" nil nil) |
| 124 | "foo.bar.com")))) | 124 | "foo.bar.com")))) |
| 125 | 125 | ||
| 126 | (ert-deftest auth-source-pass-dont-match-at-folder-name () | 126 | (ert-deftest auth-source-pass-dont-match-at-folder-name () |
| 127 | (auth-source-pass--with-store '(("foo.bar.com/foo")) | 127 | (auth-source-pass--with-store '(("foo.bar.com/foo")) |
| 128 | (should (equal (auth-source-pass--find-match "foo.bar.com" nil) | 128 | (should (equal (auth-source-pass--find-match "foo.bar.com" nil nil) |
| 129 | nil)))) | 129 | nil)))) |
| 130 | 130 | ||
| 131 | (ert-deftest auth-source-pass-find-match-matching-extracting-user-from-host () | 131 | (ert-deftest auth-source-pass-find-match-matching-extracting-user-from-host () |
| 132 | (auth-source-pass--with-store '(("foo.com/bar")) | 132 | (auth-source-pass--with-store '(("foo.com/bar")) |
| 133 | (should (equal (auth-source-pass--find-match "https://bar@foo.com" nil) | 133 | (should (equal (auth-source-pass--find-match "https://bar@foo.com" nil nil) |
| 134 | "foo.com/bar")))) | 134 | "foo.com/bar")))) |
| 135 | 135 | ||
| 136 | (ert-deftest auth-source-pass-search-with-user-first () | 136 | (ert-deftest auth-source-pass-search-with-user-first () |
| 137 | (auth-source-pass--with-store '(("foo") ("user@foo")) | 137 | (auth-source-pass--with-store '(("foo") ("user@foo")) |
| 138 | (should (equal (auth-source-pass--find-match "foo" "user") | 138 | (should (equal (auth-source-pass--find-match "foo" "user" nil) |
| 139 | "user@foo")) | 139 | "user@foo")) |
| 140 | (auth-source-pass--should-have-message-containing "Found 1 match"))) | 140 | (auth-source-pass--should-have-message-containing "Found 1 match"))) |
| 141 | 141 | ||
| 142 | (ert-deftest auth-source-pass-give-priority-to-desired-user () | 142 | (ert-deftest auth-source-pass-give-priority-to-desired-user () |
| 143 | (auth-source-pass--with-store '(("foo") ("subdir/foo" ("user" . "someone"))) | 143 | (auth-source-pass--with-store '(("foo") ("subdir/foo" ("user" . "someone"))) |
| 144 | (should (equal (auth-source-pass--find-match "foo" "someone") | 144 | (should (equal (auth-source-pass--find-match "foo" "someone" nil) |
| 145 | "subdir/foo")) | 145 | "subdir/foo")) |
| 146 | (auth-source-pass--should-have-message-containing "Found 2 matches") | 146 | (auth-source-pass--should-have-message-containing "Found 2 matches") |
| 147 | (auth-source-pass--should-have-message-containing "matching user field"))) | 147 | (auth-source-pass--should-have-message-containing "matching user field"))) |
| 148 | 148 | ||
| 149 | (ert-deftest auth-source-pass-give-priority-to-desired-user-reversed () | 149 | (ert-deftest auth-source-pass-give-priority-to-desired-user-reversed () |
| 150 | (auth-source-pass--with-store '(("foo" ("user" . "someone")) ("subdir/foo")) | 150 | (auth-source-pass--with-store '(("foo" ("user" . "someone")) ("subdir/foo")) |
| 151 | (should (equal (auth-source-pass--find-match "foo" "someone") | 151 | (should (equal (auth-source-pass--find-match "foo" "someone" nil) |
| 152 | "foo")) | 152 | "foo")) |
| 153 | (auth-source-pass--should-have-message-containing "Found 2 matches") | 153 | (auth-source-pass--should-have-message-containing "Found 2 matches") |
| 154 | (auth-source-pass--should-have-message-containing "matching user field"))) | 154 | (auth-source-pass--should-have-message-containing "matching user field"))) |
| 155 | 155 | ||
| 156 | (ert-deftest auth-source-pass-return-first-when-several-matches () | 156 | (ert-deftest auth-source-pass-return-first-when-several-matches () |
| 157 | (auth-source-pass--with-store '(("foo") ("subdir/foo")) | 157 | (auth-source-pass--with-store '(("foo") ("subdir/foo")) |
| 158 | (should (equal (auth-source-pass--find-match "foo" nil) | 158 | (should (equal (auth-source-pass--find-match "foo" nil nil) |
| 159 | "foo")) | 159 | "foo")) |
| 160 | (auth-source-pass--should-have-message-containing "Found 2 matches") | 160 | (auth-source-pass--should-have-message-containing "Found 2 matches") |
| 161 | (auth-source-pass--should-have-message-containing "the first one"))) | 161 | (auth-source-pass--should-have-message-containing "the first one"))) |
| 162 | 162 | ||
| 163 | (ert-deftest auth-source-pass-make-divansantana-happy () | 163 | (ert-deftest auth-source-pass-make-divansantana-happy () |
| 164 | (auth-source-pass--with-store '(("host.com")) | 164 | (auth-source-pass--with-store '(("host.com")) |
| 165 | (should (equal (auth-source-pass--find-match "smtp.host.com" "myusername@host.co.za") | 165 | (should (equal (auth-source-pass--find-match "smtp.host.com" "myusername@host.co.za" nil) |
| 166 | "host.com")))) | 166 | "host.com")))) |
| 167 | 167 | ||
| 168 | (ert-deftest auth-source-pass-hostname () | 168 | (ert-deftest auth-source-pass-find-host-without-port () |
| 169 | (should (equal (auth-source-pass--hostname "https://foo.bar:443") "foo.bar")) | 169 | (auth-source-pass--with-store '(("host.com")) |
| 170 | (should (equal (auth-source-pass--hostname "https://foo.bar") "foo.bar")) | 170 | (should (equal (auth-source-pass--find-match "host.com:8888" "someuser" nil) |
| 171 | (should (equal (auth-source-pass--hostname "http://foo.bar") "foo.bar")) | 171 | "host.com")))) |
| 172 | (should (equal (auth-source-pass--hostname "https://SomeUser@foo.bar") "foo.bar"))) | ||
| 173 | |||
| 174 | (ert-deftest auth-source-pass-hostname-with-user () | ||
| 175 | (should (equal (auth-source-pass--hostname-with-user "https://foo.bar:443") "foo.bar")) | ||
| 176 | (should (equal (auth-source-pass--hostname-with-user "https://foo.bar") "foo.bar")) | ||
| 177 | (should (equal (auth-source-pass--hostname-with-user "http://foo.bar") "foo.bar")) | ||
| 178 | (should (equal (auth-source-pass--hostname-with-user "https://SomeUser@foo.bar") "SomeUser@foo.bar"))) | ||
| 179 | 172 | ||
| 180 | (defmacro auth-source-pass--with-store-find-foo (store &rest body) | 173 | (defmacro auth-source-pass--with-store-find-foo (store &rest body) |
| 181 | "Use STORE while executing BODY. \"foo\" is the matched entry." | 174 | "Use STORE while executing BODY. \"foo\" is the matched entry." |
| @@ -207,7 +200,7 @@ This function is intended to be set to `auth-source-debug`." | |||
| 207 | (ert-deftest auth-source-pass-build-result-passes-full-host-to-find-match () | 200 | (ert-deftest auth-source-pass-build-result-passes-full-host-to-find-match () |
| 208 | (let (passed-host) | 201 | (let (passed-host) |
| 209 | (cl-letf (((symbol-function 'auth-source-pass--find-match) | 202 | (cl-letf (((symbol-function 'auth-source-pass--find-match) |
| 210 | (lambda (host _user) (setq passed-host host)))) | 203 | (lambda (host _user _port) (setq passed-host host)))) |
| 211 | (auth-source-pass--build-result "https://user@host.com:123" nil nil) | 204 | (auth-source-pass--build-result "https://user@host.com:123" nil nil) |
| 212 | (should (equal passed-host "https://user@host.com:123")) | 205 | (should (equal passed-host "https://user@host.com:123")) |
| 213 | (auth-source-pass--build-result "https://user@host.com" nil nil) | 206 | (auth-source-pass--build-result "https://user@host.com" nil nil) |