Skip to content

Commit e563730

Browse files
committed
Simplify the nvm_ls_remote_with_proxy_requiring_basic_auth test.
1 parent 1a14b76 commit e563730

File tree

3 files changed

+44
-24
lines changed

3 files changed

+44
-24
lines changed

test/fast/Unit tests/ferron-iojs-mirror.kdl

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/fast/Unit tests/ferron-nodejs-mirror.kdl

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/fast/Unit tests/nvm_ls_remote_with_proxy_requiring_basic_auth

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,62 @@
22
# shellcheck shell=dash
33
# shellcheck disable=SC2039 # local is non-POSIX
44

5+
temp_nodejs_tmp_root=""
6+
temp_iojs_tmp_root=""
57
cleanup () {
68
unset -f die cleanup NVM_NODEJS_ORG_MIRROR
79
docker stop ferron-nodejs-mirror && docker rm ferron-nodejs-mirror
810
docker stop ferron-iojs-mirror && docker rm ferron-iojs-mirror
11+
if [ -n "${temp_nodejs_tmp_root}" ]; then
12+
rm -rf -- "${temp_nodejs_tmp_root}"
13+
fi
14+
if [ -n "${temp_iojs_tmp_root}" ]; then
15+
rm -rf -- "${temp_iojs_tmp_root}"
16+
fi
917
}
1018
die () { echo "$@" ; cleanup ; exit 1; }
1119

1220
set -e
1321

14-
{ [ -e "ferron-nodejs-mirror.kdl" ] && [ -e "ferron-iojs-mirror.kdl" ]; } || die nvm_ls_remote_with_proxy_requiring_basic_auth Need to set working directory of script to Unit tests directory.
15-
1622
# shellcheck source=/dev/null # The nvm.sh script is checked separately.
1723
\. ../../../nvm.sh
1824

19-
docker run --detach --name ferron-nodejs-mirror --publish 8080:8080 --volume "$(pwd):/mnt/cwd" ferronserver/ferron:2 ferron --config /mnt/cwd/ferron-nodejs-mirror.kdl
20-
docker run --detach --name ferron-iojs-mirror --publish 8081:8081 --volume "$(pwd):/mnt/cwd" ferronserver/ferron:2 ferron --config /mnt/cwd/ferron-iojs-mirror.kdl
25+
# Setup the temporary directories to host the mock nodejs and iojs mirrors.
26+
MOCKS_DIR="$PWD/mocks"
27+
temp_nodejs_tmp_root="$(mktemp --directory)"
28+
mkdir -p "${temp_nodejs_tmp_root}/dist"
29+
cp "$MOCKS_DIR/nodejs.org-dist-index.tab" "${temp_nodejs_tmp_root}/dist/index.tab"
30+
temp_iojs_tmp_root="$(mktemp --directory)"
31+
mkdir -p "${temp_iojs_tmp_root}/dist"
32+
cp "$MOCKS_DIR/iojs.org-dist-index.tab" "${temp_iojs_tmp_root}/dist/index.tab"
33+
34+
# Add necessary ferron config file needed for both containers.
35+
# NOTE: The valid credentials for these test servers are 'test:123?45>6'.
36+
cat <<EOF >"${temp_nodejs_tmp_root}/ferron.kdl"
37+
:8080 {
38+
log "/dev/stderr"
39+
error_log "/dev/stderr"
40+
status 401 users="test" brute_protection=#false
41+
user "test" "\$argon2id\$v=19\$m=19456,t=2,p=1\$emTillHaS3OqFuvITdXxzg\$G00heP8QSXk5H/ruTiLt302Xk3uETfU5QO8hBIwUq08"
42+
root "/mnt/www"
43+
}
44+
EOF
45+
cat <<EOF >"${temp_iojs_tmp_root}/ferron.kdl"
46+
:8081 {
47+
log "/dev/stderr"
48+
error_log "/dev/stderr"
49+
status 401 users="test" brute_protection=#false
50+
user "test" "\$argon2id\$v=19\$m=19456,t=2,p=1\$emTillHaS3OqFuvITdXxzg\$G00heP8QSXk5H/ruTiLt302Xk3uETfU5QO8hBIwUq08"
51+
root "/mnt/www"
52+
}
53+
EOF
54+
# Need to adjust permissions to ensure ferron running under container can read the files in the temp directories.
55+
chmod a+rx "${temp_nodejs_tmp_root}"
56+
chmod a+rx "${temp_iojs_tmp_root}"
57+
58+
# Start containers
59+
docker run --detach --name ferron-nodejs-mirror --publish 8080:8080 --volume "${temp_nodejs_tmp_root}:/mnt/www" --workdir "/mnt/www" ferronserver/ferron:2 ferron --config /mnt/www/ferron.kdl
60+
docker run --detach --name ferron-iojs-mirror --publish 8081:8081 --volume "${temp_iojs_tmp_root}:/mnt/www" --workdir "/mnt/www" ferronserver/ferron:2 ferron --config /mnt/www/ferron.kdl
2161
sleep 1 # wait for ferron containers to start
2262

2363
export NVM_NODEJS_ORG_MIRROR="http://localhost:8080/dist"

0 commit comments

Comments
 (0)