setup_draft
fake_creds <<EOF
-access: test-access
-refresh: test-refresh
-expire: 2000000000
+access-nobody@example.com: test-access
+refresh-nobody@example.com: test-refresh
+expire-nobody@example.com: 2000000000
EOF
start_fakesmtp
setup_draft
fake_creds <<EOF
-access: old-access
-refresh: test-refresh
-expire: 1414303986
+access-nobody@example.com: old-access
+refresh-nobody@example.com: test-refresh
+expire-nobody@example.com: 1414303986
EOF
expect_http_post_refresh
EOF
expect_creds <<EOF
-access: test-access
-refresh: test-refresh
-expire:
+access-nobody@example.com: test-access
+refresh-nobody@example.com: test-refresh
+expire-nobody@example.com:
EOF
test_send
setup_draft
fake_creds <<EOF
-access: old-access
-refresh: old-refresh
-expire: 1414303986
+access-nobody@example.com: old-access
+refresh-nobody@example.com: old-refresh
+expire-nobody@example.com: 1414303986
EOF
expect_http_post_old_refresh
EOF
expect_creds <<EOF
-access: test-access
-refresh: test-refresh
+access-nobody@example.com: test-access
+refresh-nobody@example.com: test-refresh
EOF
test_send
setup_draft
fake_creds <<EOF
-access: old-access
-refresh: test-refresh
+access-nobody@example.com: old-access
+refresh-nobody@example.com: test-refresh
EOF
expect_http_post_refresh
EOF
expect_creds <<EOF
-access: test-access
-refresh: test-refresh
+access-nobody@example.com: test-access
+refresh-nobody@example.com: test-refresh
EOF
test_send
setup_draft
fake_creds <<EOF
-refresh: test-refresh
+refresh-nobody@example.com: test-refresh
EOF
expect_http_post_refresh
EOF
expect_creds <<EOF
-access: test-access
-refresh: test-refresh
+access-nobody@example.com: test-access
+refresh-nobody@example.com: test-refresh
EOF
test_send
fake_creds < /dev/null
-test_send_no_servers 'send: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test'
+test_send_no_servers 'send: user not found in cred file: nobody@example.com'
# TEST
start_test 'garbage creds file'
fake_creds <<EOF
bork: bork
-access: test-access
+access-nobody@example.com: test-access
EOF
test_send_no_servers 'send: error loading cred file: unexpected field'
start_test 'garbage expiration time'
fake_creds <<EOF
-access: test-access
-expire: 99999999999999999999999999999999
+access-nobody@example.com: test-access
+expire-nobody@example.com: 99999999999999999999999999999999
EOF
test_send_no_servers 'send: error loading cred file: invalid expiration time'
start_test 'refresh response has no access token'
fake_creds <<EOF
-refresh: test-refresh
+refresh-nobody@example.com: test-refresh
EOF
expect_http_post_refresh
start_test 'expired access token, no refresh token -- tell user to mhlogin'
fake_creds <<EOF
-access: test-access
-expire: 1414303986
+access-nobody@example.com: test-access
+expire-nobody@example.com: 1414303986
EOF
test_send_no_servers 'send: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test'
start_test 'access token has no expiration, no refresh token -- tell user to mhlogin'
fake_creds <<EOF
-access: test-access
+access-nobody@example.com: test-access
EOF
test_send_no_servers 'send: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test'
start_test 'refresh finds no http server'
fake_creds <<EOF
-access: test-access
-refresh: test-refresh
+access-nobody@example.com: test-access
+refresh-nobody@example.com: test-refresh
EOF
cat > "${testname}.expected-send-output" <<EOF
start_test 'refresh gets response too big'
fake_creds <<EOF
-refresh: test-refresh
+refresh-nobody@example.com: test-refresh
EOF
expect_http_post_refresh
XOAUTH='not-that-one'
fake_creds <<EOF
-access: test-access
-expire: 2000000000
+access-nobody@example.com: test-access
+expire-nobody@example.com: 2000000000
EOF
test_send_only_fakesmtp 'post: problem initializing server; [BHST] Not no way, not no how!
test_send_only_fakesmtp 'post: problem initializing server; [BHST] SMTP server does not support SASL XOAUTH2
send: message not delivered to anyone'
+# TEST
+start_test 'botched json response'
+
+fake_creds <<EOF
+refresh-nobody@example.com: test-refresh
+EOF
+
+expect_http_post_refresh
+
+fake_json_response <<EOF
+{
+ "refresh_token": "refresh-toke
+}
+EOF
+
+test_send_only_fakehttp 'send: error refreshing OAuth2 token
+send: invalid response'
+
clean_fakesmtp
clean_fakehttp
finish_test