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"
14 cat /dev
/null
> "${MHTMPDIR}/$$.expected-creds"
15 cat /dev
/null
> "${MHTMPDIR}/oauth-test"
16 chmod 600 "${MHTMPDIR}/oauth-test"
21 run_test
'eval echo code | mhlogin -saslmech xoauth2 -authservice test' \
22 "Load the following URL in your browser and authorize nmh to access test:
24 http://127.0.0.1:${http_port}/oauth/auth?response_type=code&client_id=test-id&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=test-scope
26 Enter the authorization code: $1"
32 test_mhlogin_invalid_response
() {
33 test_mhlogin
'mhlogin: error exchanging code for OAuth2 token
34 mhlogin: invalid response'
42 echo 'mhlogin receives access and expiration'
46 fake_json_response
<<EOF
48 "access_token": "test-access",
49 "token_type": "Bearer",
62 echo 'mhlogin receives access and refresh'
66 fake_json_response
<<EOF
68 "access_token": "test-access",
69 "token_type": "Bearer"
80 echo 'mhlogin receives access, expiration, and refresh'
84 fake_json_response
<<EOF
86 "access_token": "test-access",
87 "refresh_token": "refresh-token",
89 "token_type": "Bearer"
95 refresh: refresh-token
102 echo 'mhlogin receives refresh only'
104 expect_http_post_code
106 fake_json_response
<<EOF
108 "refresh_token": "refresh-token",
109 "token_type": "Bearer"
114 refresh: refresh-token
120 echo 'mhlogin receives token_type only'
122 expect_http_post_code
124 fake_json_response
<<EOF
126 "token_type": "Bearer"
132 test_mhlogin_invalid_response
135 echo 'mhlogin ignores extra bits in successful response JSON'
137 expect_http_post_code
139 fake_json_response
<<EOF
141 "access_token": "test-access",
142 "refresh_token": "refresh-token",
146 "c": [{}, {"foo": "bar"}]
150 "token_type": "Bearer"
156 refresh: refresh-token
163 echo 'mhlogin user enters bad code'
165 expect_http_post_code
167 fake_http_response
'400 Bad Request' <<EOF
168 Content-Type: application/json
171 "error": "invalid_grant"
177 test_mhlogin
'Code rejected; try again? '
184 echo 'mhlogin response has no content-type'
186 expect_http_post_code
188 fake_http_response
'200 OK' <<EOF
191 "access_token": "test-access",
192 "token_type": "Bearer",
199 test_mhlogin_invalid_response
202 echo 'mhlogin JSON array'
204 expect_http_post_code
206 fake_json_response
<<EOF
212 test_mhlogin_invalid_response
215 echo 'mhlogin JSON empty object'
217 expect_http_post_code
219 fake_json_response
<<EOF
225 test_mhlogin_invalid_response
228 echo 'mhlogin empty response body'
230 expect_http_post_code
232 fake_json_response
<<EOF
237 test_mhlogin_invalid_response
240 echo 'mhlogin gets proper error from http'
242 expect_http_post_code
244 fake_http_response
'400 Bad Request' <<EOF
245 Content-Type: application/json
248 "error": "invalid_request"
254 test_mhlogin
'mhlogin: error exchanging code for OAuth2 token
255 mhlogin: bad OAuth request; re-run with -snoop and send REDACTED output to nmh-workers'