Compare commits

..

2 Commits

Author SHA1 Message Date
David Welch
87ba60ed30
Merge 4cf9964fbdd7130c2e5e35a662b608be37e75ee0 into e597bb208efe942f30139df88b5ef74e78c15925 2024-06-29 00:01:05 +00:00
David Welch
4cf9964fbd
[New] Add support for NVM_AUTH_HEADER env var
Co-authored-by: David Welch <david@davidwelch.co>
Co-authored-by: Andre Kradolfer <narfdre@gmail.com>
2024-06-21 08:55:22 -06:00
2 changed files with 10 additions and 10 deletions

13
nvm.sh
View File

@ -120,15 +120,16 @@ nvm_download() {
local CURL_COMPRESSED_FLAG="" local CURL_COMPRESSED_FLAG=""
local CURL_HEADER_FLAG="" local CURL_HEADER_FLAG=""
if [ -n "${NVM_AUTH_HEADER:-}" ]; then if [ -n "$NVM_AUTH_HEADER" ]; then
sanitized_header=$(nvm_sanitize_auth_header "${NVM_AUTH_HEADER}") sanitized_header=$(nvm_sanitize_auth_header "$NVM_AUTH_HEADER")
CURL_HEADER_FLAG="--header \"Authorization: ${sanitized_header}\"" CURL_HEADER_FLAG="--header \"Authorization: $sanitized_header\""
fi fi
if nvm_curl_use_compression; then if nvm_curl_use_compression; then
CURL_COMPRESSED_FLAG="--compressed" CURL_COMPRESSED_FLAG="--compressed"
fi fi
eval "curl -q --fail ${CURL_COMPRESSED_FLAG:-} ${CURL_HEADER_FLAG:-} $*"
eval "curl -q --fail ${CURL_COMPRESSED_FLAG:-} ${CURL_HEADER_FLAG:-} $@"
elif nvm_has "wget"; then elif nvm_has "wget"; then
# Emulate curl with wget # Emulate curl with wget
ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \ ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \
@ -151,7 +152,7 @@ nvm_download() {
nvm_sanitize_auth_header() { nvm_sanitize_auth_header() {
# Remove potentially dangerous characters # Remove potentially dangerous characters
nvm_echo "$1" | command sed 's/[^a-zA-Z0-9:;_. -]//g' echo "$1" | sed 's/[^a-zA-Z0-9:;_. -]//g'
} }
nvm_has_system_node() { nvm_has_system_node() {

View File

@ -19,10 +19,9 @@ nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" >/de
# nvm_download should pass when calling with auth header # nvm_download should pass when calling with auth header
docker pull kennethreitz/httpbin && docker run -d --name httpbin -p 80:80 kennethreitz/httpbin docker pull kennethreitz/httpbin && docker run -d --name httpbin -p 80:80 kennethreitz/httpbin
sleep 1 # wait for httpbin to start sleep 1 # wait for httpbin to start
NVM_AUTH_HEADER="Bearer test-token" nvm_download "http://127.0.0.1/bearer" > /dev/null || die 'nvm_download with auth header should send correctly' NVM_AUTH_HEADER="Bearer test-token"
nvm_download "http://127.0.0.1/bearer" > /dev/null || die "nvm_download unable to send auth header"
# nvm_download should fail when calling without auth header unset NVM_AUTH_HEADER
nvm_download "http://127.0.0.1/bearer" > /dev/null && die 'nvm_download with no auth header should not send the header and should fail'
docker stop httpbin && docker rm httpbin docker stop httpbin && docker rm httpbin
cleanup cleanup