aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJarno Malmari2017-04-01 09:19:46 +0300
committerEli Zaretskii2017-04-01 09:19:46 +0300
commit5b264d88792fec2a31a48c0de5ffe396c3c14604 (patch)
treeec7ddb582bdcca9e795cc803046c35207b6e254e /test
parent226cafd24df9c233f6359c93273d4da22db7f62d (diff)
downloademacs-5b264d88792fec2a31a48c0de5ffe396c3c14604.tar.gz
emacs-5b264d88792fec2a31a48c0de5ffe396c3c14604.zip
Initial implementation of HTTP Digest qop for url
This also refactors digest authentication functions in url-auth.el. * lisp/url/url-auth.el (url-digest-auth, url-digest-auth-create-key): (url-digest-auth-build-response, url-digest-auth-directory-id-assoc): (url-digest-auth-name-value-string, url-digest-auth-source-creds): (url-digest-cached-key, url-digest-cache-key, url-digest-find-creds): (url-digest-find-new-key, url-digest-prompt-creds): Add new functions to simplify code and aid in unit testing. (url-digest-auth-build-response): Hook up new functionality, or fall back to previous. (url-digest-auth-make-request-digest-qop): (url-digest-auth-make-cnonce, url-digest-auth-nonce-count): (url-digest-auth-name-value-string): Add new helper functions. * test/lisp/url/url-auth-tests.el (url-auth-test-colonjoin): (url-auth-test-digest-ha1, url-auth-test-digest-ha2): (url-auth-test-digest-request-digest): Add a few tests as now more features are testable via intermediate functions. (url-auth-test-challenges, url-auth-test-digest-request-digest): Test the new implementation. Parts of these were accidentally already merged in the past.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/url/url-auth-tests.el51
1 files changed, 46 insertions, 5 deletions
diff --git a/test/lisp/url/url-auth-tests.el b/test/lisp/url/url-auth-tests.el
index 11e5a479720..30636db083c 100644
--- a/test/lisp/url/url-auth-tests.el
+++ b/test/lisp/url/url-auth-tests.el
@@ -77,6 +77,49 @@ server's WWW-Authenticate header field.")
77 :expected-ha2 "b44272ea65ee4af7fb26c5dba58f6863" 77 :expected-ha2 "b44272ea65ee4af7fb26c5dba58f6863"
78 :expected-response "0d84884d967e04440efc77e9e2b5b561"))) 78 :expected-response "0d84884d967e04440efc77e9e2b5b561")))
79 79
80(ert-deftest url-auth-test-colonjoin ()
81 "Check joining strings with `:'."
82 (should (string= (url-digest-auth-colonjoin) ""))
83 (should (string= (url-digest-auth-colonjoin nil) ""))
84 (should (string= (url-digest-auth-colonjoin nil nil nil) "::"))
85 (should (string= (url-digest-auth-colonjoin "") ""))
86 (should (string= (url-digest-auth-colonjoin "" "") ":"))
87 (should (string= (url-digest-auth-colonjoin "one") "one"))
88 (should (string= (url-digest-auth-colonjoin "one" "two" "three") "one:two:three")))
89
90(ert-deftest url-auth-test-digest-ha1 ()
91 "Check HA1 computation."
92 (dolist (row url-auth-test-challenges)
93 (should (string= (url-digest-auth-make-ha1 (plist-get row :username)
94 (plist-get row :realm)
95 (plist-get row :password))
96 (plist-get row :expected-ha1)
97 ))))
98
99(ert-deftest url-auth-test-digest-ha2 ()
100 "Check HA2 computation."
101 (dolist (row url-auth-test-challenges)
102 (should (string= (url-digest-auth-make-ha2 (plist-get row :method)
103 (plist-get row :uri))
104 (plist-get row :expected-ha2)))))
105
106(ert-deftest url-auth-test-digest-request-digest ()
107 "Check digest response value."
108 (dolist (row url-auth-test-challenges)
109 (should (string= (plist-get row :expected-response)
110 (if (plist-member row :qop)
111 (url-digest-auth-make-request-digest-qop
112 (plist-get row :qop)
113 (plist-get row :expected-ha1)
114 (plist-get row :expected-ha2)
115 (plist-get row :nonce)
116 (plist-get row :nc)
117 (plist-get row :cnonce))
118 (url-digest-auth-make-request-digest
119 (plist-get row :expected-ha1)
120 (plist-get row :expected-ha2)
121 (plist-get row :nonce)))))))
122
80(ert-deftest url-auth-test-digest-create-key () 123(ert-deftest url-auth-test-digest-create-key ()
81 "Check user credentials in their hashed form." 124 "Check user credentials in their hashed form."
82 (dolist (challenge url-auth-test-challenges) 125 (dolist (challenge url-auth-test-challenges)
@@ -223,14 +266,12 @@ test and cannot be passed by arguments to `url-digest-auth'."
223 (progn 266 (progn
224 ;; We don't know these, just check that they exists. 267 ;; We don't know these, just check that they exists.
225 (should (string-match-p ".*response=\".*?\".*" auth)) 268 (should (string-match-p ".*response=\".*?\".*" auth))
226 ;; url-digest-auth doesn't return these AFAICS. 269 (should (string-match-p ".*nc=\".*?\".*" auth))
227;;; (should (string-match-p ".*nc=\".*?\".*" auth)) 270 (should (string-match-p ".*cnonce=\".*?\".*" auth)))
228;;; (should (string-match-p ".*cnonce=\".*?\".*" auth))
229 )
230 (should (string-match ".*response=\"\\(.*?\\)\".*" auth)) 271 (should (string-match ".*response=\"\\(.*?\\)\".*" auth))
231 (should (string= (match-string 1 auth) 272 (should (string= (match-string 1 auth)
232 (plist-get challenge :expected-response)))) 273 (plist-get challenge :expected-response))))
233 ))) 274 )))
234 275
235(ert-deftest url-auth-test-digest-auth-opaque () 276(ert-deftest url-auth-test-digest-auth-opaque ()
236 "Check that `opaque' value is added to result when presented by 277 "Check that `opaque' value is added to result when presented by