Six fast tests failed outside of CI's setup, which runs them as a non-root user with `sudo` and a terminal. `nvm_download_artifact error propagation` expected `mkdir -p` under `/nonexistent` to fail, which root can create; it now uses a path under a regular file, which nobody can create. `nvm_get_arch_unofficial` now only uses `sudo` when it is not already root, and skips the chroot checks when it can do neither. `nvm_write_nvmrc`'s permissions check and the `nvm uninstall` permissions test are skipped as root, since root ignores file permissions. `nvm_stdout_is_terminal`'s `/dev/tty` checks are skipped when there is no controlling terminal, as in `docker run` without `-t`. `nvm_process_nvmrc` now fails with a clear message when the `test/fixtures/nvmrc` submodule is not checked out, instead of on an unexpanded glob. This is not a vulnerability fix.
59 lines
1.7 KiB
Bash
Executable File
59 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
die () { echo "$@" ; exit 1; }
|
|
|
|
: nvm.sh
|
|
\. ../../../nvm.sh
|
|
|
|
\. ../../common.sh
|
|
|
|
# Test that mkdir failure propagates from brace group (not subshell)
|
|
# a path under a regular file can not be created, even by root
|
|
NOT_A_DIR="$(mktemp)"
|
|
nvm_download_artifact_mkdir_test() {
|
|
local tmpdir
|
|
tmpdir="${NOT_A_DIR}/path"
|
|
command mkdir -p "${tmpdir}/files" || {
|
|
return 3
|
|
}
|
|
}
|
|
nvm_download_artifact_mkdir_test 2>/dev/null
|
|
EXIT_CODE=$?
|
|
command rm -f "${NOT_A_DIR}"
|
|
[ "${EXIT_CODE}" = "3" ] || die "Expected mkdir failure to propagate with exit code 3, got ${EXIT_CODE}"
|
|
|
|
# Test that download failure propagates with exit code 4
|
|
nvm_get_mirror() { echo "http://example.com"; }
|
|
nvm_binary_available() { return 0; }
|
|
nvm_get_download_slug() { echo "node-v20.0.0-linux-x64"; }
|
|
nvm_get_artifact_compression() { echo "tar.gz"; }
|
|
nvm_cache_dir() { echo "${TMPDIR:-/tmp}/nvm_test_cache_$$"; }
|
|
nvm_get_checksum() { echo "fake_checksum"; }
|
|
nvm_version_greater_than_or_equal_to() { return 0; }
|
|
nvm_download() { return 1; }
|
|
nvm_grep() { return 1; }
|
|
|
|
nvm_download_artifact node binary std v20.0.0 2>/dev/null
|
|
EXIT_CODE=$?
|
|
[ "${EXIT_CODE}" = "4" ] || die "Expected download failure to propagate with exit code 4, got ${EXIT_CODE}"
|
|
|
|
# clean up any dirs created by the download failure test
|
|
command rm -rf "$(nvm_cache_dir)"
|
|
|
|
# Test that checksum failure propagates with exit code 6
|
|
nvm_download() {
|
|
while [ "$#" -gt 0 ]; do
|
|
if [ "$1" = "-o" ]; then command touch "$2"; return 0; fi
|
|
shift
|
|
done
|
|
return 0
|
|
}
|
|
nvm_compare_checksum() { return 1; }
|
|
|
|
nvm_download_artifact node binary std v20.0.0 2>/dev/null
|
|
EXIT_CODE=$?
|
|
[ "${EXIT_CODE}" = "6" ] || die "Expected checksum failure to propagate with exit code 6, got ${EXIT_CODE}"
|
|
|
|
# clean up
|
|
command rm -rf "$(nvm_cache_dir)"
|