]> diplodocus.org Git - nmh/blobdiff - test/oauth/test-send
spelling-fixes ( docs, man, readme )
[nmh] / test / oauth / test-send
index 363debc64e8f047eaa15ea9963ed005874830055..ad40dbdd3cbdc42f4638759cf7410946a73ec62f 100755 (executable)
@@ -24,28 +24,28 @@ export XOAUTH
 XOAUTH='dXNlcj1ub2JvZHlAZXhhbXBsZS5jb20BYXV0aD1CZWFyZXIgdGVzdC1hY2Nlc3MBAQ=='
 
 # TEST
 XOAUTH='dXNlcj1ub2JvZHlAZXhhbXBsZS5jb20BYXV0aD1CZWFyZXIgdGVzdC1hY2Nlc3MBAQ=='
 
 # TEST
-echo 'access token ready, smtp server accepts message'
+start_test 'access token ready, smtp server accepts message'
 
 setup_draft
 
 fake_creds <<EOF
 
 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
 run_test "send -draft -server 127.0.0.1 -port ${smtp_port} -saslmech xoauth2 -authservice test -user nobody@example.com"
 
 # TEST
 EOF
 
 start_fakesmtp
 run_test "send -draft -server 127.0.0.1 -port ${smtp_port} -saslmech xoauth2 -authservice test -user nobody@example.com"
 
 # TEST
-echo 'expired access token, refresh works, smtp server accepts message'
+start_test 'expired access token, refresh works, smtp server accepts message'
 
 setup_draft
 
 fake_creds <<EOF
 
 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_http_post_refresh
@@ -59,9 +59,9 @@ fake_json_response <<EOF
 EOF
 
 expect_creds <<EOF
 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
 EOF
 
 test_send
@@ -70,14 +70,14 @@ check_creds_private
 check_creds
 
 # TEST
 check_creds
 
 # TEST
-echo 'expired access token, refresh works and gets updated, smtp server accepts message'
+start_test 'expired access token, refresh works and gets updated, smtp server accepts message'
 
 setup_draft
 
 fake_creds <<EOF
 
 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_http_post_old_refresh
@@ -91,8 +91,8 @@ fake_json_response <<EOF
 EOF
 
 expect_creds <<EOF
 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
 EOF
 
 test_send
@@ -100,13 +100,13 @@ test_send
 check_creds
 
 # TEST
 check_creds
 
 # TEST
-echo 'access token has no expiration, refresh works, smtp server accepts message'
+start_test 'access token has no expiration, refresh works, smtp server accepts message'
 
 setup_draft
 
 fake_creds <<EOF
 
 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_http_post_refresh
@@ -119,8 +119,8 @@ fake_json_response <<EOF
 EOF
 
 expect_creds <<EOF
 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
 EOF
 
 test_send
@@ -128,12 +128,12 @@ test_send
 check_creds
 
 # TEST
 check_creds
 
 # TEST
-echo 'no access token, refresh works, smtp server accepts message'
+start_test 'no access token, refresh works, smtp server accepts message'
 
 setup_draft
 
 fake_creds <<EOF
 
 setup_draft
 
 fake_creds <<EOF
-refresh: test-refresh
+refresh-nobody@example.com: test-refresh
 EOF
 
 expect_http_post_refresh
 EOF
 
 expect_http_post_refresh
@@ -146,8 +146,8 @@ fake_json_response <<EOF
 EOF
 
 expect_creds <<EOF
 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
 EOF
 
 test_send
@@ -161,26 +161,26 @@ check_creds
 setup_draft
 
 # TEST
 setup_draft
 
 # TEST
-echo 'no service definition'
+start_test 'no service definition'
 
 run_test "send -draft -server 127.0.0.1 -port ${smtp_port} -saslmech xoauth2 -authservice bogus -user nobody@example.com" 'send: incomplete OAuth2 service definition: scope is missing'
 
 # TEST
 
 run_test "send -draft -server 127.0.0.1 -port ${smtp_port} -saslmech xoauth2 -authservice bogus -user nobody@example.com" 'send: incomplete OAuth2 service definition: scope is missing'
 
 # TEST
-echo 'no creds file -- should tell user to mhlogin'
+start_test 'no creds file -- should tell user to mhlogin'
 
 rm -f "${MHTMPDIR}/oauth-test"
 
 test_send_no_servers 'send: no credentials -- run mhlogin -saslmech xoauth2 -authservice test'
 
 # TEST
 
 rm -f "${MHTMPDIR}/oauth-test"
 
 test_send_no_servers 'send: no credentials -- run mhlogin -saslmech xoauth2 -authservice test'
 
 # TEST
-echo 'empty creds file -- should tell user to mhlogin'
+start_test 'empty creds file -- should tell user to mhlogin'
 
 fake_creds < /dev/null
 
 
 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
 
 # TEST
-echo 'garbage creds file'
+start_test 'garbage creds file'
 
 echo bork | fake_creds
 
 
 echo bork | fake_creds
 
