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
160 start_test
'fill all slots in creds table'
165 access-nobody@example.com: test-access
166 refresh-nobody@example.com: test-refresh
167 expire-nobody@example.com: 2000000000
168 access-nobody2@example.com: test-access
169 refresh-nobody2@example.com: test-refresh
170 expire-nobody2@example.com: 2000000000
171 access-nobody3@example.com: test-access
172 refresh-nobod3y@example.com: test-refresh
173 expire-nobody3@example.com: 2000000000
174 access-nobody4@example.com: test-access
175 refresh-nobody4@example.com: test-refresh
176 expire-nobody4@example.com: 2000000000
177 access-nobody5@example.com: test-access
178 refresh-nobody5@example.com: test-refresh
179 expire-nobody5@example.com: 2000000000
180 access-nobody6@example.com: test-access
181 refresh-nobody6@example.com: test-refresh
182 expire-nobody6@example.com: 2000000000
183 access-nobody7@example.com: test-access
184 refresh-nobody7@example.com: test-refresh
185 expire-nobody7@example.com: 2000000000
186 access-nobody8@example.com: test-access
187 refresh-nobody8@example.com: test-refresh
188 expire-nobody8@example.com: 2000000000
189 access-nobody9@example.com: test-access
190 refresh-nobody9@example.com: test-refresh
191 expire-nobody9@example.com: 2000000000
192 access-nobody10@example.com: test-access
193 refresh-nobody10@example.com: test-refresh
194 expire-nobody10@example.com: 2000000000
195 access-nobody11@example.com: test-access
196 refresh-nobody11@example.com: test-refresh
197 expire-nobody11@example.com: 2000000000
198 access-nobody12@example.com: test-access
199 refresh-nobody12@example.com: test-refresh
200 expire-nobody12@example.com: 2000000000
201 access-nobody13@example.com: test-access
202 refresh-nobody13@example.com: test-refresh
203 expire-nobody13@example.com: 2000000000
204 access-nobody14@example.com: test-access
205 refresh-nobody14@example.com: test-refresh
206 expire-nobody14@example.com: 2000000000
207 access-nobody15@example.com: test-access
208 refresh-nobody15@example.com: test-refresh
209 expire-nobody15@example.com: 2000000000
210 access-nobody16@example.com: test-access
211 refresh-nobody16@example.com: test-refresh
212 expire-nobody16@example.com: 2000000000
216 run_test
"send -draft -server 127.0.0.1 -port ${smtp_port} -sasl -saslmech xoauth2 -authservice test -user nobody@example.com"
225 start_test
'no service definition'
227 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'
230 start_test
'no creds file -- should tell user to mhlogin'
232 rm -f "${MHTMPDIR}/oauth-test"
234 test_send_only_fakesmtp
'post: no credentials -- run mhlogin -saslmech xoauth2 -authservice test
235 send: message not delivered to anyone'
238 start_test
'empty creds file -- should tell user to mhlogin'
240 fake_creds
< /dev
/null
242 test_send_only_fakesmtp
'post: user not found in cred file: nobody@example.com
243 send: message not delivered to anyone'
246 start_test
'garbage creds file'
248 echo bork
| fake_creds
250 test_send_only_fakesmtp
'post: eof encountered in field "bork"
251 post: error loading cred file
252 send: message not delivered to anyone'
255 start_test
'unexpected field in creds file'
259 access-nobody@example.com: test-access
262 test_send_only_fakesmtp
'post: error loading cred file: unexpected field
263 send: message not delivered to anyone'
266 start_test
'garbage expiration time'
269 access-nobody@example.com: test-access
270 expire-nobody@example.com: 99999999999999999999999999999999
273 test_send_only_fakesmtp
'post: error loading cred file: invalid expiration time
274 send: message not delivered to anyone'
277 start_test
'refresh response has no access token'
280 refresh-nobody@example.com: test-refresh
283 expect_http_post_refresh
285 fake_json_response
<<EOF
287 "refresh_token": "refresh-token",
288 "token_type": "Bearer"
292 test_send
'post: error refreshing OAuth2 token
293 post: invalid response: no access token
294 send: message not delivered to anyone'
297 start_test
'expired access token, no refresh token -- tell user to mhlogin'
300 access-nobody@example.com: test-access
301 expire-nobody@example.com: 1414303986
304 test_send_only_fakesmtp
'post: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test
305 send: message not delivered to anyone'
308 start_test
'access token has no expiration, no refresh token -- tell user to mhlogin'
311 access-nobody@example.com: test-access
314 test_send_only_fakesmtp
'post: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test
315 send: message not delivered to anyone'
318 start_test
'refresh finds no http server'
321 access-nobody@example.com: test-access
322 refresh-nobody@example.com: test-refresh
325 cat > "${testname}.expected-send-output" <<EOF
326 post: error refreshing OAuth2 token
327 post: error making HTTP request to OAuth2 authorization endpoint: [details]
328 send: message not delivered to anyone
332 run_prog send
-draft -server 127.0.0.1 -port ${smtp_port} \
333 -sasl -saslmech xoauth2
-authservice test -user nobody@example.com
> "${testname}.send-output" 2>&1 || true
334 # Clear out an error message we get from libcurl on some systems (seen at least
335 # 3 different versions of this error message, on FreeBSD 10.1, Ubuntu 12.04, and
337 f
="${testname}.send-output"
338 sed 's/\(post: error making HTTP request to OAuth2 authorization endpoint:\).*/\1 [details]/' "$f" > "$f".clean
339 check
"$f".clean
"${testname}.expected-send-output"
343 start_test
'refresh gets bogus 200 response from http server'
345 expect_http_post_refresh
347 fake_http_response
'200 OK' <<EOF
348 Content-Type: text/html
353 test_send
'post: error refreshing OAuth2 token
354 post: invalid response
355 send: message not delivered to anyone'
358 start_test
'refresh gets 500 response from http server'
360 expect_http_post_refresh
362 fake_http_response
'500 Server Error' <<EOF
363 Content-Type: text/html
368 test_send
'post: error refreshing OAuth2 token
369 post: invalid response
370 send: message not delivered to anyone'
373 start_test
'refresh gets proper error from http'
375 expect_http_post_refresh
377 fake_http_response
'400 Bad Request' <<EOF
378 Content-Type: application/json
381 "error": "invalid_grant"
385 test_send
'post: credentials rejected -- run mhlogin -saslmech xoauth2 -authservice test
386 send: message not delivered to anyone'
389 start_test
'refresh gets response too big'
392 refresh-nobody@example.com: test-refresh
395 expect_http_post_refresh
397 fake_json_response
<<EOF
399 "access_token": "test-access",
400 "token_type": "Bearer",
405 awk 'BEGIN { for (i = 0; i < 8192; i++) { print "." } }' \
406 >> "${testname}.http-res"
408 test_send
'post: error refreshing OAuth2 token
409 post: refusing to process response body larger than 8192 bytes
410 send: message not delivered to anyone'
413 start_test
'smtp server rejects token'
415 XOAUTH
='not-that-one'
418 access-nobody@example.com: test-access
419 expire-nobody@example.com: 2000000000
422 test_send_only_fakesmtp
'post: problem initializing server; [BHST] Authentication failed: Not no way, not no how!
423 send: message not delivered to anyone'
426 start_test
'botched json response'
429 refresh-nobody@example.com: test-refresh
432 expect_http_post_refresh
434 fake_json_response
<<EOF
436 "refresh_token": "refresh-toke
440 test_send
'post: error refreshing OAuth2 token
441 post: invalid response
442 send: message not delivered to anyone'
445 start_test
"smtp server doesn't support oauth"
449 test_send_only_fakesmtp
'post: problem initializing server; [BHST] SMTP server does not support SASL
450 send: message not delivered to anyone'