2016-08-11 14:09:54 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
2016-11-07 03:34:36 +08:00
|
|
|
die () { echo "$@" ; exit 1; }
|
2016-08-11 14:09:54 +08:00
|
|
|
|
2017-03-17 14:54:55 +08:00
|
|
|
unset NVM_NODEJS_ORG_MIRROR
|
|
|
|
unset NVM_IOJS_ORG_MIRROR
|
|
|
|
|
2017-03-29 00:37:14 +08:00
|
|
|
set +e # TODO: fix
|
2016-11-04 13:15:18 +08:00
|
|
|
\. ../../../nvm.sh
|
2017-03-29 00:37:14 +08:00
|
|
|
set -e
|
2016-08-11 14:09:54 +08:00
|
|
|
|
|
|
|
! nvm_get_mirror || die 'unknown release type did not error'
|
|
|
|
! nvm_get_mirror node || die 'unknown release type did not error'
|
|
|
|
! nvm_get_mirror iojs || die 'unknown release type did not error'
|
|
|
|
! nvm_get_mirror node foo || die 'unknown release type did not error'
|
|
|
|
! nvm_get_mirror iojs foo || die 'unknown release type did not error'
|
|
|
|
|
2017-03-17 14:54:55 +08:00
|
|
|
[ -z "$NVM_NODEJS_ORG_MIRROR" ] || die "MIRROR environment variables should not be exported"
|
|
|
|
[ -z "$NVM_IOJS_ORG_MIRROR" ] || die "MIRROR environment variables should not be exported"
|
|
|
|
|
|
|
|
[ "$(nvm_get_mirror node std)" = "https://nodejs.org/dist" ] || die "incorrect default node-std mirror"
|
|
|
|
[ "$(nvm_get_mirror iojs std)" = "https://iojs.org/dist" ] || die "incorrect default iojs-std mirror"
|
|
|
|
|
2023-12-03 06:44:46 +08:00
|
|
|
NVM_NODEJS_ORG_MIRROR="https://test-domain"
|
|
|
|
[ "$(nvm_get_mirror node std)" = "https://test-domain" ] || die "node-std mirror should respect NVM_NODEJS_ORG_MIRROR"
|
2017-03-17 14:54:55 +08:00
|
|
|
unset NVM_NODEJS_ORG_MIRROR
|
|
|
|
|
2023-12-03 06:44:46 +08:00
|
|
|
NVM_IOJS_ORG_MIRROR="https://test-domain"
|
|
|
|
[ "$(nvm_get_mirror iojs std)" = "https://test-domain" ] || die "iojs-std mirror should respect NVM_IOJS_ORG_MIRROR"
|
2017-03-17 14:54:55 +08:00
|
|
|
unset NVM_IOJS_ORG_MIRROR
|
2023-11-02 12:01:28 +08:00
|
|
|
|
2023-12-03 06:44:46 +08:00
|
|
|
testMirrors() {
|
|
|
|
NVM_NODEJS_ORG_MIRROR="${1-}"
|
|
|
|
! nvm_get_mirror node std || die "NVM_NODEJS_ORG_MIRROR errors with command injection attempt (${1-})"
|
|
|
|
[ "$(nvm_get_mirror node std)" = "" ] || die 'NVM_NODEJS_ORG_MIRROR is protected against command injection'
|
2023-11-02 12:01:28 +08:00
|
|
|
|
2023-12-03 06:44:46 +08:00
|
|
|
NVM_IOJS_ORG_MIRROR="${1-}"
|
|
|
|
! nvm_get_mirror iojs std || die "NVM_IOJS_ORG_MIRROR errors with command injection attempt (${1-})"
|
|
|
|
[ "$(nvm_get_mirror iojs std)" = "" ] || die 'NVM_IOJS_ORG_MIRROR is protected against command injection'
|
|
|
|
}
|
|
|
|
|
|
|
|
testMirrors '`do something bad`'
|
|
|
|
testMirrors 'https://nodejs.org/dist; xdg-open http://www.google.com;'
|
|
|
|
testMirrors 'https://nodejs.org/dist&&xdg-open http://www.google.com;'
|
|
|
|
testMirrors 'https://nodejs.org/dist|xdg-open http://www.google.com;'
|