]> diplodocus.org Git - nmh/commitdiff
Sort JSON output from oauth tests so that comparisons don't
authorDavid Levine <david.levine@gonift.com>
Sun, 13 Mar 2016 16:58:25 +0000 (12:58 -0400)
committerDavid Levine <david.levine@gonift.com>
Sun, 13 Mar 2016 16:58:25 +0000 (12:58 -0400)
depend on it being in a specific order.  Also, clean up test
tmp files.

test/oauth/common.sh
test/oauth/test-inc
test/oauth/test-mhlogin
test/oauth/test-send
test/oauth/test-share

index 8b21fd12f51cd51f5093ffd74c5c4e8b3ff91dee..e0fdb2a801c9920cfdda56b8f23ef3444b14d9ea 100644 (file)
@@ -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,9 +99,10 @@ 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
+    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}
 POST /oauth/token HTTP/1.1
 User-Agent: nmh/${MH_VERSION} ${CURL_USER_AGENT}
 Host: 127.0.0.1:${http_port}
@@ -118,7 +127,7 @@ expect_http_post_old_refresh() {
 }
 
 expect_creds() {
 }
 
 expect_creds() {
-    cat > "${testname}.expected-creds"
+    cat > "${MHTMPDIR}/$$.expected-creds"
 }
 
 test_inc() {
 }
 
 test_inc() {
@@ -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() {
@@ -168,6 +181,6 @@ check_creds() {
     f="${MHTMPDIR}/oauth-test"
 
     sed 's/^expire:.*/expire:/' "$f" > "$f".notime
     f="${MHTMPDIR}/oauth-test"
 
     sed 's/^expire:.*/expire:/' "$f" > "$f".notime
-    check "$f".notime "${testname}.expected-creds"
+    check "$f".notime "${MHTMPDIR}/$$.expected-creds"
     rm "$f"
 }
     rm "$f"
 }
index 8c71e62427b53e946817102186316916823d698e..16b55b5865845f4ecd735d317165bc32817697e7 100755 (executable)
@@ -47,12 +47,6 @@ fake_json_response <<EOF
 }
 EOF
 
 }
 EOF
 
-expect_creds <<EOF
-access: test-access
-refresh: test-refresh
-expire:
-EOF
-
 start_fakehttp
 start_pop_xoauth
 
 start_fakehttp
 start_pop_xoauth
 
@@ -113,4 +107,6 @@ start_pop testuser testpass
 
 test_inc 'inc: POP server does not support SASL'
 
 
 test_inc 'inc: POP server does not support SASL'
 
+clean_fakehttp
+
 exit ${failed:-0}
 exit ${failed:-0}
index 6103f70681ea013f4680191397ce6afd0a69a06e..b7287a4117e901b99772ae52375dc11a77185681 100755 (executable)
@@ -11,7 +11,7 @@ fi
 . "${srcdir}/test/oauth/common.sh"
 
 expect_no_creds() {
 . "${srcdir}/test/oauth/common.sh"
 
 expect_no_creds() {
-    cat /dev/null > "${testname}.expected-creds"
+    cat /dev/null > "${MHTMPDIR}/$$.expected-creds"
     cat /dev/null > "${MHTMPDIR}/oauth-test"
     chmod 600 "${MHTMPDIR}/oauth-test"
 }
     cat /dev/null > "${MHTMPDIR}/oauth-test"
     chmod 600 "${MHTMPDIR}/oauth-test"
 }
@@ -254,4 +254,6 @@ expect_no_creds
 test_mhlogin 'mhlogin: error exchanging code for OAuth2 token
 mhlogin: bad OAuth request; re-run with -snoop and send REDACTED output to nmh-workers'
 
 test_mhlogin 'mhlogin: error exchanging code for OAuth2 token
 mhlogin: bad OAuth request; re-run with -snoop and send REDACTED output to nmh-workers'
 
+clean_fakehttp
+
 exit ${failed:-0}
 exit ${failed:-0}
index 513c8989e925281b845efa8876bdb69f721457ec..1c5ae4bfc4f8c2da649d350b07cbf29b59ab762c 100755 (executable)
@@ -355,4 +355,7 @@ 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_send_only_fakesmtp 'post: problem initializing server; [BHST] SMTP server does not support SASL XOAUTH2
 send: message not delivered to anyone'
 
+clean_fakesmtp
+clean_fakehttp
+
 exit ${failed:-0}
 exit ${failed:-0}
index af88756639b491ab57bce94f061d9afbb3a96409..6353ec56ac821bba9890c9c79bfedb029087b6c1 100755 (executable)
@@ -136,4 +136,7 @@ run_test "msgchk -host 127.0.0.1 -port ${pop_port} -oauth test -user nobody@exam
 start_pop_xoauth
 test_inc_success
 
 start_pop_xoauth
 test_inc_success
 
+clean_fakesmtp
+clean_fakehttp
+
 exit ${failed:-0}
 exit ${failed:-0}