3 # Test the XOAUTH2 support in send
6 if test -z "${MH_OBJ_DIR}"; then
7 srcdir
=`dirname "$0"`/..
/..
8 MH_OBJ_DIR
=`cd "${srcdir}" && pwd`; export MH_OBJ_DIR
11 .
"${srcdir}/test/oauth/common.sh"
13 check_exit
'-eq 1' send
-
15 test_send_only_fakehttp
() {
17 test_send_no_servers
"$@"
26 XOAUTH
='dXNlcj1ub2JvZHlAZXhhbXBsZS5jb20BYXV0aD1CZWFyZXIgdGVzdC1hY2Nlc3MBAQ=='
29 start_test
'access token ready, smtp server accepts message'
34 access-nobody@example.com: test-access
35 refresh-nobody@example.com: test-refresh
36 expire-nobody@example.com: 2000000000
40 run_test
"send -draft -server 127.0.0.1 -port ${smtp_port} -sasl -saslmech xoauth2 -authservice test -user nobody@example.com"
43 start_test
'expired access token, refresh works, smtp server accepts message'
48 access-nobody@example.com: old-access
49 refresh-nobody@example.com: test-refresh
50 expire-nobody@example.com: 1414303986
53 expect_http_post_refresh
55 fake_json_response
<<EOF
57 "access_token": "test-access",
58 "token_type": "Bearer",
64 access-nobody@example.com: test-access
65 refresh-nobody@example.com: test-refresh
66 expire-nobody@example.com:
75 start_test
'expired access token, refresh works and gets updated, smtp server accepts message'
80 access-nobody@example.com: old-access
81 refresh-nobody@example.com: old-refresh
82 expire-nobody@example.com: 1414303986
85 expect_http_post_old_refresh
87 fake_json_response
<<EOF
89 "access_token": "test-access",
90 "refresh_token": "test-refresh",
91 "token_type": "Bearer"
96 access-nobody@example.com: test-access
97 refresh-nobody@example.com: test-refresh
105 start_test
'access token has no expiration, refresh works, smtp server accepts message'
110 access-nobody@example.com: old-access
111 refresh-nobody@example.com: test-refresh
114 expect_http_post_refresh
116 fake_json_response
<<EOF
118 "access_token": "test-access",
119 "token_type": "Bearer"
124 access-nobody@example.com: test-access
125 refresh-nobody@example.com: test-refresh
133 start_test
'no access token, refresh works, smtp server accepts message'
138 refresh-nobody@example.com: test-refresh
141 expect_http_post_refresh
143 fake_json_response
<<EOF
145 "access_token": "test-access",
146 "token_type": "Bearer"
151 access-nobody@example.com: test-access
152 refresh-nobody@example.com: test-refresh
166 start_test
'no service definition'
168 run_test
"send -draft -server 127.0.0.1 -port ${smtp_port} -sasl -saslmech xoauth2 -authservice bogus -user nobody@example.com" 'send: Unable to retrieve oauth profile entries: scope is missing'
171 start_test
'no creds file -- should tell user to mhlogin'
173 rm -f "${MHTMPDIR}/oauth-test"
175 test_send_only_fakesmtp
'post: no credentials -- run mhlogin -saslmech xoauth2 -authservice test
176 send: message not delivered to anyone'
179 start_test
'empty creds file -- should tell user to mhlogin'
181 fake_creds
< /dev
/null
183 test_send_only_fakesmtp
'post: user not found in cred file: nobody@example.com
184 send: message not delivered to anyone'
187 start_test
'garbage creds file'
189 echo bork
| fake_creds
191 test_send_only_fakesmtp
'post: eof encountered in field "bork"
192 post: error loading cred file
193 send: message not delivered to anyone'
196 start_test
'unexpected field in creds file'
200 access-nobody@example.com: test-access
203 test_send_only_fakesmtp
'post: error loading cred file: unexpected field
204 send: message not delivered to anyone'
207 start_test
'garbage expiration time'
210 access-nobody@example.com: test-access
211 expire-nobody@example.com: 99999999999999999999999999999999
214 test_send_only_fakesmtp
'post: error loading cred file: invalid expiration time
215 send: message not delivered to anyone'
218 start_test
'refresh response has no access token'
221 refresh-nobody@example.com: test-refresh
224 expect_http_post_refresh
226 fake_json_response
<<EOF
228 "refresh_token": "refresh-token",
229 "token_type": "Bearer"
233 test_send
'post: error refreshing OAuth2 token
234 post: invalid response: no access token
235 send: message not delivered to anyone'
238 start_test
'expired access token, no refresh token -- tell user to mhlogin'
241 access-nobody@example.com: test-access
242 expire-nobody@example.com: 1414303986
245 test_send_only_fakesmtp
'post: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test
246 send: message not delivered to anyone'
249 start_test
'access token has no expiration, no refresh token -- tell user to mhlogin'
252 access-nobody@example.com: test-access
255 test_send_only_fakesmtp
'post: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test
256 send: message not delivered to anyone'
259 start_test
'refresh finds no http server'
262 access-nobody@example.com: test-access
263 refresh-nobody@example.com: test-refresh
266 cat > "${testname}.expected-send-output" <<EOF
267 post: error refreshing OAuth2 token
268 post: error making HTTP request to OAuth2 authorization endpoint: [details]
269 send: message not delivered to anyone
273 run_prog send
-draft -server 127.0.0.1 -port ${smtp_port} \
274 -sasl -saslmech xoauth2
-authservice test -user nobody@example.com
> "${testname}.send-output" 2>&1 || true
275 # Clear out an error message we get from libcurl on some systems (seen at least
276 # 3 different versions of this error message, on FreeBSD 10.1, Ubuntu 12.04, and
278 f
="${testname}.send-output"
279 sed 's/\(post: error making HTTP request to OAuth2 authorization endpoint:\).*/\1 [details]/' "$f" > "$f".clean
280 check
"$f".clean
"${testname}.expected-send-output"
284 start_test
'refresh gets bogus 200 response from http server'
286 expect_http_post_refresh
288 fake_http_response
'200 OK' <<EOF
289 Content-Type: text/html
294 test_send
'post: error refreshing OAuth2 token
295 post: invalid response
296 send: message not delivered to anyone'
299 start_test
'refresh gets 500 response from http server'
301 expect_http_post_refresh
303 fake_http_response
'500 Server Error' <<EOF
304 Content-Type: text/html
309 test_send
'post: error refreshing OAuth2 token
310 post: invalid response
311 send: message not delivered to anyone'
314 start_test
'refresh gets proper error from http'
316 expect_http_post_refresh
318 fake_http_response
'400 Bad Request' <<EOF
319 Content-Type: application/json
322 "error": "invalid_grant"
326 test_send
'post: credentials rejected -- run mhlogin -saslmech xoauth2 -authservice test
327 send: message not delivered to anyone'
330 start_test
'refresh gets response too big'
333 refresh-nobody@example.com: test-refresh
336 expect_http_post_refresh
338 fake_json_response
<<EOF
340 "access_token": "test-access",
341 "token_type": "Bearer",
346 awk 'BEGIN { for (i = 0; i < 8192; i++) { print "." } }' \
347 >> "${testname}.http-res"
349 test_send
'post: error refreshing OAuth2 token
350 post: refusing to process response body larger than 8192 bytes
351 send: message not delivered to anyone'
354 start_test
'smtp server rejects token'
356 XOAUTH
='not-that-one'
359 access-nobody@example.com: test-access
360 expire-nobody@example.com: 2000000000
363 test_send_only_fakesmtp
'post: problem initializing server; [BHST] Authentication failed: Not no way, not no how!
364 send: message not delivered to anyone'
367 start_test
'botched json response'
370 refresh-nobody@example.com: test-refresh
373 expect_http_post_refresh
375 fake_json_response
<<EOF
377 "refresh_token": "refresh-toke
381 test_send
'post: error refreshing OAuth2 token
382 post: invalid response
383 send: message not delivered to anyone'
386 start_test
"smtp server doesn't support oauth"
390 test_send_only_fakesmtp
'post: problem initializing server; [BHST] SMTP server does not support SASL
391 send: message not delivered to anyone'