Skip to content

Commit a20b27e

Browse files
committed
test: commit
1 parent 9562c00 commit a20b27e

File tree

5 files changed

+114
-25
lines changed

5 files changed

+114
-25
lines changed

tests/commands/head_bucket.sh

+23
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ head_bucket() {
3535
bucket_info=$(send_command s3cmd --no-check-certificate info "s3://$2" 2>&1) || exit_code=$?
3636
elif [[ $1 == 'mc' ]]; then
3737
bucket_info=$(send_command mc --insecure stat "$MC_ALIAS"/"$2" 2>&1) || exit_code=$?
38+
elif [[ $1 == 'rest' ]]; then
39+
bucket_info=$(head_bucket_rest "$2") || exit_code=$?
40+
return $exit_code
3841
else
3942
log 2 "invalid command type $1"
4043
fi
@@ -49,3 +52,23 @@ head_bucket() {
4952
echo "$bucket_info"
5053
return 0
5154
}
55+
56+
head_bucket_rest() {
57+
if [ $# -ne 1 ]; then
58+
log 2 "'head_bucket_rest' requires bucket name"
59+
return 2
60+
fi
61+
if ! result=$(COMMAND_LOG="$COMMAND_LOG" BUCKET_NAME="$BUCKET_ONE_NAME" OUTPUT_FILE="$TEST_FILE_FOLDER/result.txt" ./tests/rest_scripts/head_bucket.sh 2>&1); then
62+
log 2 "error getting head bucket"
63+
return 2
64+
fi
65+
if [ "$result" == "200" ]; then
66+
bucket_info="$(cat "$TEST_FILE_FOLDER/result.txt")"
67+
echo "$bucket_info"
68+
return 0
69+
elif [ "$result" == "404" ]; then
70+
return 1
71+
fi
72+
log 2 "unexpected response code '$result' ($(cat "$TEST_FILE_FOLDER/result.txt"))"
73+
return 2
74+
}

tests/rest_scripts/head_bucket.sh

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2024 Versity Software
4+
# This file is licensed under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance
6+
# with the License. You may obtain a copy of the License at
7+
#
8+
# http:#www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing,
11+
# software distributed under the License is distributed on an
12+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13+
# KIND, either express or implied. See the License for the
14+
# specific language governing permissions and limitations
15+
# under the License.
16+
17+
source ./tests/rest_scripts/rest.sh
18+
19+
# Fields
20+
21+
# shellcheck disable=SC2153
22+
bucket_name="$BUCKET_NAME"
23+
24+
# shellcheck disable=SC2034
25+
current_date_time=$(date -u +"%Y%m%dT%H%M%SZ")
26+
27+
canonical_request_data=("HEAD" "/$bucket_name" "" "host:$host")
28+
canonical_request_data+=("x-amz-content-sha256:UNSIGNED-PAYLOAD" "x-amz-date:$current_date_time")
29+
if ! build_canonical_request "${canonical_request_data[@]}"; then
30+
log_rest 2 "error building request"
31+
exit 1
32+
fi
33+
# shellcheck disable=SC2119
34+
create_canonical_hash_sts_and_signature
35+
36+
curl_command+=(curl -ksI -w "\"%{http_code}\"" "$AWS_ENDPOINT_URL/$bucket_name"
37+
-H "\"Authorization: AWS4-HMAC-SHA256 Credential=$aws_access_key_id/$year_month_day/$aws_region/s3/aws4_request,SignedHeaders=$param_list,Signature=$signature\"")
38+
curl_command+=("${header_fields[@]}")
39+
curl_command+=(-o "$OUTPUT_FILE")
40+
# shellcheck disable=SC2154
41+
eval "${curl_command[*]}" 2>&1

tests/test_rest.sh

+19-24
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ test_file="test_file"
124124
run bucket_cleanup_if_bucket_exists "s3api" "$BUCKET_ONE_NAME"
125125
assert_success
126126
# in static bucket config, bucket will still exist
127-
if ! bucket_exists "s3api" "$BUCKET_ONE_NAME"; then
127+
if ! bucket_exists "rest" "$BUCKET_ONE_NAME"; then
128128
run create_bucket_object_lock_enabled "$BUCKET_ONE_NAME"
129129
assert_success
130130
fi
@@ -155,7 +155,7 @@ test_file="test_file"
155155
assert_success
156156

157157
# in static bucket config, bucket will still exist
158-
if ! bucket_exists "s3api" "$BUCKET_ONE_NAME"; then
158+
if ! bucket_exists "rest" "$BUCKET_ONE_NAME"; then
159159
run create_bucket_object_lock_enabled "$BUCKET_ONE_NAME"
160160
assert_success
161161
fi
@@ -456,7 +456,7 @@ test_file="test_file"
456456
assert_success
457457

458458
# in static bucket config, bucket will still exist
459-
if ! bucket_exists "s3api" "$BUCKET_ONE_NAME"; then
459+
if ! bucket_exists "rest" "$BUCKET_ONE_NAME"; then
460460
run create_bucket_object_lock_enabled "$BUCKET_ONE_NAME"
461461
assert_success
462462
fi
@@ -482,7 +482,7 @@ test_file="test_file"
482482
assert_success
483483

484484
# in static bucket config, bucket will still exist
485-
if ! bucket_exists "s3api" "$BUCKET_ONE_NAME"; then
485+
if ! bucket_exists "rest" "$BUCKET_ONE_NAME"; then
486486
run create_bucket_object_lock_enabled "$BUCKET_ONE_NAME"
487487
assert_success
488488
fi
@@ -504,24 +504,19 @@ test_file="test_file"
504504
run setup_bucket_and_file "$BUCKET_ONE_NAME" "$test_file"
505505
assert_success
506506

507-
expiry_date="Thu, 01 Dec 2025 16:00:00 GMT"
508-
#expiry_date="kldfjakjf"
509-
if ! result=$(COMMAND_LOG="$COMMAND_LOG" DATA_FILE="$TEST_FILE_FOLDER/$test_file" BUCKET_NAME="$BUCKET_ONE_NAME" OBJECT_KEY="$test_file" EXPIRES="$expiry_date" TEST_FILE_FOLDER="$TEST_FILE_FOLDER" OUTPUT_FILE="$TEST_FILE_FOLDER/result.txt" ./tests/rest_scripts/put_object.sh 2>&1); then
510-
log 2 "error: $result"
511-
return 1
512-
fi
513-
if [ "$result" != "200" ]; then
514-
log 2 "expected response code of '200', was '$result' ($(cat "$TEST_FILE_FOLDER/result.txt"))"
515-
return 1
516-
fi
517-
if ! result=$(COMMAND_LOG="$COMMAND_LOG" BUCKET_NAME="$BUCKET_ONE_NAME" OBJECT_KEY="$test_file" TEST_FILE_FOLDER="$TEST_FILE_FOLDER" OUTPUT_FILE="$TEST_FILE_FOLDER/result.txt" ./tests/rest_scripts/head_object.sh 2>&1); then
518-
log 2 "error: $result"
519-
return 1
520-
fi
521-
if [ "$result" != "200" ]; then
522-
log 2 "expected response code of '200', was '$result' ($(cat "$TEST_FILE_FOLDER/result.txt"))"
523-
return 1
524-
fi
525-
log 5 "data: ($(cat "$TEST_FILE_FOLDER/result.txt"))"
526-
return 1
507+
run put_object_rest_check_expires_header "$TEST_FILE_FOLDER/$test_file" "$BUCKET_ONE_NAME" "$test_file"
508+
assert_success
509+
}
510+
511+
@test "REST - HeadBucket" {
512+
run setup_bucket "s3api" "$BUCKET_ONE_NAME"
513+
assert_success
514+
515+
run head_bucket_rest "$BUCKET_ONE_NAME"
516+
assert_success
517+
}
518+
519+
@test "REST - HeadBucket - doesn't exist" {
520+
run head_bucket_rest "$BUCKET_ONE_NAME"
521+
assert_failure 1
527522
}

tests/util/util_bucket.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ bucket_exists() {
152152
local exists=0
153153
head_bucket "$1" "$2" || exists=$?
154154
# shellcheck disable=SC2181
155-
if [ $exists -ne 0 ] && [ $exists -ne 1 ]; then
155+
if [ $exists -eq 2 ]; then
156156
log 2 "unexpected error checking if bucket exists"
157157
return 2
158158
fi

tests/util/util_object.sh

+30
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,33 @@ check_invalid_checksum_type() {
457457
return 1
458458
fi
459459
}
460+
461+
put_object_rest_check_expires_header() {
462+
if [ $# -ne 3 ]; then
463+
log 2 "'put_object-put_object_rest_check_expires_header' requires data file, bucket, key"
464+
return 1
465+
fi
466+
expiry_date="Tue, 11 Mar 2025 16:00:00 GMT"
467+
if ! result=$(COMMAND_LOG="$COMMAND_LOG" DATA_FILE="$1" BUCKET_NAME="$2" OBJECT_KEY="$3" EXPIRES="$expiry_date" OUTPUT_FILE="$TEST_FILE_FOLDER/result.txt" ./tests/rest_scripts/put_object.sh 2>&1); then
468+
log 2 "error: $result"
469+
return 1
470+
fi
471+
if [ "$result" != "200" ]; then
472+
log 2 "expected response code of '200', was '$result' ($(cat "$TEST_FILE_FOLDER/result.txt"))"
473+
return 1
474+
fi
475+
if ! result=$(COMMAND_LOG="$COMMAND_LOG" BUCKET_NAME="$BUCKET_ONE_NAME" OBJECT_KEY="$test_file" OUTPUT_FILE="$TEST_FILE_FOLDER/result.txt" ./tests/rest_scripts/head_object.sh 2>&1); then
476+
log 2 "error: $result"
477+
return 1
478+
fi
479+
if [ "$result" != "200" ]; then
480+
log 2 "expected response code of '200', was '$result' ($(cat "$TEST_FILE_FOLDER/result.txt"))"
481+
return 1
482+
fi
483+
returned_expiry_date="$(grep "Expires" "$TEST_FILE_FOLDER/result.txt" | cut -d' ' -f2- | tr -d '\r')"
484+
if [ "$returned_expiry_date" != "$expiry_date" ]; then
485+
log 2 "expected expiry date '$expiry_date', actual '$returned_expiry_date'"
486+
return 1
487+
fi
488+
return 0
489+
}

0 commit comments

Comments
 (0)