]> diplodocus.org Git - nmh/blobdiff - test/oauth/test-mhlogin
Reorder configure options to be before variables
[nmh] / test / oauth / test-mhlogin
index ed23e05cc60e17b8425bd1477b8682bd2b60f3d0..c4a7bf2d812f65824441db3753ac6e18bfa8cd11 100755 (executable)
@@ -10,6 +10,8 @@ fi
 
 . "${srcdir}/test/oauth/common.sh"
 
 
 . "${srcdir}/test/oauth/common.sh"
 
+check_exit '-eq 1' mhlogin -
+
 expect_no_creds() {
     cat /dev/null > "${MHTMPDIR}/$$.expected-creds"
     cat /dev/null > "${MHTMPDIR}/oauth-test"
 expect_no_creds() {
     cat /dev/null > "${MHTMPDIR}/$$.expected-creds"
     cat /dev/null > "${MHTMPDIR}/oauth-test"
@@ -303,17 +305,33 @@ mhlogin: bad OAuth request; re-run with -snoop and send REDACTED output to nmh-w
 # TEST
 start_test 'mhlogin -browser'
 
 # TEST
 start_test 'mhlogin -browser'
 
-run_test "eval echo code | mhlogin -saslmech xoauth2 -authservice test\
- -user nobody@example.com -browser 'echo \$@ > ${MHTMPDIR}/$$.browser'" \
-"Follow the prompts in your browser to authorize nmh to access test.
-Enter the authorization code: mhlogin: error exchanging code for OAuth2 token
-mhlogin: error making HTTP request to OAuth2 authorization endpoint: Failed to connect to 127.0.0.1 port ${http_port}: Connection refused"
+#### Strip off the error string because it can vary, e.g.,
+####   "Failed to connect to 127.0.0.1 port 64546: Connection refused", or
+####   "Connection timed out after 1004 milliseconds"
+echo code | mhlogin -saslmech xoauth2 -authservice test -user nobody@example.com \
+                    -browser "echo \$@ > ${MHTMPDIR}/$$.browser" 2>&1 1>/dev/null | \
+    sed 's/\( endpoint:\) .*/\1/' > "${MHTMPDIR}/$$.mhlogin.err"
+cat > "${MHTMPDIR}/$$.mhlogin.err.expected" <<EOF
+mhlogin: error exchanging code for OAuth2 token
+mhlogin: error making HTTP request to OAuth2 authorization endpoint:
+EOF
+check "${MHTMPDIR}/$$.mhlogin.err" "${MHTMPDIR}/$$.mhlogin.err.expected"
 
 cat > "${MHTMPDIR}/$$.browser.expected" <<EOF
 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
 EOF
 check "${MHTMPDIR}/$$.browser" "${MHTMPDIR}/$$.browser.expected"
 
 
 cat > "${MHTMPDIR}/$$.browser.expected" <<EOF
 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
 EOF
 check "${MHTMPDIR}/$$.browser" "${MHTMPDIR}/$$.browser.expected"
 
+# TEST
+start_test 'empty authorization code'
+run_test 'eval echo '' | mhlogin -saslmech xoauth2 -authservice test -user nobody@example.com' \
+         "Load the following URL in your browser and authorize nmh to access test:
+
+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
+
+Enter the authorization code: Empty code; try again? "
+
+
 clean_fakehttp
 finish_test
 
 clean_fakehttp
 finish_test