@@ -188,30 +188,30 @@ test_send_no_servers 'send: eof encountered in field "bork"
 send: error loading cred file'
 
 # TEST
 send: error loading cred file'
 
 # TEST
-echo 'unexpected field in creds file'
+start_test 'unexpected field in creds file'
 
 fake_creds <<EOF
 bork: bork
 
 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'
 
 # TEST
 EOF
 
 test_send_no_servers 'send: error loading cred file: unexpected field'
 
 # TEST
-echo 'garbage expiration time'
+start_test 'garbage expiration time'
 
 fake_creds <<EOF
 
 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'
 
 # TEST
 EOF
 
 test_send_no_servers 'send: error loading cred file: invalid expiration time'
 
 # TEST
-echo 'refresh response has no access token'
+start_test 'refresh response has no access token'
 
 fake_creds <<EOF
 
 fake_creds <<EOF
-refresh: test-refresh
+refresh-nobody@example.com: test-refresh
 EOF
 
 expect_http_post_refresh
 EOF
 
 expect_http_post_refresh
@@ -227,30 +227,30 @@ test_send_only_fakehttp 'send: error refreshing OAuth2 token
 send: invalid response: no access token'
 
 # TEST
 send: invalid response: no access token'
 
 # TEST
-echo 'expired access token, no refresh token -- tell user to mhlogin'
+start_test 'expired access token, no refresh token -- tell user to mhlogin'
 
 fake_creds <<EOF
 
 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'
 
 # TEST
 EOF
 
 test_send_no_servers 'send: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test'
 
 # TEST
-echo 'access token has no expiration, no refresh token -- tell user to mhlogin'
+start_test 'access token has no expiration, no refresh token -- tell user to mhlogin'
 
 fake_creds <<EOF
 
 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'
 
 # TEST
 EOF
 
 test_send_no_servers 'send: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test'
 
 # TEST
-echo 'refresh finds no http server'
+start_test 'refresh finds no http server'
 
 fake_creds <<EOF
 
 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
 EOF
 
 cat > "${testname}.expected-send-output" <<EOF
@@ -269,7 +269,7 @@ check "$f".clean "${testname}.expected-send-output"
 rm "$f"
 
 # TEST
 rm "$f"
 
 # TEST
-echo 'refresh gets bogus 200 response from http server'
+start_test 'refresh gets bogus 200 response from http server'
 
 expect_http_post_refresh
 
 
 expect_http_post_refresh
 
@@ -283,7 +283,7 @@ test_send_only_fakehttp 'send: error refreshing OAuth2 token
 send: invalid response'
 
 # TEST
 send: invalid response'
 
 # TEST
-echo 'refresh gets 500 response from http server'
+start_test 'refresh gets 500 response from http server'
 
 expect_http_post_refresh
 
 
 expect_http_post_refresh
 
@@ -297,7 +297,7 @@ test_send_only_fakehttp 'send: error refreshing OAuth2 token
 send: invalid response'
 
 # TEST
 send: invalid response'
 
 # TEST
-echo 'refresh gets proper error from http'
+start_test 'refresh gets proper error from http'
 
 expect_http_post_refresh
 
 
 expect_http_post_refresh
 
@@ -312,10 +312,10 @@ EOF
 test_send_only_fakehttp 'send: credentials rejected -- run mhlogin -saslmech xoauth2 -authservice test'
 
 # TEST
 test_send_only_fakehttp 'send: credentials rejected -- run mhlogin -saslmech xoauth2 -authservice test'
 
 # TEST
-echo 'refresh gets response too big'
+start_test 'refresh gets response too big'
 
 fake_creds <<EOF
 
 fake_creds <<EOF
-refresh: test-refresh
+refresh-nobody@example.com: test-refresh
 EOF
 
 expect_http_post_refresh
 EOF
 
 expect_http_post_refresh
@@ -335,27 +335,46 @@ test_send_only_fakehttp 'send: error refreshing OAuth2 token
 send: refusing to process response body larger than 8192 bytes'
 
 # TEST
 send: refusing to process response body larger than 8192 bytes'
 
 # TEST
-echo 'smtp server rejects token'
+start_test 'smtp server rejects token'
 
 XOAUTH='not-that-one'
 
 fake_creds <<EOF
 
 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!
 send: message not delivered to anyone'
 
 # TEST
 EOF
 
 test_send_only_fakesmtp 'post: problem initializing server; [BHST] Not no way, not no how!
 send: message not delivered to anyone'
 
 # TEST
-echo "smtp server doesn't support oauth"
+start_test "smtp server doesn't support oauth"
 
 unset XOAUTH
 
 test_send_only_fakesmtp 'post: problem initializing server; [BHST] SMTP server does not support SASL XOAUTH2
 send: message not delivered to anyone'
 
 
 unset XOAUTH
 
 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
 clean_fakesmtp
 clean_fakehttp
+finish_test
 
 exit ${failed:-0}
 
 exit ${failed:-0}