aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDamien Cassou2017-04-03 21:36:03 +0200
committerTed Zlatanov2017-04-26 15:11:35 -0400
commit14ff8b1fb60459c4c5cb147e07e3902dc569f8e0 (patch)
treef2200f9516a295cc6ae28593eb2ca12d5efee1dd /test
parentc2d4ed8f2ee18d5e3fb56b31c2e1b784b1ea70e0 (diff)
downloademacs-feature/auth-source-pass.tar.gz
emacs-feature/auth-source-pass.zip
auth-source-pass: Add documentation; fix tests and indentation.feature/auth-source-pass
* doc/misc/auth.texi: Document new integration with Pass. Use @itemize instead of @enumerate. * lisp/auth-source-pass.el: Fix indentation. (auth-source-pass--remove-directory-name): Remove. * test/lisp/auth-source-pass-tests.el: Adjust test macros.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/auth-source-pass-tests.el243
1 files changed, 116 insertions, 127 deletions
diff --git a/test/lisp/auth-source-pass-tests.el b/test/lisp/auth-source-pass-tests.el
index 1a7c9a70365..102611d2fae 100644
--- a/test/lisp/auth-source-pass-tests.el
+++ b/test/lisp/auth-source-pass-tests.el
@@ -63,108 +63,102 @@
63This function is intended to be set to `auth-source-debug`." 63This function is intended to be set to `auth-source-debug`."
64 (add-to-list 'auth-source-pass--debug-log (apply #'format msg) t)) 64 (add-to-list 'auth-source-pass--debug-log (apply #'format msg) t))
65 65
66(defmacro auth-source-pass--deftest (name arglist store &rest body) 66(defmacro auth-source-pass--with-store (store &rest body)
67 "Define a new ert-test NAME with ARGLIST using STORE as password-store. 67 "Use STORE as password-store while executing BODY."
68BODY is a sequence of instructions that will be evaluated. 68 (declare (indent 1))
69 69 `(cl-letf (((symbol-function 'auth-source-pass-parse-entry) (lambda (entry) (cdr (cl-find entry ,store :key #'car :test #'string=))) )
70This macro overrides `auth-source-pass-parse-entry' and `auth-source-pass-entries' to 70 ((symbol-function 'auth-source-pass-entries) (lambda () (mapcar #'car ,store)))
71test code without touching the file system." 71 ((symbol-function 'auth-source-pass--entry-valid-p) (lambda (_entry) t)))
72 (declare (indent 3)) 72 (let ((auth-source-debug #'auth-source-pass--debug)
73 `(ert-deftest ,name ,arglist 73 (auth-source-pass--debug-log nil))
74 (cl-letf (((symbol-function 'auth-source-pass-parse-entry) (lambda (entry) (cdr (cl-find entry ,store :key #'car :test #'string=))) ) 74 ,@body)))
75 ((symbol-function 'auth-source-pass-entries) (lambda () (mapcar #'car ,store))) 75
76 ((symbol-function 'auth-source-pass--entry-valid-p) (lambda (_entry) t))) 76(ert-deftest auth-source-pass-find-match-matching-at-entry-name ()
77 (let ((auth-source-debug #'auth-source-pass--debug) 77 (auth-source-pass--with-store '(("foo"))
78 (auth-source-pass--debug-log nil)) 78 (should (equal (auth-source-pass--find-match "foo" nil)
79 ,@body)))) 79 "foo"))))
80 80
81(auth-source-pass--deftest auth-source-pass-find-match-matching-at-entry-name () 81(ert-deftest auth-source-pass-find-match-matching-at-entry-name-part ()
82 '(("foo")) 82 (auth-source-pass--with-store '(("foo"))
83 (should (equal (auth-source-pass--find-match "foo" nil) 83 (should (equal (auth-source-pass--find-match "https://foo" nil)
84 "foo"))) 84 "foo"))))
85 85
86(auth-source-pass--deftest auth-source-pass-find-match-matching-at-entry-name-part () 86(ert-deftest auth-source-pass-find-match-matching-at-entry-name-ignoring-user ()
87 '(("foo")) 87 (auth-source-pass--with-store '(("foo"))
88 (should (equal (auth-source-pass--find-match "https://foo" nil) 88 (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil)
89 "foo"))) 89 "foo"))))
90 90
91(auth-source-pass--deftest auth-source-pass-find-match-matching-at-entry-name-ignoring-user () 91(ert-deftest auth-source-pass-find-match-matching-at-entry-name-with-user ()
92 '(("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)
94 "foo"))) 94 "SomeUser@foo"))))
95 95
96(auth-source-pass--deftest auth-source-pass-find-match-matching-at-entry-name-with-user () 96(ert-deftest auth-source-pass-find-match-matching-at-entry-name-prefer-full ()
97 '(("SomeUser@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)
99 "SomeUser@foo"))) 99 "SomeUser@foo"))))
100 100
101(auth-source-pass--deftest auth-source-pass-find-match-matching-at-entry-name-prefer-full () 101(ert-deftest auth-source-pass-find-match-matching-at-entry-name-prefer-full-reversed ()
102 '(("SomeUser@foo") ("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)
104 "SomeUser@foo"))) 104 "SomeUser@foo"))))
105 105
106;; same as previous one except the store is in another order 106(ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain ()
107(auth-source-pass--deftest auth-source-pass-find-match-matching-at-entry-name-prefer-full-reversed () 107 (auth-source-pass--with-store '(("bar.com"))
108 '(("foo") ("SomeUser@foo")) 108 (should (equal (auth-source-pass--find-match "foo.bar.com" nil)
109 (should (equal (auth-source-pass--find-match "https://SomeUser@foo" nil) 109 "bar.com"))))
110 "SomeUser@foo"))) 110
111 111(ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-with-user ()
112(auth-source-pass--deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain () 112 (auth-source-pass--with-store '(("someone@bar.com"))
113 '(("bar.com")) 113 (should (equal (auth-source-pass--find-match "foo.bar.com" "someone")
114 (should (equal (auth-source-pass--find-match "foo.bar.com" nil) 114 "someone@bar.com"))))
115 "bar.com"))) 115
116 116(ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-with-bad-user ()
117(auth-source-pass--deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-with-user () 117 (auth-source-pass--with-store '(("someoneelse@bar.com"))
118 '(("someone@bar.com")) 118 (should (equal (auth-source-pass--find-match "foo.bar.com" "someone")
119 (should (equal (auth-source-pass--find-match "foo.bar.com" "someone") 119 nil))))
120 "someone@bar.com"))) 120
121 121(ert-deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-prefer-full ()
122(auth-source-pass--deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-with-bad-user () 122 (auth-source-pass--with-store '(("bar.com") ("foo.bar.com"))
123 '(("someoneelse@bar.com")) 123 (should (equal (auth-source-pass--find-match "foo.bar.com" nil)
124 (should (equal (auth-source-pass--find-match "foo.bar.com" "someone") 124 "foo.bar.com"))))
125 nil))) 125
126 126(ert-deftest auth-source-pass-dont-match-at-folder-name ()
127(auth-source-pass--deftest auth-source-pass-find-match-matching-at-entry-name-without-subdomain-prefer-full () 127 (auth-source-pass--with-store '(("foo.bar.com/foo"))
128 '(("bar.com") ("foo.bar.com")) 128 (should (equal (auth-source-pass--find-match "foo.bar.com" nil)
129 (should (equal (auth-source-pass--find-match "foo.bar.com" nil) 129 nil))))
130 "foo.bar.com"))) 130
131 131(ert-deftest auth-source-pass-search-with-user-first ()
132(auth-source-pass--deftest auth-source-pass-dont-match-at-folder-name () 132 (auth-source-pass--with-store '(("foo") ("user@foo"))
133 '(("foo.bar.com/foo")) 133 (should (equal (auth-source-pass--find-match "foo" "user")
134 (should (equal (auth-source-pass--find-match "foo.bar.com" nil) 134 "user@foo"))
135 nil))) 135 (auth-source-pass--should-have-message-containing "Found 1 match")))
136 136
137(auth-source-pass--deftest auth-source-pass-search-with-user-first () 137(ert-deftest auth-source-pass-give-priority-to-desired-user ()
138 '(("foo") ("user@foo")) 138 (auth-source-pass--with-store '(("foo") ("subdir/foo" ("user" . "someone")))
139 (should (equal (auth-source-pass--find-match "foo" "user") 139 (should (equal (auth-source-pass--find-match "foo" "someone")
140 "user@foo")) 140 "subdir/foo"))
141 (auth-source-pass--should-have-message-containing "Found 1 match")) 141 (auth-source-pass--should-have-message-containing "Found 2 matches")
142 142 (auth-source-pass--should-have-message-containing "matching user field")))
143(auth-source-pass--deftest auth-source-pass-give-priority-to-desired-user () 143
144 '(("foo") ("subdir/foo" ("user" . "someone"))) 144(ert-deftest auth-source-pass-give-priority-to-desired-user-reversed ()
145 (should (equal (auth-source-pass--find-match "foo" "someone") 145 (auth-source-pass--with-store '(("foo" ("user" . "someone")) ("subdir/foo"))
146 "subdir/foo")) 146 (should (equal (auth-source-pass--find-match "foo" "someone")
147 (auth-source-pass--should-have-message-containing "Found 2 matches") 147 "foo"))
148 (auth-source-pass--should-have-message-containing "matching user field")) 148 (auth-source-pass--should-have-message-containing "Found 2 matches")
149 149 (auth-source-pass--should-have-message-containing "matching user field")))
150(auth-source-pass--deftest auth-source-pass-give-priority-to-desired-user-reversed () 150
151 '(("foo" ("user" . "someone")) ("subdir/foo")) 151(ert-deftest auth-source-pass-return-first-when-several-matches ()
152 (should (equal (auth-source-pass--find-match "foo" "someone") 152 (auth-source-pass--with-store '(("foo") ("subdir/foo"))
153 "foo")) 153 (should (equal (auth-source-pass--find-match "foo" nil)
154 (auth-source-pass--should-have-message-containing "Found 2 matches") 154 "foo"))
155 (auth-source-pass--should-have-message-containing "matching user field")) 155 (auth-source-pass--should-have-message-containing "Found 2 matches")
156 156 (auth-source-pass--should-have-message-containing "the first one")))
157(auth-source-pass--deftest auth-source-pass-return-first-when-several-matches () 157
158 '(("foo") ("subdir/foo")) 158(ert-deftest auth-source-pass-make-divansantana-happy ()
159 (should (equal (auth-source-pass--find-match "foo" nil) 159 (auth-source-pass--with-store '(("host.com"))
160 "foo")) 160 (should (equal (auth-source-pass--find-match "smtp.host.com" "myusername@host.co.za")
161 (auth-source-pass--should-have-message-containing "Found 2 matches") 161 "host.com"))))
162 (auth-source-pass--should-have-message-containing "the first one"))
163
164(auth-source-pass--deftest auth-source-pass-make-divansantana-happy ()
165 '(("host.com"))
166 (should (equal (auth-source-pass--find-match "smtp.host.com" "myusername@host.co.za")
167 "host.com")))
168 162
169(ert-deftest auth-source-pass-hostname () 163(ert-deftest auth-source-pass-hostname ()
170 (should (equal (auth-source-pass--hostname "https://foo.bar") "foo.bar")) 164 (should (equal (auth-source-pass--hostname "https://foo.bar") "foo.bar"))
@@ -176,37 +170,32 @@ test code without touching the file system."
176 (should (equal (auth-source-pass--hostname-with-user "http://foo.bar") "foo.bar")) 170 (should (equal (auth-source-pass--hostname-with-user "http://foo.bar") "foo.bar"))
177 (should (equal (auth-source-pass--hostname-with-user "https://SomeUser@foo.bar") "SomeUser@foo.bar"))) 171 (should (equal (auth-source-pass--hostname-with-user "https://SomeUser@foo.bar") "SomeUser@foo.bar")))
178 172
179(defmacro auth-source-pass--deftest-build-result (name arglist store &rest body) 173(defmacro auth-source-pass--with-store-find-foo (store &rest body)
180 "Define a new ert-test NAME with ARGLIST using STORE as password-store. 174 "Use STORE while executing BODY. \"foo\" is the matched entry."
181BODY is a sequence of instructions that will be evaluated. 175 (declare (indent 1))
182 176 `(auth-source-pass--with-store ,store
183This macro overrides `auth-source-pass-parse-entry',
184`auth-source-pass-entries', and `auth-source-pass--find-match' to
185ease testing."
186 (declare (indent 3))
187 `(auth-source-pass--deftest ,name ,arglist ,store
188 (cl-letf (((symbol-function 'auth-source-pass-find-match) 177 (cl-letf (((symbol-function 'auth-source-pass-find-match)
189 (lambda (_host _user) 178 (lambda (_host _user)
190 "foo"))) 179 "foo")))
191 ,@body))) 180 ,@body)))
192 181
193(auth-source-pass--deftest-build-result auth-source-pass-build-result-return-parameters () 182(ert-deftest auth-source-pass-build-result-return-parameters ()
194 '(("foo")) 183 (auth-source-pass--with-store-find-foo '(("foo"))
195 (let ((result (auth-source-pass--build-result "foo" 512 "user"))) 184 (let ((result (auth-source-pass--build-result "foo" 512 "user")))
196 (should (equal (plist-get result :port) 512)) 185 (should (equal (plist-get result :port) 512))
197 (should (equal (plist-get result :user) "user")))) 186 (should (equal (plist-get result :user) "user")))))
198 187
199(auth-source-pass--deftest-build-result auth-source-pass-build-result-return-entry-values () 188(ert-deftest auth-source-pass-build-result-return-entry-values ()
200 '(("foo" ("port" . 512) ("user" . "anuser"))) 189 (auth-source-pass--with-store-find-foo '(("foo" ("port" . 512) ("user" . "anuser")))
201 (let ((result (auth-source-pass--build-result "foo" nil nil))) 190 (let ((result (auth-source-pass--build-result "foo" nil nil)))
202 (should (equal (plist-get result :port) 512)) 191 (should (equal (plist-get result :port) 512))
203 (should (equal (plist-get result :user) "anuser")))) 192 (should (equal (plist-get result :user) "anuser")))))
204 193
205(auth-source-pass--deftest-build-result auth-source-pass-build-result-entry-takes-precedence () 194(ert-deftest auth-source-pass-build-result-entry-takes-precedence ()
206 '(("foo" ("port" . 512) ("user" . "anuser"))) 195 (auth-source-pass--with-store-find-foo '(("foo" ("port" . 512) ("user" . "anuser")))
207 (let ((result (auth-source-pass--build-result "foo" 1024 "anotheruser"))) 196 (let ((result (auth-source-pass--build-result "foo" 1024 "anotheruser")))
208 (should (equal (plist-get result :port) 512)) 197 (should (equal (plist-get result :port) 512))
209 (should (equal (plist-get result :user) "anuser")))) 198 (should (equal (plist-get result :user) "anuser")))))
210 199
211(ert-deftest auth-source-pass-only-return-entries-that-can-be-open () 200(ert-deftest auth-source-pass-only-return-entries-that-can-be-open ()
212 (cl-letf (((symbol-function 'auth-source-pass-entries) 201 (cl-letf (((symbol-function 'auth-source-pass-entries)
@@ -220,7 +209,7 @@ ease testing."
220 '("foo.site.com"))) 209 '("foo.site.com")))
221 (should (equal (auth-source-pass--find-all-by-entry-name "bar.site.com" "someuser") 210 (should (equal (auth-source-pass--find-all-by-entry-name "bar.site.com" "someuser")
222 '())) 211 '()))
223 (should (equal (auth-pass--find-all-by-entry-name "baz.site.com" "scott") 212 (should (equal (auth-source-pass--find-all-by-entry-name "baz.site.com" "scott")
224 '("mail/baz.site.com/scott"))))) 213 '("mail/baz.site.com/scott")))))
225 214
226(ert-deftest auth-source-pass-entry-is-not-valid-when-unreadable () 215(ert-deftest auth-source-pass-entry-is-not-valid-when-unreadable ()