test: REST HeadObject, x-amz-checksum-sha256 test

This commit is contained in:
Luke McCrone
2025-02-17 21:02:54 -03:00
parent f42c20297b
commit 593b53d829
21 changed files with 267 additions and 314 deletions
+11 -12
View File
@@ -22,27 +22,26 @@ source ./tests/rest_scripts/rest.sh
bucket_name="$BUCKET_NAME"
# shellcheck disable=SC2154
key="$OBJECT_KEY"
# shellcheck disable=SC2154
checksum_mode="${CHECKSUM_MODE:=false}"
current_date_time=$(date -u +"%Y%m%dT%H%M%SZ")
#x-amz-object-attributes:ETag
canonical_request="GET
/$bucket_name/$key
canonical_request_data+=("GET" "/$bucket_name/$key" "" "host:$host")
if [ "$checksum_mode" == "true" ]; then
canonical_request_data+=("x-amz-checksum-mode:ENABLED")
fi
canonical_request_data+=("x-amz-content-sha256:UNSIGNED-PAYLOAD" "x-amz-date:$current_date_time")
host:$host
x-amz-content-sha256:UNSIGNED-PAYLOAD
x-amz-date:$current_date_time
host;x-amz-content-sha256;x-amz-date
UNSIGNED-PAYLOAD"
build_canonical_request "${canonical_request_data[@]}"
# shellcheck disable=SC2119
create_canonical_hash_sts_and_signature
curl_command+=(curl -ks -w "\"%{http_code}\"" "$AWS_ENDPOINT_URL/$bucket_name/$key"
-H "\"Authorization: AWS4-HMAC-SHA256 Credential=$aws_access_key_id/$year_month_day/$aws_region/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=$signature\""
-H "\"x-amz-content-sha256: UNSIGNED-PAYLOAD\""
-H "\"x-amz-date: $current_date_time\""
-o "$OUTPUT_FILE")
-H "\"Authorization: AWS4-HMAC-SHA256 Credential=$aws_access_key_id/$year_month_day/$aws_region/s3/aws4_request,SignedHeaders=$param_list,Signature=$signature\"")
curl_command+=("${header_fields[@]}")
curl_command+=(-o "$OUTPUT_FILE")
# shellcheck disable=SC2154
eval "${curl_command[*]}" 2>&1
+12 -4
View File
@@ -36,13 +36,21 @@ x-amz-date:$current_date_time
host;x-amz-content-sha256;x-amz-date
UNSIGNED-PAYLOAD"
canonical_request_data=("HEAD" "/$bucket_name/$key" "" "host:$host")
if [ "$CHECKSUM" == "true" ]; then
canonical_request_data+=("x-amz-checksum-mode:ENABLED")
fi
canonical_request_data+=("x-amz-content-sha256:UNSIGNED-PAYLOAD" "x-amz-date:$current_date_time")
if ! build_canonical_request "${canonical_request_data[@]}"; then
log_rest 2 "error building request"
exit 1
fi
# shellcheck disable=SC2119
create_canonical_hash_sts_and_signature
curl_command+=(curl -ksI -w "\"%{http_code}\"" "$AWS_ENDPOINT_URL/$bucket_name/$key"
-H "\"Authorization: AWS4-HMAC-SHA256 Credential=$aws_access_key_id/$year_month_day/$aws_region/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=$signature\""
-H "\"x-amz-content-sha256: UNSIGNED-PAYLOAD\""
-H "\"x-amz-date: $current_date_time\""
-o "$OUTPUT_FILE")
-H "\"Authorization: AWS4-HMAC-SHA256 Credential=$aws_access_key_id/$year_month_day/$aws_region/s3/aws4_request,SignedHeaders=$param_list,Signature=$signature\"")
curl_command+=("${header_fields[@]}")
curl_command+=(-o "$OUTPUT_FILE")
# shellcheck disable=SC2154
eval "${curl_command[*]}" 2>&1
+8 -32
View File
@@ -29,45 +29,21 @@ checksum="$CHECKSUM"
current_date_time=$(date -u +"%Y%m%dT%H%M%SZ")
payload_hash="$(sha256sum "$data_file" | awk '{print $1}')"
checksum_hash="$(echo -n "$payload_hash" | xxd -r -p | base64)"
if [ "$CHECKSUM" == "true" ]; then
canonical_request="PUT
/$bucket_name/$key
host:$host
x-amz-checksum-sha256:$checksum_hash
x-amz-content-sha256:$payload_hash
x-amz-date:$current_date_time
host;x-amz-checksum-sha256;x-amz-content-sha256;x-amz-date
$payload_hash"
else
canonical_request="PUT
/$bucket_name/$key
host:$host
x-amz-content-sha256:$payload_hash
x-amz-date:$current_date_time
host;x-amz-content-sha256;x-amz-date
$payload_hash"
cr_data=("PUT" "/$bucket_name/$key" "" "host:$host")
if [ "$checksum" == "true" ]; then
checksum_hash="$(echo -n "$payload_hash" | xxd -r -p | base64)"
cr_data+=("x-amz-checksum-sha256:$checksum_hash")
fi
cr_data+=("x-amz-content-sha256:$payload_hash" "x-amz-date:$current_date_time")
build_canonical_request "${cr_data[@]}"
# shellcheck disable=SC2119
create_canonical_hash_sts_and_signature
curl_command+=(curl -ks -w "\"%{http_code}\"" -X PUT "$AWS_ENDPOINT_URL/$bucket_name/$key")
if [ "$CHECKSUM" == "true" ]; then
curl_command+=(-H "\"Authorization: AWS4-HMAC-SHA256 Credential=$aws_access_key_id/$year_month_day/$aws_region/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-checksum-sha256,Signature=$signature\"")
else
curl_command+=(-H "\"Authorization: AWS4-HMAC-SHA256 Credential=$aws_access_key_id/$year_month_day/$aws_region/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=$signature\"")
fi
curl_command+=(-H "\"x-amz-content-sha256: $payload_hash\""
-H "\"x-amz-date: $current_date_time\"")
if [ "$checksum" == "true" ]; then
curl_command+=(-H "\"x-amz-checksum-sha256: $checksum_hash\"")
fi
curl_command+=(-H "\"Authorization: AWS4-HMAC-SHA256 Credential=$aws_access_key_id/$year_month_day/$aws_region/s3/aws4_request,SignedHeaders=$param_list,Signature=$signature\"")
curl_command+=("${header_fields[@]}")
curl_command+=(-T "$data_file" -o "$OUTPUT_FILE")
# shellcheck disable=SC2154
eval "${curl_command[*]}" 2>&1
+29
View File
@@ -100,3 +100,32 @@ log_rest() {
echo "$2"
fi
}
build_canonical_request() {
if [ $# -lt 0 ]; then
log_rest 2 "'build_canonical_request' requires parameters"
return 1
fi
canonical_request=""
param_list=""
local payload=""
header_fields=()
for line in "$@"; do
canonical_request+="$line
"
if [[ "$line" == *":"* ]]; then
local key="${line%%:*}"
local value="${line#*:}"
if [ "$key" == "x-amz-content-sha256" ]; then
payload="$value"
fi
if [[ "$value" != "" ]]; then
param_list=$(add_parameter "$param_list" "$key" ";")
header_fields+=(-H "\"$key: $value\"")
fi
fi
done
canonical_request+="
$param_list
$payload"
}