# Common routines for OAuth tests . "${MH_OBJ_DIR}/test/common.sh" setup_test if [ "${OAUTH_SUPPORT}" -eq 0 ]; then test_skip 'no oauth support' fi testname="${MH_TEST_DIR}/$$" arith_eval 64001 + `id -u` % 1000 http_port=${arith_val} arith_eval 64000 + `id -u` % 1000 pop_port=${arith_val} arith_eval 64002 + `id -u` % 1000 smtp_port=${arith_val} cat >> ${MH} < "${pop_message}" < To: Some Other User Subject: Hello Date: Sun, 17 Dec 2006 12:13:14 -0500 Hey man EOM } setup_draft() { cat > "${MH_TEST_DIR}/Mail/draft" < To: Somebody Else Subject: Test MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" This is a test EOF } start_fakehttp() { "${MH_OBJ_DIR}/test/fakehttp" "${testname}.http-req" ${http_port} \ "${testname}.http-res" > /dev/null } start_pop() { "${MH_OBJ_DIR}/test/fakepop" "${pop_port}" "$1" "$2" "${pop_message}" \ > /dev/null } start_pop_xoauth() { start_pop XOAUTH \ 'dXNlcj1ub2JvZHlAZXhhbXBsZS5jb20BYXV0aD1CZWFyZXIgdGVzdC1hY2Nlc3MBAQ==' } start_fakesmtp() { "${MH_OBJ_DIR}/test/fakesmtp" "${testname}.smtp-req" ${smtp_port} \ > /dev/null } clean_fakesmtp() { rm "${testname}.smtp-req" } fake_creds() { cat > "${MHTMPDIR}/oauth-test" } fake_http_response() { echo "HTTP/1.1 $1" > "${testname}.http-res" cat >> "${testname}.http-res" } clean_fakehttp() { rm -f "${testname}.http-res" } fake_json_response() { (echo 'Content-Type: application/json'; echo; cat) | fake_http_response '200 OK' } # 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. Note that it is # sorted, so that it doesn't depend on the JSON being in a specific order. expect_http_post() { sort > "${testname}.expected-http-req" < "${MHTMPDIR}/$$.expected-creds" } test_inc() { run_test "inc -host 127.0.0.1 -port ${pop_port} -saslmech xoauth2 -authservice test -user nobody@example.com -width 80" "$@" } test_inc_success() { test_inc 'Incorporating new mail into inbox... 11+ 12/17 No Such User Hello<>' check "${pop_message}" "`mhpath +inbox 11`" 'keep first' } test_send_no_servers() { run_test "send -draft -server 127.0.0.1 -port ${smtp_port} -saslmech xoauth2 -authservice test -user nobody@example.com" "$@" } test_send_only_fakesmtp() { start_fakesmtp test_send_no_servers "$@" } test_send() { start_fakehttp test_send_only_fakesmtp "$@" 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() { 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() { f="${MHTMPDIR}/oauth-test" if ls -dl "$f" | grep '^-rw-------' > /dev/null 2>&1; then : else echo "$f permissions not private" failed=`expr ${failed:-0} + 1` fi } check_creds() { # It's hard to calculate the exact expiration time mhlogin is going to use, # so we'll just use sed to remove the actual time so we can easily compare # it against our "correct" output. f="${MHTMPDIR}/oauth-test" sed 's/^\(expire.*:\).*/\1/' "$f" > "$f".notime check "$f".notime "${MHTMPDIR}/$$.expected-creds" rm "$f" }