]> diplodocus.org Git - nmh/blobdiff - test/oauth/common.sh
Reorder configure options to be before variables
[nmh] / test / oauth / common.sh
index 5deebfd567b0118a950c8ce41410d6749a7fb4e9..342e5786367e045e1e990d58ad6ccb54b2f6bfac 100644 (file)
@@ -10,13 +10,13 @@ fi
 
 testname="${MH_TEST_DIR}/$$"
 
 
 testname="${MH_TEST_DIR}/$$"
 
-arith_eval 64001 + `id -u` % 1000
+arith_eval 64001 + $$ % 1000
 http_port=${arith_val}
 
 http_port=${arith_val}
 
-arith_eval 64000 + `id -u` % 1000
+arith_eval ${http_port} + 1
 pop_port=${arith_val}
 
 pop_port=${arith_val}
 
-arith_eval 64002 + `id -u` % 1000
+arith_eval ${pop_port} + 1
 smtp_port=${arith_val}
 
 cat >> ${MH} <<EOF
 smtp_port=${arith_val}
 
 cat >> ${MH} <<EOF
@@ -29,7 +29,7 @@ oauth-test-redirect_uri: urn:ietf:wg:oauth:2.0:oob
 EOF
 
 setup_pop() {
 EOF
 
 setup_pop() {
-    pop_message=${MH_TEST_DIR}/testmessage
+    pop_message=${MHTMPDIR}/testmessage
     cat > "${pop_message}" <<EOM
 Received: From somewhere
 From: No Such User <nosuch@example.com>
     cat > "${pop_message}" <<EOM
 Received: From somewhere
 From: No Such User <nosuch@example.com>
@@ -73,6 +73,10 @@ start_fakesmtp() {
         > /dev/null
 }
 
         > /dev/null
 }
 
+clean_fakesmtp() {
+    rm "${testname}.smtp-req"
+}
+
 fake_creds() {
     cat > "${MHTMPDIR}/oauth-test"
 }
 fake_creds() {
     cat > "${MHTMPDIR}/oauth-test"
 }
@@ -82,6 +86,10 @@ fake_http_response() {
     cat >> "${testname}.http-res"
 }
 
     cat >> "${testname}.http-res"
 }
 
+clean_fakehttp() {
+    rm -f "${testname}.http-res"
+}
+
 fake_json_response() {
     (echo 'Content-Type: application/json';
      echo;
 fake_json_response() {
     (echo 'Content-Type: application/json';
      echo;
@@ -91,16 +99,17 @@ fake_json_response() {
 # The format of the POST request is mostly dependent on curl, and could possibly
 # change with newer or older curl versions, or by configuration.  curl 7.39.0
 # makes POST requests like this on FreeBSD 10 and Ubuntu 14.04.  If you find
 # The format of the POST request is mostly dependent on curl, and could possibly
 # change with newer or older curl versions, or by configuration.  curl 7.39.0
 # makes POST requests like this on FreeBSD 10 and Ubuntu 14.04.  If you find
-# this failing, you'll need to make this a smarter comparison.
+# this failing, you'll need to make this a smarter comparison.  Note that it is
+# sorted, so that it doesn't depend on the JSON being in a specific order.
 expect_http_post() {
 expect_http_post() {
-    cat > "${testname}.expected-http-req" <<EOF
-POST /oauth/token HTTP/1.1\r
-User-Agent: nmh/${MH_VERSION} ${CURL_USER_AGENT}\r
-Host: 127.0.0.1:${http_port}\r
-Accept: */*\r
-Content-Length: $1\r
-Content-Type: application/x-www-form-urlencoded\r
-\r
+    sort > "${testname}.expected-http-req" <<EOF
+POST /oauth/token HTTP/1.1
+User-Agent: nmh/${MH_VERSION} ${CURL_USER_AGENT}
+Host: 127.0.0.1:${http_port}
+Accept: */*
+Content-Length: $1
+Content-Type: application/x-www-form-urlencoded
+
 $2
 EOF
 }
 $2
 EOF
 }
@@ -118,11 +127,11 @@ expect_http_post_old_refresh() {
 }
 
 expect_creds() {
 }
 
 expect_creds() {
-    cat > "${testname}.expected-creds"
+    cat > "${MHTMPDIR}/$$.expected-creds"
 }
 
 test_inc() {
 }
 
 test_inc() {
-    run_test "inc -host 127.0.0.1 -port ${pop_port} -oauth test -user nobody@example.com -width 80" "$@"
+    run_test "inc -host 127.0.0.1 -port ${pop_port} -sasl -saslmech xoauth2 -authservice test -user nobody@example.com -width 80" "$@"
 }
 
 test_inc_success() {
 }
 
 test_inc_success() {
@@ -133,7 +142,7 @@ test_inc_success() {
 }
 
 test_send_no_servers() {
 }
 
 test_send_no_servers() {
-    run_test "send -draft -server 127.0.0.1 -port ${smtp_port} -oauth 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_send_only_fakesmtp() {
 }
 
 test_send_only_fakesmtp() {
@@ -144,11 +153,15 @@ test_send_only_fakesmtp() {
 test_send() {
     start_fakehttp
     test_send_only_fakesmtp "$@"
 test_send() {
     start_fakehttp
     test_send_only_fakesmtp "$@"
-    check "${testname}.http-req" "${testname}.expected-http-req"
+    sort -o "${testname}.http-req.sorted" "${testname}.http-req"
+    rm "${testname}.http-req"
+    check "${testname}.http-req.sorted" "${testname}.expected-http-req"
 }
 
 check_http_req() {
 }
 
 check_http_req() {
-    check "${testname}.http-req" "${testname}.expected-http-req"
+    sort -o "${testname}.http-req.sorted" "${testname}.http-req"
+    rm "${testname}.http-req"
+    check "${testname}.http-req.sorted" "${testname}.expected-http-req"
 }
 
 check_creds_private() {
 }
 
 check_creds_private() {
@@ -167,7 +180,7 @@ check_creds() {
     # it against our "correct" output.
     f="${MHTMPDIR}/oauth-test"
 
     # it against our "correct" output.
     f="${MHTMPDIR}/oauth-test"
 
-    sed 's/^expire:.*/expire:/' "$f" > "$f".notime
-    check "$f".notime "${testname}.expected-creds"
+    sed 's/^\(expire.*:\).*/\1/' "$f" > "$f".notime
+    check "$f".notime "${MHTMPDIR}/$$.expected-creds"
     rm "$f"
 }
     rm "$f"
 }