]> diplodocus.org Git - nmh/blobdiff - test/oauth/test-send
Escape literal leading full stop in man/new.man.
[nmh] / test / oauth / test-send
index 363debc64e8f047eaa15ea9963ed005874830055..4d5a850aac3f39534a6629918a9e317bc4e70d8e 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Test the XOAUTH2 support in sen
+# Test the XOAUTH2 support in send
 #
 
 if test -z "${MH_OBJ_DIR}"; then
@@ -10,6 +10,8 @@ fi
 
 . "${srcdir}/test/oauth/common.sh"
 
+check_exit '-eq 1' send -
+
 test_send_only_fakehttp() {
     start_fakehttp
     test_send_no_servers "$@"
@@ -24,28 +26,28 @@ export XOAUTH
 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
-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"
+run_test "send -draft -server 127.0.0.1 -port ${smtp_port} -sasl -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
-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
@@ -59,9 +61,9 @@ fake_json_response <<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
@@ -70,14 +72,14 @@ check_creds_private
 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
-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
@@ -91,8 +93,8 @@ fake_json_response <<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
@@ -100,13 +102,13 @@ test_send
 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
-access: old-access
-refresh: test-refresh
+access-nobody@example.com: old-access
+refresh-nobody@example.com: test-refresh
 EOF
 
 expect_http_post_refresh
@@ -119,8 +121,8 @@ fake_json_response <<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
@@ -128,12 +130,12 @@ test_send
 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
-refresh: test-refresh
+refresh-nobody@example.com: test-refresh
 EOF
 
 expect_http_post_refresh
@@ -146,8 +148,8 @@ fake_json_response <<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
@@ -161,57 +163,62 @@ check_creds
 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'
+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'
 
 # 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_send_only_fakesmtp 'post: no credentials -- run mhlogin -saslmech xoauth2 -authservice test
+send: message not delivered to anyone'
 
 # TEST
-echo 'empty creds file -- should tell user to mhlogin'
+start_test 'empty creds file -- should tell user to mhlogin'
 
 fake_creds < /dev/null
 
-test_send_no_servers 'send: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test'
+test_send_only_fakesmtp 'post: user not found in cred file: nobody@example.com
+send: message not delivered to anyone'
 
 # TEST
-echo 'garbage creds file'
+start_test 'garbage creds file'
 
 echo bork | fake_creds
 
-test_send_no_servers 'send: eof encountered in field "bork"
-send: error loading cred file'
+test_send_only_fakesmtp 'post: eof encountered in field "bork"
+post: error loading cred file
+send: message not delivered to anyone'
 
 # TEST
-echo 'unexpected field in creds file'
+start_test 'unexpected field in 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'
+test_send_only_fakesmtp 'post: error loading cred file: unexpected field
+send: message not delivered to anyone'
 
 # TEST
-echo 'garbage expiration time'
+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'
+test_send_only_fakesmtp 'post: error loading cred file: invalid expiration time
+send: message not delivered to anyone'
 
 # TEST
-echo 'refresh response has no access token'
+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
@@ -223,53 +230,58 @@ fake_json_response <<EOF
 }
 EOF
 
-test_send_only_fakehttp 'send: error refreshing OAuth2 token
-send: invalid response: no access token'
+test_send 'post: error refreshing OAuth2 token
+post: invalid response: no access token
+send: message not delivered to anyone'
 
 # 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
-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_send_only_fakesmtp 'post: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test
+send: message not delivered to anyone'
 
 # 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
-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_send_only_fakesmtp 'post: no valid credentials -- run mhlogin -saslmech xoauth2 -authservice test
+send: message not delivered to anyone'
 
 # TEST
-echo 'refresh finds no http server'
+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
-send: error refreshing OAuth2 token
-send: error making HTTP request to OAuth2 authorization endpoint: [details]
+post: error refreshing OAuth2 token
+post: error making HTTP request to OAuth2 authorization endpoint: [details]
+send: message not delivered to anyone
 EOF
 
+start_fakesmtp
 run_prog send -draft -server 127.0.0.1 -port ${smtp_port} \
-  -saslmech xoauth2 -authservice test -user nobody@example.com > "${testname}.send-output" 2>&1 || true
+  -sasl -saslmech xoauth2 -authservice test -user nobody@example.com > "${testname}.send-output" 2>&1 || true
 # Clear out an error message we get from libcurl on some systems (seen at least
 # 3 different versions of this error message, on FreeBSD 10.1, Ubuntu 12.04, and
 # Ubuntu 14.04).
 f="${testname}.send-output"
-sed 's/\(send: error making HTTP request to OAuth2 authorization endpoint:\).*/\1 [details]/' "$f" > "$f".clean
+sed 's/\(post: error making HTTP request to OAuth2 authorization endpoint:\).*/\1 [details]/' "$f" > "$f".clean
 check "$f".clean "${testname}.expected-send-output"
 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
 
@@ -279,11 +291,12 @@ Content-Type: text/html
 <html>doh!</htmxl>
 EOF
 
-test_send_only_fakehttp 'send: error refreshing OAuth2 token
-send: invalid response'
+test_send 'post: error refreshing OAuth2 token
+post: invalid response
+send: message not delivered to anyone'
 
 # TEST
-echo 'refresh gets 500 response from http server'
+start_test 'refresh gets 500 response from http server'
 
 expect_http_post_refresh
 
@@ -293,11 +306,12 @@ Content-Type: text/html
 <html>doh!</html>
 EOF
 
-test_send_only_fakehttp 'send: error refreshing OAuth2 token
-send: invalid response'
+test_send 'post: error refreshing OAuth2 token
+post: invalid response
+send: message not delivered to anyone'
 
 # TEST
-echo 'refresh gets proper error from http'
+start_test 'refresh gets proper error from http'
 
 expect_http_post_refresh
 
@@ -309,13 +323,14 @@ Content-Type: application/json
 }
 EOF
 
-test_send_only_fakehttp 'send: credentials rejected -- run mhlogin -saslmech xoauth2 -authservice test'
+test_send 'post: credentials rejected -- run mhlogin -saslmech xoauth2 -authservice test
+send: message not delivered to anyone'
 
 # TEST
-echo 'refresh gets response too big'
+start_test 'refresh gets response too big'
 
 fake_creds <<EOF
-refresh: test-refresh
+refresh-nobody@example.com: test-refresh
 EOF
 
 expect_http_post_refresh
@@ -331,31 +346,52 @@ EOF
 awk 'BEGIN { for (i = 0; i < 8192; i++) { print "." } }' \
     >> "${testname}.http-res"
 
-test_send_only_fakehttp 'send: error refreshing OAuth2 token
-send: refusing to process response body larger than 8192 bytes'
+test_send 'post: error refreshing OAuth2 token
+post: refusing to process response body larger than 8192 bytes
+send: message not delivered to anyone'
 
 # TEST
-echo 'smtp server rejects token'
+start_test 'smtp server rejects token'
 
 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] Authentication failed: Not no way, not no how!
+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_fakesmtp 'post: problem initializing server; [BHST] Not no way, not no how!
+test_send 'post: error refreshing OAuth2 token
+post: invalid response
 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
+test_send_only_fakesmtp 'post: problem initializing server; [BHST] SMTP server does not support SASL
 send: message not delivered to anyone'
 
 clean_fakesmtp
 clean_fakehttp
+finish_test
 
 exit ${failed:-0}