mirror of
https://github.com/versity/versitygw.git
synced 2026-01-08 20:43:07 +00:00
test: chunked upload - more tests, final signature test
This commit is contained in:
@@ -54,4 +54,79 @@ attempt_chunked_upload_with_bad_first_signature() {
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
chunked_upload_success() {
|
||||
if [ $# -ne 3 ]; then
|
||||
log 2 "'chunked_upload_success_as' requires data file, bucket name, key"
|
||||
return 1
|
||||
fi
|
||||
if ! result=$(COMMAND_LOG="$COMMAND_LOG" \
|
||||
AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID" \
|
||||
AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY" \
|
||||
AWS_ENDPOINT_URL="$AWS_ENDPOINT_URL" \
|
||||
DATA_FILE="$1" \
|
||||
BUCKET_NAME="$2" \
|
||||
OBJECT_KEY="$3" CHUNK_SIZE=8192 TEST_MODE=false COMMAND_FILE="$TEST_FILE_FOLDER/command.txt" ./tests/rest_scripts/put_object_openssl_chunked_example.sh 2>&1); then
|
||||
log 2 "error creating command: $result"
|
||||
return 1
|
||||
fi
|
||||
|
||||
host="${AWS_ENDPOINT_URL#http*://}"
|
||||
if [ "$host" == "s3.amazonaws.com" ]; then
|
||||
host+=":443"
|
||||
fi
|
||||
if ! result=$(openssl s_client -connect "$host" -ign_eof < "$TEST_FILE_FOLDER/command.txt" 2>&1); then
|
||||
log 2 "error sending openssl command: $result"
|
||||
return 1
|
||||
fi
|
||||
response_code="$(echo "$result" | grep "HTTP" | awk '{print $2}')"
|
||||
if [ "$response_code" != "200" ]; then
|
||||
log 2 "expected response '200', was '$response_code'"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
attempt_chunked_upload_with_bad_final_signature() {
|
||||
if [ $# -ne 3 ]; then
|
||||
log 2 "'attempt_chunked_upload_with_bad_first_signature' requires data file, bucket name, key"
|
||||
return 1
|
||||
fi
|
||||
if ! result=$(COMMAND_LOG="$COMMAND_LOG" \
|
||||
AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID" \
|
||||
AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY" \
|
||||
AWS_ENDPOINT_URL="$AWS_ENDPOINT_URL" \
|
||||
DATA_FILE="$1" \
|
||||
BUCKET_NAME="$2" \
|
||||
OBJECT_KEY="$3" \
|
||||
CHUNK_SIZE=8192 \
|
||||
TEST_MODE=false \
|
||||
COMMAND_FILE="$TEST_FILE_FOLDER/command.txt" \
|
||||
FINAL_SIGNATURE="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ./tests/rest_scripts/put_object_openssl_chunked_example.sh 2>&1); then
|
||||
log 2 "error creating command: $result"
|
||||
return 1
|
||||
fi
|
||||
host="${AWS_ENDPOINT_URL#http*://}"
|
||||
if [ "$host" == "s3.amazonaws.com" ]; then
|
||||
host+=":443"
|
||||
fi
|
||||
if ! result=$(openssl s_client -connect "$host" -ign_eof < "$TEST_FILE_FOLDER/command.txt" 2>&1); then
|
||||
log 2 "error sending openssl command: $result"
|
||||
return 1
|
||||
fi
|
||||
response_code="$(echo "$result" | grep "HTTP" | awk '{print $2}')"
|
||||
log 5 "response code: $response_code"
|
||||
if [ "$response_code" != "403" ]; then
|
||||
log 2 "expected code '403', was '$response_code'"
|
||||
return 1
|
||||
fi
|
||||
response_data="$(echo "$result" | grep "<")"
|
||||
log 5 "response data: $response_data"
|
||||
log 5 "END"
|
||||
if ! check_xml_element <(echo "$response_data") "SignatureDoesNotMatch" "Error" "Code"; then
|
||||
log 2 "error checking XML element"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -65,6 +65,28 @@ create_test_file() {
|
||||
return 0
|
||||
}
|
||||
|
||||
create_file_single_char() {
|
||||
if [ "$#" -ne 3 ]; then
|
||||
log 2 "'create_file_single_char' requires filename, size, char"
|
||||
return 1
|
||||
fi
|
||||
if [[ -e "$TEST_FILE_FOLDER/$1" ]]; then
|
||||
if ! error=$(rm "$TEST_FILE_FOLDER/$1" 2>&1); then
|
||||
log 2 "error removing existing file: $error"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
if ! error=$(touch "$TEST_FILE_FOLDER/$1" 2>&1); then
|
||||
log 2 "error creating new file: $error"
|
||||
return 1
|
||||
fi
|
||||
if ! error=$(dd if=/dev/zero bs=1 count="$2" | tr '\0' "$3" > "$TEST_FILE_FOLDER/$1" 2>&1); then
|
||||
log 2 "error adding data to file: $error"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# params: folder name
|
||||
# fail if error
|
||||
create_test_folder() {
|
||||
|
||||
@@ -260,16 +260,12 @@ get_and_check_no_policy_error() {
|
||||
log 2 "'get_and_check_no_policy_error' requires bucket name"
|
||||
return 1
|
||||
fi
|
||||
if ! result=$(COMMAND_LOG="$COMMAND_LOG" BUCKET_NAME="$1" OUTPUT_FILE="$TEST_FILE_FOLDER/response.txt" ./tests/rest_scripts/get_bucket_policy.sh); then
|
||||
log 2 "error attempting to get bucket policy response: $result"
|
||||
if ! get_bucket_policy_rest_expect_code "$1" "404"; then
|
||||
log 2 "GetBucketPolicy returned unexpected response code"
|
||||
return 1
|
||||
fi
|
||||
if [ "$result" != "404" ]; then
|
||||
log 2 "GetBucketOwnershipControls returned unexpected response code: $result, reply: $(cat "$TEST_FILE_FOLDER/response.txt")"
|
||||
return 1
|
||||
fi
|
||||
log 5 "response: $(cat "$TEST_FILE_FOLDER/response.txt")"
|
||||
if ! bucket_name=$(xmllint --xpath '//*[local-name()="BucketName"]/text()' "$TEST_FILE_FOLDER/response.txt" 2>&1); then
|
||||
log 5 "response: $bucket_policy"
|
||||
if ! bucket_name=$(xmllint --xpath '//*[local-name()="BucketName"]/text()' <(echo -n "$bucket_policy") 2>&1); then
|
||||
log 2 "error getting bucket name: $bucket_name"
|
||||
return 1
|
||||
fi
|
||||
@@ -314,21 +310,16 @@ put_and_check_policy_rest() {
|
||||
log 2 "unexpected response code, expected '200' or '204', actual '$result' (reply: $(cat "$TEST_FILE_FOLDER/result.txt"))"
|
||||
return 1
|
||||
fi
|
||||
if ! result=$(COMMAND_LOG="$COMMAND_LOG" BUCKET_NAME="$1" OUTPUT_FILE="$TEST_FILE_FOLDER/policy.txt" ./tests/rest_scripts/get_bucket_policy.sh); then
|
||||
if ! get_bucket_policy_rest "$1"; then
|
||||
log 2 "error attempting to get bucket policy response: $result"
|
||||
return 1
|
||||
fi
|
||||
if [ "$result" != "200" ]; then
|
||||
log 2 "unexpected response code, expected '200', actual '$result' (reply: $(cat "$TEST_FILE_FOLDER/policy.txt"))"
|
||||
return 1
|
||||
fi
|
||||
log 5 "policy: $(cat "$TEST_FILE_FOLDER/policy.txt")"
|
||||
if [ "$DIRECT" == "true" ]; then
|
||||
principal="arn:aws:iam::$DIRECT_AWS_USER_ID:user/$4"
|
||||
else
|
||||
principal="$4"
|
||||
fi
|
||||
if ! check_policy "$(cat "$TEST_FILE_FOLDER/policy.txt")" "$3" "$principal" "$5" "$6"; then
|
||||
if ! check_policy "$bucket_policy" "$3" "$principal" "$5" "$6"; then
|
||||
log 2 "policies not equal"
|
||||
return 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user