Skip to content

Commit 464abd9

Browse files
committed
add basic tests for PREFIX_LEADING_DIRECTORY_PATH
1 parent 11bab22 commit 464abd9

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

standalone_ubuntu_oss_install.sh

+2
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ PROXY_CACHE_VALID_FORBIDDEN=${PROXY_CACHE_VALID_FORBIDDEN:-'30s'}
173173
CORS_ENABLED=${CORS_ENABLED:-'false'}
174174
# Configure portion of URL to be removed (optional)
175175
STRIP_LEADING_DIRECTORY_PATH=${STRIP_LEADING_DIRECTORY_PATH:-''}
176+
# Configure portion of URL to be added to the beginning of the requested path (optional)
177+
PREFIX_LEADING_DIRECTORY_PATH=${PREFIX_LEADING_DIRECTORY_PATH:-''}
176178
EOF
177179

178180
# By enabling CORS, we also need to enable the OPTIONS method which

test.sh

+25-11
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,13 @@ integration_test() {
249249
printf "\e[1m Integration test suite with APPEND_SLASH_FOR_POSSIBLE_DIRECTORY=%s\e[22m\n" "$4"
250250
printf "\033[34;1m▶\033[0m"
251251
printf "\e[1m Integration test suite with STRIP_LEADING_DIRECTORY_PATH=%s\e[22m\n" "$5"
252+
printf "\033[34;1m▶\033[0m"
253+
printf "\e[1m Integration test suite with PREFIX_LEADING_DIRECTORY_PATH=%s\e[22m\n" "$6"
254+
252255

253256
p "Starting Docker Compose Environment"
254257
# COMPOSE_COMPATIBILITY=true Supports older style compose filenames with _ vs -
255-
COMPOSE_COMPATIBILITY=true AWS_SIGS_VERSION=$1 ALLOW_DIRECTORY_LIST=$2 PROVIDE_INDEX_PAGE=$3 APPEND_SLASH_FOR_POSSIBLE_DIRECTORY=$4 STRIP_LEADING_DIRECTORY_PATH=$5 compose up -d
258+
COMPOSE_COMPATIBILITY=true AWS_SIGS_VERSION=$1 ALLOW_DIRECTORY_LIST=$2 PROVIDE_INDEX_PAGE=$3 APPEND_SLASH_FOR_POSSIBLE_DIRECTORY=$4 STRIP_LEADING_DIRECTORY_PATH=$5 PREFIX_LEADING_DIRECTORY_PATH=$6 compose up -d
256259

257260
if [ "${wait_for_it_installed}" ]; then
258261
if [ -x "${wait_for_it_cmd}" ]; then
@@ -261,8 +264,8 @@ integration_test() {
261264
fi
262265

263266
p "Starting HTTP API tests (v$1 signatures)"
264-
echo " test/integration/test_api.sh \"$test_server\" \"$test_dir\" $1 $2 $3 $4 $5"
265-
bash "${test_dir}/integration/test_api.sh" "${test_server}" "${test_dir}" "$1" "$2" "$3" "$4" "$5";
267+
echo " test/integration/test_api.sh \"$test_server\" \"$test_dir\" $1 $2 $3 $4 $5 $6"
268+
bash "${test_dir}/integration/test_api.sh" "${test_server}" "${test_dir}" "$1" "$2" "$3" "$4" "$5" "$6";
266269

267270
# We check to see if NGINX is in fact using the correct version of AWS
268271
# signatures as it was configured to do.
@@ -404,41 +407,52 @@ runUnitTestWithSessionToken "s3gateway_test.js"
404407
integration_test_data
405408

406409
p "Testing API with AWS Signature V2 and allow directory listing off"
407-
integration_test 2 0 0 0 ""
410+
integration_test 2 0 0 0 "" ""
408411

409412
compose stop nginx-s3-gateway # Restart with new config
410413

411414
p "Testing API with AWS Signature V2 and allow directory listing on"
412-
integration_test 2 1 0 0 ""
415+
integration_test 2 1 0 0 "" ""
413416

414417
compose stop nginx-s3-gateway # Restart with new config
415418

416419
p "Testing API with AWS Signature V2 and static site on"
417-
integration_test 2 0 1 0 ""
420+
integration_test 2 0 1 0 "" ""
418421

419422
compose stop nginx-s3-gateway # Restart with new config
420423

421424
p "Testing API with AWS Signature V2 and allow directory listing on and append slash and allow index"
422-
integration_test 2 1 1 1 ""
425+
integration_test 2 1 1 1 "" ""
423426

424427
compose stop nginx-s3-gateway # Restart with new config
425428

426429
p "Test API with AWS Signature V4 and allow directory listing off"
427-
integration_test 4 0 0 0 ""
430+
integration_test 4 0 0 0 "" ""
428431

429432
compose stop nginx-s3-gateway # Restart with new config
430433

431434
p "Test API with AWS Signature V4 and allow directory listing on and appending /"
432-
integration_test 4 1 0 1 ""
435+
integration_test 4 1 0 1 "" ""
433436

434437
compose stop nginx-s3-gateway # Restart with new config
435438

436439
p "Test API with AWS Signature V4 and static site on appending /"
437-
integration_test 4 0 1 1 ""
440+
integration_test 4 0 1 1 "" ""
438441

439442
compose stop nginx-s3-gateway # Restart with new config
440443

441444
p "Testing API with AWS Signature V2 and allow directory listing off and prefix stripping on"
442-
integration_test 2 0 0 0 /my-bucket
445+
integration_test 2 0 0 0 /my-bucket ""
446+
447+
compose stop nginx-s3-gateway # Restart with new config
448+
449+
p "Test API with AWS Signature V4 and prefix leading directory path on"
450+
integration_test 4 0 0 0 "" "/b"
451+
452+
p "Test API with AWS Signature V4 and prefix leading directory path on and prefix stripping on"
453+
integration_test 4 0 0 0 "/tostrip" "/b"
454+
455+
p "Testing API with AWS Signature V2 and prefix leading directory path"
456+
integration_test 2 0 0 0 "" "/b"
443457

444458
p "All integration tests complete"

test/docker-compose.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ services:
2727
PROVIDE_INDEX_PAGE:
2828
APPEND_SLASH_FOR_POSSIBLE_DIRECTORY:
2929
STRIP_LEADING_DIRECTORY_PATH:
30+
PREFIX_LEADING_DIRECTORY_PATH:
3031
AWS_SIGS_VERSION:
3132
STATIC_SITE_HOSTING:
3233
PROXY_CACHE_MAX_SIZE: "10g"

test/integration/test_api.sh

+15
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ allow_directory_list=$4
2626
index_page=$5
2727
append_slash=$6
2828
strip_leading_directory=$7
29+
prefix_leading_directory_path=$8
30+
2931
test_fail_exit_code=2
3032
no_dep_exit_code=3
3133
checksum_length=32
@@ -159,6 +161,19 @@ for (( i=1; i<=3; i++ )); do
159161
done
160162
set -o errexit
161163

164+
if [ -n "${prefix_leading_directory_path}" ]; then
165+
assertHttpRequestEquals "GET" "/c/d.txt" "data/bucket-1/b/c/d.txt"
166+
167+
if [ -n "${strip_leading_directory}" ]; then
168+
# When these two flags are used together, stripped value is basically
169+
# replaced with the specified prefix
170+
assertHttpRequestEquals "GET" "/tostrip/c/d.txt" "data/bucket-1/b/c/d.txt"
171+
fi
172+
173+
# Exit early for this case since all tests following will fail because of the added prefix
174+
exit 0
175+
fi
176+
162177
# Ordinary filenames
163178

164179
assertHttpRequestEquals "HEAD" "a.txt" "200"

0 commit comments

Comments
 (0)