* sasl-digest.el (sasl-digest-md5-challenge): Abolish.
[elisp/flim.git] / tests / test-sasl.el
1 (require 'lunit)
2 (require 'sasl)
3
4 (luna-define-class test-sasl (lunit-test-case))
5
6 (luna-define-method test-sasl-find-mechanism ((case test-sasl))
7   (let ((mechanisms sasl-mechanisms))
8     (while mechanisms
9       (let* ((sasl-mechanisms (list (car mechanisms))))
10         (lunit-assert
11          (sasl-find-mechanism (list (car mechanisms)))))
12       (setq mechanisms (cdr mechanisms)))))
13
14 (luna-define-method test-sasl-digest-md5-imap ((case test-sasl))
15   (let* ((sasl-mechanisms '("DIGEST-MD5"))
16          (mechanism
17           (sasl-find-mechanism '("DIGEST-MD5")))
18          (client
19           (sasl-make-client mechanism "chris" "imap" "elwood.innosoft.com"))
20          (sasl-read-passphrase
21           #'(lambda (prompt)
22               "secret"))
23          step
24          response)
25     (sasl-client-set-property client 'realm "elwood.innosoft.com")
26     (sasl-client-set-property client 'cnonce "OA6MHXh6VqTrRk")
27     (setq step (sasl-next-step client nil))
28     (sasl-step-set-data
29      step "realm=\"elwood.innosoft.com\",nonce=\"OA6MG9tEQGm2hh\",\
30 qop=\"auth\",algorithm=md5-sess,charset=utf-8")
31     (setq step (sasl-next-step client step))
32     (sasl-step-data step)
33     (setq response (sasl-digest-md5-parse-string (sasl-step-data step)))
34     (lunit-assert
35      (string=
36       (plist-get response 'response) "d388dad90d4bbd760a152321f2143af7"))))
37
38 (luna-define-method test-sasl-digest-md5-acap ((case test-sasl))
39   (let* ((sasl-mechanisms '("DIGEST-MD5"))
40          (mechanism
41           (sasl-find-mechanism '("DIGEST-MD5")))
42          (client
43           (sasl-make-client mechanism "chris" "acap" "elwood.innosoft.com"))
44          (sasl-read-passphrase
45           #'(lambda (prompt)
46               "secret"))
47          step
48          response)
49     (sasl-client-set-property client 'realm "elwood.innosoft.com")
50     (sasl-client-set-property client 'cnonce "OA9BSuZWMSpW8m")
51     (setq step (sasl-next-step client nil))
52     (sasl-step-set-data
53      step "realm=\"elwood.innosoft.com\",nonce=\"OA9BSXrbuRhWay\",qop=\"auth\",\
54 algorithm=md5-sess,charset=utf-8")
55     (setq step (sasl-next-step client step))
56     (sasl-step-data step)
57     (setq response (sasl-digest-md5-parse-string (sasl-step-data step)))
58     (lunit-assert
59      (string=
60       (plist-get response 'response) "6084c6db3fede7352c551284490fd0fc"))))