From dcf57d619864ba05b1af6e62d32165c00878b604 Mon Sep 17 00:00:00 2001 From: Adrian Sevcenco Date: Mon, 27 Nov 2023 12:57:56 +0200 Subject: [PATCH] tests:: fix 002_env_tokens.test --- alienpy/version.py | 4 +-- tests/002_env_tokens.test/test.sh | 42 +++++++++++++++++-------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/alienpy/version.py b/alienpy/version.py index bd5cca6..70e848f 100644 --- a/alienpy/version.py +++ b/alienpy/version.py @@ -2,8 +2,8 @@ import sys -ALIENPY_VERSION_HASH = 'd946ecb' -ALIENPY_VERSION_DATE = '20231127_094152' +ALIENPY_VERSION_HASH = '000a445' +ALIENPY_VERSION_DATE = '20231127_105732' ALIENPY_VERSION_STR = '1.5.5' if __name__ == '__main__': diff --git a/tests/002_env_tokens.test/test.sh b/tests/002_env_tokens.test/test.sh index 220a600..8243917 100755 --- a/tests/002_env_tokens.test/test.sh +++ b/tests/002_env_tokens.test/test.sh @@ -6,39 +6,43 @@ command -v alien.py &> /dev/null || { echo "alien.py command not found; skip tes export ALIENPY_DEBUG=1 ALIENPY_DEBUG_FILE=log.txt ALIENPY_DEBUG_APPEND=1 clean_logs +# Clear env if set +unset ${JALIEN_TOKEN_CERT} ${JALIEN_TOKEN_KEY} tokens_backup () { -echo ${1} -echo ${2} -mv "${1}" "${1}_backup" -mv "${2}" "${2}_backup" +token1="$(realpath ${1})" +shift +token2="$(realpath ${1})" +shift +mv -f "${token1}" "${token1}_backup" +mv -f "${token2}" "${token2}_backup" } tokens_restore () { -mv "${1}_backup" "${1}" -mv "${2}_backup" "${2}" +token1="$(realpath ${1})" +shift +token2="$(realpath ${1})" +shift +mv -f "${token1}_backup" "${token1}" +mv -f "${token2}_backup" "${token2}" } TMPDIR=${TMPDIR:-/tmp} FILECERT="${TMPDIR}/tokencert_$(id -u).pem" -FILEKEY="${TMPDIR}/tokenkey_$(id -u).pem)" - -# Clear env if set -unset ${JALIEN_TOKEN_CERT} ${JALIEN_TOKEN_KEY} +FILEKEY="${TMPDIR}/tokenkey_$(id -u).pem" # backup tokens tokens_backup "${FILECERT}" "${FILEKEY}" -exit - # check that error is thrown if tokens are missing -alien-token-info &> /dev/null && { echo "exitcode == 0 when it should fail"; exit 1; } - -export JALIEN_TOKEN_CERT="$(< ${FILECERT})" -export JALIEN_TOKEN_KEY="$(< ${FILEKEY})" -alien-token-info &> /dev/null || { echo "No alien token found"; tokens_restore "${FILECERT}" "${FILEKEY}"; exit 1; } +alien-token-info &> /dev/null && { echo "The missing tokens case should fail"; exit 1; } -alien.py pwd &> /dev/null && { clean_logs; } || { echo "Error running pwd"; tokens_restore "${FILECERT}" "${FILEKEY}"; exit 1; } +export JALIEN_TOKEN_CERT="$(< ${FILECERT}_backup)" +export JALIEN_TOKEN_KEY="$(< ${FILEKEY}_backup)" +alien-token-info &> /dev/null || { echo "FAIL! No alien token found"; STATUS="1"; } && { echo "OK! valid tokens found in environment"; STATUS="0"; } +[[ "${STATUS}" == "1" ]] && { tokens_restore "${FILECERT}" "${FILEKEY}"; exit ${STATUS}; } -tokens_restore "${FILECERT}" "${FILEKEY}" +alien.py pwd &> /dev/null && { echo "OK! valid connection to JAliEn services"; STATUS="0"; clean_logs; } || { echo "FAIL! error connecting to JAliEn Services"; STATUS="1"; } +tokens_restore "${FILECERT}" "${FILEKEY}"; +exit ${STATUS};