Skip to content
Myr

[Fix] `nvm_download`: send a well-formed Authorization header on the wget path

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The wget path passed `NVM_AUTH_HEADER` as the raw header line (e.g. `--header "Bearer secret-token"`), omitting the `Authorization:` header name that the curl path includes. Per the documented usage (`NVM_AUTH_HEADER="Bearer secret-token"`) the value is the credential, so wget was sending a malformed header. Prefix it with `Authorization: ` to match the curl path.

authored by Jordan Harband · committed by Jordan Harband · parent 84079db · Browse files · 2 files+44 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+44 added−1 removed

  • tests:+43 added−0 removed
  • other:+1 added−1 removed

2 files+44 added−1 removed

added:test/fast/Unit tests/nvm_download wget Authorization header+43 added
1#!/bin/sh23OLDPATH="$PATH"4WORK="$PWD/nvm_download-wgetauth-work.$$"5TEST_BIN="$WORK/bin"6ARGV_LOG="$WORK/argv.log"78cleanup() {9 unset -f die cleanup nvm_has10 rm -rf "$WORK"11 export PATH="$OLDPATH"12}13die () { echo "$@" ; cleanup ; exit 1; }1415\. ../../../nvm.sh1617OLDPATH="$PATH"1819mkdir -p "$TEST_BIN"2021# fake wget: record each received argument verbatim, then succeed22{23 echo '#!/bin/sh'24 echo ': > "$ARGV_LOG"'25 echo 'for a in "$@"; do printf "%s\n" "$a" >> "$ARGV_LOG"; done'26 echo 'exit 0'27} > "$TEST_BIN/wget"28chmod +x "$TEST_BIN/wget"2930export ARGV_LOG31export PATH="$TEST_BIN:$OLDPATH"32# force the wget path while keeping system tools (sed) available for sanitization33nvm_has() { [ "$1" != curl ] && command -v "$1" >/dev/null 2>&1; }3435# given an Authorization credential in NVM_AUTH_HEADER36# when nvm_download uses the wget path37NVM_AUTH_HEADER='Bearer test-token' nvm_download "https://nodejs.org/dist/x" -o - || die 'nvm_download (wget) returned nonzero'38# then wget receives a well-formed Authorization header (with the header name, like the curl path)39grep -Fxqe '--header' "$ARGV_LOG" || die "wget did not receive --header; got: $(cat "$ARGV_LOG")"40grep -Fxq 'Authorization: Bearer test-token' "$ARGV_LOG" || die "wget did not receive a well-formed Authorization header; got: $(cat "$ARGV_LOG")"4142cleanup43echo "nvm_download wget Authorization header: passed"
modified:nvm.sh+1 added-1 removed
149 unmodified lines
150 ")151152 if [ -n "${NVM_AUTH_HEADER:-}" ]; then153 sanitized_header=$(nvm_sanitize_auth_header "${NVM_AUTH_HEADER}")154 ARGS="${ARGS} --header \"${sanitized_header}\""154 ARGS="${ARGS} --header \"Authorization: ${sanitized_header}\""155 fi156 # shellcheck disable=SC2086157 eval wget $ARGS158 fi
4667 unmodified lines