#!/bin/sh # # Test mhlogin # if test -z "${MH_OBJ_DIR}"; then srcdir=`dirname "$0"`/../.. MH_OBJ_DIR=`cd "${srcdir}" && pwd`; export MH_OBJ_DIR fi . "${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" chmod 600 "${MHTMPDIR}/oauth-test" } test_mhlogin() { start_fakehttp run_test 'eval echo code | 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: $1" check_http_req check_creds_private check_creds } test_mhlogin_invalid_response() { test_mhlogin 'mhlogin: error exchanging code for OAuth2 token mhlogin: invalid response' } # # success cases # # TEST start_test 'mhlogin receives access and expiration' expect_http_post_code fake_json_response < ${MHTMPDIR}/$$.browser" 2>&1 1>/dev/null | \ sed 's/\( endpoint:\) .*/\1/' > "${MHTMPDIR}/$$.mhlogin.err" cat > "${MHTMPDIR}/$$.mhlogin.err.expected" < "${MHTMPDIR}/$$.browser.expected" <