Skip to content

Commit

Permalink
tests:: fix 002_env_tokens.test
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansev committed Nov 27, 2023
1 parent 00c719c commit dcf57d6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions alienpy/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down
42 changes: 23 additions & 19 deletions tests/002_env_tokens.test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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};

0 comments on commit dcf57d6

Please sign in to comment.