From: David Levine Date: Sun, 13 Mar 2016 16:58:25 +0000 (-0400) Subject: Sort JSON output from oauth tests so that comparisons don't X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/f0beecb5ab89a3e2e2913919f304b1dcdee53a66?ds=inline;hp=-c Sort JSON output from oauth tests so that comparisons don't depend on it being in a specific order. Also, clean up test tmp files. --- f0beecb5ab89a3e2e2913919f304b1dcdee53a66 diff --git a/test/oauth/common.sh b/test/oauth/common.sh index 8b21fd12..e0fdb2a8 100644 --- a/test/oauth/common.sh +++ b/test/oauth/common.sh @@ -29,7 +29,7 @@ oauth-test-redirect_uri: urn:ietf:wg:oauth:2.0:oob EOF setup_pop() { - pop_message=${MH_TEST_DIR}/testmessage + pop_message=${MHTMPDIR}/testmessage cat > "${pop_message}" < @@ -73,6 +73,10 @@ start_fakesmtp() { > /dev/null } +clean_fakesmtp() { + rm "${testname}.smtp-req" +} + fake_creds() { cat > "${MHTMPDIR}/oauth-test" } @@ -82,6 +86,10 @@ fake_http_response() { cat >> "${testname}.http-res" } +clean_fakehttp() { + rm -f "${testname}.http-res" +} + 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 -# 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() { - cat > "${testname}.expected-http-req" < "${testname}.expected-http-req" < "${testname}.expected-creds" + cat > "${MHTMPDIR}/$$.expected-creds" } test_inc() { @@ -144,11 +153,15 @@ 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 "${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() { @@ -168,6 +181,6 @@ check_creds() { 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" } diff --git a/test/oauth/test-inc b/test/oauth/test-inc index 8c71e624..16b55b58 100755 --- a/test/oauth/test-inc +++ b/test/oauth/test-inc @@ -47,12 +47,6 @@ fake_json_response < "${testname}.expected-creds" + cat /dev/null > "${MHTMPDIR}/$$.expected-creds" 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' +clean_fakehttp + exit ${failed:-0} diff --git a/test/oauth/test-send b/test/oauth/test-send index 513c8989..1c5ae4bf 100755 --- a/test/oauth/test-send +++ b/test/oauth/test-send @@ -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' +clean_fakesmtp +clean_fakehttp + exit ${failed:-0} diff --git a/test/oauth/test-share b/test/oauth/test-share index af887566..6353ec56 100755 --- a/test/oauth/test-share +++ b/test/oauth/test-share @@ -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 +clean_fakesmtp +clean_fakehttp + exit ${failed:-0}