(eword-decode-string, eword-decode-region): Mention language info in doc string.
[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"))))
61
62 (luna-define-method test-sasl-scram-md5-imap ((case test-sasl))
63   (let* ((sasl-mechanisms '("SCRAM-MD5"))
64          (mechanism
65           (sasl-find-mechanism '("SCRAM-MD5")))
66          (client
67           (sasl-make-client mechanism "chris" "imap" "eleanor.innosoft.com"))
68          (sasl-read-passphrase
69           #'(lambda (prompt)
70               "secret stuff"))
71          step
72          response)
73     (sasl-client-set-property client 'nonce
74                               "<t4n4Pab9HB0Am/QLXB72eg@eleanor.innosoft.com>")
75     (setq step (sasl-next-step client nil))
76     (sasl-step-set-data step "")
77     (setq step (sasl-next-step client step))
78     (sasl-step-set-data
79      step
80      (base64-decode-string
81       "dGVzdHNhbHQBAAAAaW1hcEBlbGVhbm9yLmlubm9zb2Z0LmNvbQBqaGNOWmxSdVBiemlGcCt2TFYrTkN3"))
82     (setq step (sasl-next-step client step))
83     (lunit-assert
84      (string= (sasl-step-data step)
85            (base64-decode-string "AQAAAMg9jU8CeB4KOfk7sUhSQPs=")))))
86
87 (luna-define-method test-sasl-ntlm-imap ((case test-sasl))
88   (let* ((sasl-mechanisms '("NTLM"))
89          (mechanism
90           (sasl-find-mechanism '("NTLM")))
91          (client
92           (sasl-make-client mechanism "kawagish@nokiaseap" "imap" "xxx.yyy.com"))
93          (sasl-read-passphrase
94           #'(lambda (passphrase)
95               "!\"#456secret"))
96          step
97          response)
98     ;; init
99     (setq step (sasl-next-step client nil))
100     ;; generate authentication request
101     (sasl-step-set-data step "")
102     (setq step (sasl-next-step client step))
103     (sasl-step-data step)
104     ;; (base64-encode-string (sasl-step-data step) t) is sent to server
105     ;; generate response to challenge
106     (sasl-step-set-data
107      step
108      (string-as-unibyte
109       (base64-decode-string
110        "TlRMTVNTUAACAAAADAAMADAAAAAFggEApmEjGvh9M8YAAAAAAAAAAAAAAAA8AAAATgBPAEsARQBYAEMA")))
111     (setq step (sasl-next-step client step))
112     (sasl-step-data step)
113     (setq response (base64-encode-string (sasl-step-data step) t))
114     (lunit-assert
115      (string=
116       response "TlRMTVNTUAADAAAAGAAYAEAAAAAYABgAWAAAABIAEgBwAAAAEAAQAIIAAAAQABAAkgAAAAAAAABiAAAABYIBAIwN9i7qK/9Y31dIDR6JQTaBbjcLJm8Sc6VogMe7fnHP96+eQ5Yf3ys2nIY4rx+iQG4AbwBrAGkAYQBzAGUAYQBwAGsAYQB3AGEAZwBpAHMAaABrAGEAdwBhAGcAaQBzAGgA"))
117 ;;response
118 ))