mirror of
https://github.com/versity/versitygw.git
synced 2025-12-23 05:05:16 +00:00
test: convert more setup commands to REST, speed up github-actions
This commit is contained in:
10
.github/workflows/system.yml
vendored
10
.github/workflows/system.yml
vendored
@@ -21,9 +21,15 @@ jobs:
|
||||
RECREATE_BUCKETS: "true"
|
||||
DELETE_BUCKETS_AFTER_TEST: "true"
|
||||
BACKEND: "posix"
|
||||
- set: "REST, posix, non-static, all, folder IAM"
|
||||
- set: "REST, posix, non-static, base|acl, folder IAM"
|
||||
IAM_TYPE: folder
|
||||
RUN_SET: "rest"
|
||||
RUN_SET: "rest-base,rest-acl"
|
||||
RECREATE_BUCKETS: "true"
|
||||
DELETE_BUCKETS_AFTER_TEST: "true"
|
||||
BACKEND: "posix"
|
||||
- set: "REST, posix, non-static, chunked|checksum|versioning|bucket, folder IAM"
|
||||
IAM_TYPE: folder
|
||||
RUN_SET: "rest-chunked,rest-checksum,rest-versioning,rest-bucket"
|
||||
RECREATE_BUCKETS: "true"
|
||||
DELETE_BUCKETS_AFTER_TEST: "true"
|
||||
BACKEND: "posix"
|
||||
|
||||
@@ -46,12 +46,21 @@ delete_object() {
|
||||
}
|
||||
|
||||
delete_object_bypass_retention() {
|
||||
if ! check_param_count "delete_object_bypass_retention" "bucket, key, user, password" 4 $#; then
|
||||
if ! check_param_count "delete_object_bypass_retention" "client, bucket, key, user, password" 5 $#; then
|
||||
return 1
|
||||
fi
|
||||
if ! delete_object_error=$(AWS_ACCESS_KEY_ID="$3" AWS_SECRET_ACCESS_KEY="$4" send_command aws --no-verify-ssl s3api delete-object --bucket "$1" --key "$2" --bypass-governance-retention 2>&1); then
|
||||
log 2 "error deleting object with bypass retention: $delete_object_error"
|
||||
return 1
|
||||
if [ "$1" == "rest" ]; then
|
||||
if ! result=$(AWS_ACCESS_KEY_ID="$4" AWS_SECRET_ACCESS_KEY="$5" \
|
||||
COMMAND_LOG="$COMMAND_LOG" BUCKET_NAME="$2" OBJECT_KEY="$3" BYPASS_GOVERNANCE_RETENTION="true" \
|
||||
OUTPUT_FILE="$TEST_FILE_FOLDER/result.txt" ./tests/rest_scripts/delete_object.sh 2>&1); then
|
||||
log 2 "error deleting object: $result"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
if ! delete_object_error=$(AWS_ACCESS_KEY_ID="$4" AWS_SECRET_ACCESS_KEY="$5" send_command aws --no-verify-ssl s3api delete-object --bucket "$2" --key "$3" --bypass-governance-retention 2>&1); then
|
||||
log 2 "error deleting object with bypass retention: $delete_object_error"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -57,3 +57,19 @@ get_object_legal_hold_version_id() {
|
||||
echo "$legal_hold"
|
||||
return 0
|
||||
}
|
||||
|
||||
get_object_legal_hold_rest_version_id() {
|
||||
if ! check_param_count "get_object_legal_hold_rest_version_id" "bucket, key, version ID" 3 $#; then
|
||||
return 1
|
||||
fi
|
||||
if ! result=$(COMMAND_LOG="$COMMAND_LOG" BUCKET_NAME="$1" OBJECT_KEY="$2" VERSION_ID="$3" OUTPUT_FILE="$TEST_FILE_FOLDER/legal_hold.txt" ./tests/rest_scripts/get_object_legal_hold.sh); then
|
||||
log 2 "error getting object legal hold: $result"
|
||||
return 1
|
||||
fi
|
||||
if [ "$result" != "200" ]; then
|
||||
log 2 "get-object-legal-hold returned code $result: $(cat "$TEST_FILE_FOLDER/legal_hold.txt")"
|
||||
return 1
|
||||
fi
|
||||
legal_hold=$(cat "$TEST_FILE_FOLDER/legal_hold.txt")
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -30,47 +30,17 @@ get_object_retention() {
|
||||
}
|
||||
|
||||
get_object_retention_rest() {
|
||||
if [ $# -ne 2 ]; then
|
||||
log 2 "'get_object_tagging_rest' requires bucket, key"
|
||||
if ! check_param_count "get_object_retention_rest" "bucket, key" 2 $#; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
generate_hash_for_payload ""
|
||||
|
||||
current_date_time=$(date -u +"%Y%m%dT%H%M%SZ")
|
||||
aws_endpoint_url_address=${AWS_ENDPOINT_URL#*//}
|
||||
header=$(echo "$AWS_ENDPOINT_URL" | awk -F: '{print $1}')
|
||||
# shellcheck disable=SC2154
|
||||
canonical_request="GET
|
||||
/$1/$2
|
||||
retention=
|
||||
host:$aws_endpoint_url_address
|
||||
x-amz-content-sha256:$payload_hash
|
||||
x-amz-date:$current_date_time
|
||||
|
||||
host;x-amz-content-sha256;x-amz-date
|
||||
$payload_hash"
|
||||
|
||||
if ! generate_sts_string "$current_date_time" "$canonical_request"; then
|
||||
log 2 "error generating sts string"
|
||||
if ! result=$(COMMAND_LOG=$COMMAND_LOG BUCKET_NAME=$1 OBJECT_KEY="$2" OUTPUT_FILE="$TEST_FILE_FOLDER/retention.txt" ./tests/rest_scripts/get_object_retention.sh); then
|
||||
log 2 "error getting object retention: $result"
|
||||
return 1
|
||||
fi
|
||||
get_signature
|
||||
# shellcheck disable=SC2154
|
||||
reply=$(send_command curl -ks -w "%{http_code}" "$header://$aws_endpoint_url_address/$1/$2?retention" \
|
||||
-H "Authorization: AWS4-HMAC-SHA256 Credential=$AWS_ACCESS_KEY_ID/$ymd/$AWS_REGION/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=$signature" \
|
||||
-H "x-amz-content-sha256: $payload_hash" \
|
||||
-H "x-amz-date: $current_date_time" \
|
||||
-o "$TEST_FILE_FOLDER"/object_retention.txt 2>&1)
|
||||
log 5 "reply status code: $reply"
|
||||
if [[ "$reply" != "200" ]]; then
|
||||
if [ "$reply" == "404" ]; then
|
||||
return 1
|
||||
fi
|
||||
log 2 "reply error: $reply"
|
||||
log 2 "get object retention command returned error: $(cat "$TEST_FILE_FOLDER"/object_retention.txt)"
|
||||
return 2
|
||||
if [ "$result" != "200" ]; then
|
||||
get_object_retention_error="$(cat "$TEST_FILE_FOLDER/retention.txt")"
|
||||
log 2 "GetObjectRetention returned code $result ($get_object_retention_error)"
|
||||
return 1
|
||||
fi
|
||||
log 5 "object tags: $(cat "$TEST_FILE_FOLDER"/object_retention.txt)"
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -16,11 +16,15 @@
|
||||
|
||||
list_object_versions() {
|
||||
record_command "list-object-versions" "client:s3api"
|
||||
if [[ $# -ne 1 ]]; then
|
||||
log 2 "'list object versions' command requires bucket name"
|
||||
if ! check_param_count "list_object_versions" "client, bucket name" 2 $#; then
|
||||
return 1
|
||||
fi
|
||||
versions=$(send_command aws --no-verify-ssl s3api list-object-versions --bucket "$1" 2>&1) || local list_result=$?
|
||||
local list_result=0
|
||||
if [ "$1" == "rest" ]; then
|
||||
list_object_versions_rest "$2" || list_result=$?
|
||||
else
|
||||
versions=$(send_command aws --no-verify-ssl s3api list-object-versions --bucket "$2" 2>&1) || list_result=$?
|
||||
fi
|
||||
if [[ $list_result -ne 0 ]]; then
|
||||
log 2 "error listing object versions: $versions"
|
||||
return 1
|
||||
@@ -34,10 +38,14 @@ list_object_versions_rest() {
|
||||
log 2 "'list_object_versions_rest' requires bucket name"
|
||||
return 1
|
||||
fi
|
||||
log 5 "list object versions REST"
|
||||
if ! result=$(BUCKET_NAME="$1" OUTPUT_FILE="$TEST_FILE_FOLDER/object_versions.txt" ./tests/rest_scripts/list_object_versions.sh); then
|
||||
if ! result=$(BUCKET_NAME="$1" OUTPUT_FILE="$TEST_FILE_FOLDER/object_versions.txt" ./tests/rest_scripts/list_object_versions.sh 2>&1); then
|
||||
log 2 "error listing object versions: $result"
|
||||
return 1
|
||||
fi
|
||||
if [ "$result" != "200" ]; then
|
||||
log 2 "expected '200', was '$result' ($(cat "$TEST_FILE_FOLDER/object_versions.txt"))"
|
||||
return 1
|
||||
fi
|
||||
versions=$(cat "$TEST_FILE_FOLDER/object_versions.txt")
|
||||
return 0
|
||||
}
|
||||
@@ -22,11 +22,16 @@ source ./tests/rest_scripts/rest.sh
|
||||
bucket_name="$BUCKET_NAME"
|
||||
# shellcheck disable=SC2154
|
||||
key=$(echo -n "$OBJECT_KEY" | jq -sRr 'split("/") | map(@uri) | join("/")')
|
||||
# shellcheck disable=SC2154
|
||||
bypass_governance_retention=${BYPASS_GOVERNANCE_RETENTION:=false}
|
||||
|
||||
current_date_time=$(date -u +"%Y%m%dT%H%M%SZ")
|
||||
|
||||
#x-amz-object-attributes:ETag
|
||||
canonical_request_data+=("DELETE" "/$bucket_name/$key" "" "host:$host")
|
||||
if [ "$bypass_governance_retention" == "true" ]; then
|
||||
canonical_request_data+=("x-amz-bypass-governance-retention:true")
|
||||
fi
|
||||
canonical_request_data+=("x-amz-content-sha256:UNSIGNED-PAYLOAD" "x-amz-date:$current_date_time")
|
||||
|
||||
build_canonical_request "${canonical_request_data[@]}"
|
||||
|
||||
@@ -22,26 +22,31 @@ source ./tests/rest_scripts/rest.sh
|
||||
bucket_name="$BUCKET_NAME"
|
||||
# shellcheck disable=SC2154
|
||||
key="$OBJECT_KEY"
|
||||
# shellcheck disable=SC2153,SC2154
|
||||
version_id="$VERSION_ID"
|
||||
|
||||
current_date_time=$(date -u +"%Y%m%dT%H%M%SZ")
|
||||
|
||||
canonical_request="GET
|
||||
/$bucket_name/$key
|
||||
legal-hold=
|
||||
host:$host
|
||||
x-amz-content-sha256:UNSIGNED-PAYLOAD
|
||||
x-amz-date:$current_date_time
|
||||
|
||||
host;x-amz-content-sha256;x-amz-date
|
||||
UNSIGNED-PAYLOAD"
|
||||
canonical_request_data=("GET" "/$bucket_name/$key")
|
||||
queries=""
|
||||
if [ "$VERSION_ID" != "" ]; then
|
||||
queries=$(add_parameter "$queries" "versionId=$version_id")
|
||||
fi
|
||||
queries=$(add_parameter "$queries" "legal-hold=")
|
||||
canonical_request_data+=("$queries" "host:$host")
|
||||
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
|
||||
echo -n "$canonical_request" > "cr.txt"
|
||||
|
||||
# shellcheck disable=SC2119
|
||||
create_canonical_hash_sts_and_signature
|
||||
|
||||
curl_command+=(curl -ks -w "\"%{http_code}\"" "$AWS_ENDPOINT_URL/$bucket_name/$key?legal-hold="
|
||||
-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")
|
||||
curl_command+=(curl -ks -w "\"%{http_code}\"" "\"$AWS_ENDPOINT_URL/$bucket_name/$key?$queries\""
|
||||
-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
|
||||
40
tests/rest_scripts/get_object_retention.sh
Executable file
40
tests/rest_scripts/get_object_retention.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2024 Versity Software
|
||||
# This file is licensed under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http:#www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
# Fields
|
||||
|
||||
source ./tests/rest_scripts/rest.sh
|
||||
|
||||
# shellcheck disable=SC2153
|
||||
bucket_name="$BUCKET_NAME"
|
||||
|
||||
current_date_time=$(date -u +"%Y%m%dT%H%M%SZ")
|
||||
canonical_request_data=("GET" "/$bucket_name" "retention=" "host:$host")
|
||||
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
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
curl_command+=(curl -ks -w "\"%{http_code}\"" "$AWS_ENDPOINT_URL/$bucket_name?retention")
|
||||
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+=(-o "$OUTPUT_FILE")
|
||||
eval "${curl_command[*]}" 2>&1
|
||||
32
tests/run.sh
32
tests/run.sh
@@ -34,6 +34,12 @@ show_help() {
|
||||
echo " mc-non-file-count Run non-file count tests with mc utility"
|
||||
echo " mc-file-count Run file count test with mc utility"
|
||||
echo " rest Run tests with rest cli"
|
||||
echo " rest-base Run REST base tasks"
|
||||
echo " rest-acl Run REST ACL tests"
|
||||
echo " rest-chunked Run REST chunked upload tests"
|
||||
echo " rest-checksum Run REST checksum tests"
|
||||
echo " rest-versioning Run REST versioning tests"
|
||||
echo " rest-bucket Run REST bucket tests"
|
||||
}
|
||||
|
||||
handle_param() {
|
||||
@@ -42,7 +48,7 @@ handle_param() {
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
s3|s3-file-count|s3-non-file-count|s3api|s3cmd|s3cmd-user|s3cmd-non-user|s3cmd-file-count|mc|mc-non-file-count|mc-file-count|s3api-user|rest|s3api-policy|s3api-bucket|s3api-object|s3api-multipart)
|
||||
s3|s3-file-count|s3-non-file-count|s3api|s3cmd|s3cmd-user|s3cmd-non-user|s3cmd-file-count|mc|mc-non-file-count|mc-file-count|s3api-user|rest|s3api-policy|s3api-bucket|s3api-object|s3api-multipart|rest-base|rest-acl|rest-chunked|rest-checksum|rest-versioning|rest-bucket)
|
||||
run_suite "$1"
|
||||
;;
|
||||
*) # Handle unrecognized options or positional arguments
|
||||
@@ -155,6 +161,30 @@ run_suite() {
|
||||
exit_code=1
|
||||
fi
|
||||
;;
|
||||
rest-base)
|
||||
echo "Running REST base tests ..."
|
||||
"$HOME"/bin/bats ./tests/test_rest.sh || exit_code=$?
|
||||
;;
|
||||
rest-acl)
|
||||
echo "Running REST ACL tests ..."
|
||||
"$HOME"/bin/bats ./tests/test_rest_acl.sh || exit_code=$?
|
||||
;;
|
||||
rest-chunked)
|
||||
echo "Running REST chunked upload tests ..."
|
||||
"$HOME"/bin/bats ./tests/test_rest_chunked.sh || exit_code=$?
|
||||
;;
|
||||
rest-checksum)
|
||||
echo "Running REST checksum tests ..."
|
||||
"$HOME"/bin/bats ./tests/test_rest_checksum.sh || exit_code=$?
|
||||
;;
|
||||
rest-versioning)
|
||||
echo "Running REST versioning tests ..."
|
||||
"$HOME"/bin/bats ./tests/test_rest_versioning.sh || exit_code=$?
|
||||
;;
|
||||
rest-bucket)
|
||||
echo "Running REST bucket tests ..."
|
||||
"$HOME"/bin/bats ./tests/test_rest_bucket.sh || exit_code=$?
|
||||
;;
|
||||
s3api-user)
|
||||
echo "Running s3api user tests ..."
|
||||
"$HOME"/bin/bats ./tests/test_user_aws.sh || exit_code=$?
|
||||
|
||||
@@ -277,7 +277,7 @@ export RUN_USERS=true
|
||||
run put_object "s3api" "$TEST_FILE_FOLDER/$test_file" "$BUCKET_ONE_NAME" "$test_file"
|
||||
assert_success
|
||||
|
||||
run delete_object_bypass_retention "$BUCKET_ONE_NAME" "$test_file" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY"
|
||||
run delete_object_bypass_retention "s3api" "$BUCKET_ONE_NAME" "$test_file" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY"
|
||||
assert_failure
|
||||
assert_output -p "InvalidArgument"
|
||||
assert_output -p "x-amz-bypass-governance-retention is only applicable"
|
||||
|
||||
@@ -208,7 +208,7 @@ test_retention_bypass_s3api_root() {
|
||||
run put_bucket_policy "s3api" "$BUCKET_ONE_NAME" "$TEST_FILE_FOLDER/$policy_file"
|
||||
assert_success
|
||||
|
||||
run delete_object_bypass_retention "$BUCKET_ONE_NAME" "$bucket_file" "$username" "$secret_key"
|
||||
run delete_object_bypass_retention "s3api" "$BUCKET_ONE_NAME" "$bucket_file" "$username" "$secret_key"
|
||||
assert_success
|
||||
}
|
||||
|
||||
|
||||
@@ -162,21 +162,6 @@ bucket_cleanup() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
#if ! delete_bucket_policy "s3api" "$1"; then
|
||||
# log 2 "error deleting bucket policy"
|
||||
# return 1
|
||||
#fi
|
||||
|
||||
#if ! get_object_ownership_rule_and_update_acl "$1"; then
|
||||
# log 2 "error getting object ownership rule and updating ACL"
|
||||
# return 1
|
||||
#fi
|
||||
|
||||
#if [ "$RUN_USERS" == "true" ] && ! reset_bucket_owner "$1"; then
|
||||
# log 2 "error resetting bucket owner"
|
||||
# return 1
|
||||
#fi
|
||||
|
||||
log 5 "bucket contents, policy, ACL deletion success"
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
# under the License.
|
||||
|
||||
get_and_check_legal_hold() {
|
||||
if [ $# -ne 4 ]; then
|
||||
log 2 "'get_and_check_legal_hold' requires client, bucket, key, expected status"
|
||||
if ! check_param_count "get_and_check_legal_hold" "client, bucket, key, expected status" 4 $#; then
|
||||
return 1
|
||||
fi
|
||||
if ! head_object "$1" "$2" "$3"; then
|
||||
@@ -38,8 +37,7 @@ get_and_check_legal_hold() {
|
||||
}
|
||||
|
||||
check_legal_hold_without_lock_enabled() {
|
||||
if [ $# -ne 2 ]; then
|
||||
log 2 "'check_legal_hold_without_lock_enabled' requires bucket, key names"
|
||||
if ! check_param_count "check_legal_hold_without_lock_enabled" "bucket, key" 2 $#; then
|
||||
return 1
|
||||
fi
|
||||
if get_object_legal_hold_rest "$1" "$2"; then
|
||||
@@ -59,11 +57,11 @@ check_legal_hold_without_lock_enabled() {
|
||||
}
|
||||
|
||||
check_remove_legal_hold_versions() {
|
||||
if [ $# -ne 3 ]; then
|
||||
log 2 "'check_remove_legal_hold_versions' requires bucket, key, version ID"
|
||||
if ! check_param_count "check_remove_legal_hold_versions" "bucket, key, version ID" 3 $#; then
|
||||
return 1
|
||||
fi
|
||||
if ! legal_hold=$(get_object_legal_hold_version_id "$1" "$2" "$3"); then
|
||||
if ! get_object_legal_hold_rest_version_id "$1" "$2" "$3"; then
|
||||
# shellcheck disable=SC2154
|
||||
if [[ "$legal_hold" != *"MethodNotAllowed"* ]]; then
|
||||
log 2 "error getting object legal hold status with version id"
|
||||
return 1
|
||||
@@ -71,10 +69,14 @@ check_remove_legal_hold_versions() {
|
||||
return 0
|
||||
fi
|
||||
log 5 "legal hold: $legal_hold"
|
||||
if ! status="$(echo "$legal_hold" | grep -v "InsecureRequestWarning" | jq -r '.LegalHold.Status' 2>&1)"; then
|
||||
log 2 "error getting legal hold status: $status"
|
||||
if ! status=$(get_element_text <(echo -n "$legal_hold") "LegalHold" "Status"); then
|
||||
log 2 "error getting XML legal hold status"
|
||||
return 1
|
||||
fi
|
||||
#if ! status="$(echo "$legal_hold" | grep -v "InsecureRequestWarning" | jq -r '.LegalHold.Status' 2>&1)"; then
|
||||
# log 2 "error getting legal hold status: $status"
|
||||
# return 1
|
||||
#fi
|
||||
if [ "$status" == "ON" ]; then
|
||||
if ! put_object_legal_hold_version_id "$1" "$2" "$3" "OFF"; then
|
||||
log 2 "error removing legal hold of version ID"
|
||||
@@ -85,8 +87,7 @@ check_remove_legal_hold_versions() {
|
||||
}
|
||||
|
||||
check_legal_hold_without_payload() {
|
||||
if [ $# -ne 2 ]; then
|
||||
log 2 "'check_legal_hold_without_payload' requires bucket name, key"
|
||||
if ! check_param_count "check_legal_hold_without_payload" "bucket, key" 2 $#; then
|
||||
return 1
|
||||
fi
|
||||
if ! result=$(COMMAND_LOG="$COMMAND_LOG" BUCKET_NAME="$1" OBJECT_KEY="$2" OMIT_PAYLOAD="true" OUTPUT_FILE="$TEST_FILE_FOLDER/result.txt" ./tests/rest_scripts/put_object_legal_hold.sh); then
|
||||
@@ -105,8 +106,7 @@ check_legal_hold_without_payload() {
|
||||
}
|
||||
|
||||
rest_check_legal_hold() {
|
||||
if [ $# -ne 2 ]; then
|
||||
log 2 "'rest_check_legal_hold' requires bucket name, key"
|
||||
if ! check_param_count "rest_check_legal_hold" "bucket, key" 2 $#; then
|
||||
return 1
|
||||
fi
|
||||
if ! result=$(COMMAND_LOG="$COMMAND_LOG" BUCKET_NAME="$1" OBJECT_KEY="$2" STATUS="ON" OUTPUT_FILE="$TEST_FILE_FOLDER/result.txt" ./tests/rest_scripts/put_object_legal_hold.sh); then
|
||||
|
||||
@@ -20,6 +20,7 @@ get_and_check_object_lock_config() {
|
||||
if ! check_param_count "get_and_check_object_lock_config" "bucket, expected enabled value, expected governance mode, expected days" 4 $#; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! get_object_lock_configuration "s3api" "$1"; then
|
||||
log 2 "error getting object lock config"
|
||||
return 1
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
source ./tests/drivers/drivers.sh
|
||||
|
||||
# params: bucket name
|
||||
# return 0 for success, 1 for error
|
||||
add_governance_bypass_policy() {
|
||||
@@ -59,11 +61,7 @@ check_for_and_remove_worm_protection() {
|
||||
if [[ $LOG_LEVEL_INT -ge 5 ]]; then
|
||||
log_worm_protection "$1" "$2"
|
||||
fi
|
||||
if ! add_governance_bypass_policy "$1"; then
|
||||
log 2 "error adding new governance bypass policy"
|
||||
return 2
|
||||
fi
|
||||
if ! delete_object_bypass_retention "$1" "$2" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY"; then
|
||||
if ! delete_object_bypass_retention "rest" "$1" "$2" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY"; then
|
||||
log 2 "error deleting object after legal hold removal"
|
||||
return 2
|
||||
fi
|
||||
@@ -80,13 +78,13 @@ log_worm_protection() {
|
||||
if ! check_param_count "log_worm_protection" "bucket, key" 2 $#; then
|
||||
return 1
|
||||
fi
|
||||
if ! get_object_legal_hold "$1" "$2"; then
|
||||
if ! get_object_legal_hold_rest "$1" "$2"; then
|
||||
log 2 "error getting object legal hold status"
|
||||
return
|
||||
fi
|
||||
# shellcheck disable=SC2154
|
||||
log 5 "LEGAL HOLD: $legal_hold"
|
||||
if ! get_object_retention "$1" "$2"; then
|
||||
if ! get_object_retention_rest "$1" "$2"; then
|
||||
log 2 "error getting object retention"
|
||||
# shellcheck disable=SC2154
|
||||
if [[ $get_object_retention_error != *"NoSuchObjectLockConfiguration"* ]]; then
|
||||
|
||||
@@ -4,8 +4,7 @@ source ./tests/commands/get_bucket_versioning.sh
|
||||
source ./tests/commands/list_object_versions.sh
|
||||
|
||||
check_if_versioning_enabled() {
|
||||
if [ $# -ne 1 ]; then
|
||||
log 2 "'check_if_versioning_enabled' requires bucket name"
|
||||
if ! check_param_count "check_if_versioning_enabled" "bucket" 1 $#; then
|
||||
return 2
|
||||
fi
|
||||
if ! get_bucket_versioning 's3api' "$1"; then
|
||||
@@ -24,11 +23,10 @@ check_if_versioning_enabled() {
|
||||
}
|
||||
|
||||
delete_old_versions() {
|
||||
if [ $# -ne 1 ]; then
|
||||
log 2 "'delete_old_versions' requires bucket name"
|
||||
if ! check_param_count "delete_old_versions" "bucket" 1 $#; then
|
||||
return 1
|
||||
fi
|
||||
if ! list_object_versions "$1"; then
|
||||
if ! list_object_versions "rest" "$1"; then
|
||||
log 2 "error listing object versions"
|
||||
return 1
|
||||
fi
|
||||
@@ -37,12 +35,8 @@ delete_old_versions() {
|
||||
version_keys=()
|
||||
version_ids=()
|
||||
|
||||
if ! parse_version_data "$versions" '.Versions[]'; then
|
||||
log 2 "error parsing Versions elements"
|
||||
return 1
|
||||
fi
|
||||
if ! parse_version_data "$versions" '.DeleteMarkers[]'; then
|
||||
log 2 "error getting DeleteMarkers elements"
|
||||
if ! parse_version_data_by_type "rest" "$2"; then
|
||||
log 2 "error parsing version data"
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -57,8 +51,7 @@ delete_old_versions() {
|
||||
}
|
||||
|
||||
delete_object_version_with_or_without_retention() {
|
||||
if [ $# -ne 1 ]; then
|
||||
log 2 "'delete_object_version_with_or_without_retention' requires bucket name"
|
||||
if ! check_param_count "delete_object_version_with_or_without_retention" "bucket" 1 $#; then
|
||||
return 1
|
||||
fi
|
||||
log 5 "idx: $idx"
|
||||
@@ -84,9 +77,30 @@ delete_object_version_with_or_without_retention() {
|
||||
return 0
|
||||
}
|
||||
|
||||
parse_version_data_by_type() {
|
||||
if ! check_param_count "parse_version_data_by_type" "client, data" 2 $#; then
|
||||
return 1
|
||||
fi
|
||||
if [ "$1" == "rest" ]; then
|
||||
log 5 "version data: $versions"
|
||||
if ! parse_versions_rest "$versions"; then
|
||||
log 2 "error parsing REST object versions"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
if ! parse_version_data "$versions" '.Versions[]'; then
|
||||
log 2 "error parsing Versions elements"
|
||||
return 1
|
||||
fi
|
||||
if ! parse_version_data "$versions" '.DeleteMarkers[]'; then
|
||||
log 2 "error getting DeleteMarkers elements"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
parse_version_data() {
|
||||
if [ $# -ne 2 ]; then
|
||||
log 2 "'parse_version_data' requires raw data, element name"
|
||||
if ! check_param_count "parse_version_data" "raw data, element name" 2 $#; then
|
||||
return 1
|
||||
fi
|
||||
if ! version_data="$(echo "$1" | jq -c "$2" 2>&1)"; then
|
||||
@@ -111,8 +125,7 @@ parse_version_data() {
|
||||
}
|
||||
|
||||
check_versioning_status_rest() {
|
||||
if [ $# -ne 2 ]; then
|
||||
log 2 "'check_versioning_status_rest' requires bucket, expected value"
|
||||
if ! check_param_count "check_versioning_status_rest" "bucket, expected value" 2 $#; then
|
||||
return 1
|
||||
fi
|
||||
if ! get_bucket_versioning_rest "$BUCKET_ONE_NAME"; then
|
||||
@@ -142,9 +155,56 @@ check_versioning_status_rest() {
|
||||
return 0
|
||||
}
|
||||
|
||||
echo_versions() {
|
||||
if ! check_param_count "echo_versions" "'Version' or 'DeleteMarker', 'Key' or 'VersionId'" 2 $#; then
|
||||
return 1
|
||||
fi
|
||||
if ! keys=$(echo -n "$versions" | xmllint --xpath "//*[local-name()=\"$1\"]/*[local-name()=\"$2\"]/text()" - | xmlstarlet unesc 2>&1); then
|
||||
if [[ "$keys" == *"XPath set is empty"* ]]; then
|
||||
return 0
|
||||
fi
|
||||
log 2 "error getting Version 'Key' values: $keys"
|
||||
return 1
|
||||
fi
|
||||
log 5 "keys to append: ${keys[*]}"
|
||||
echo "${keys[*]}"
|
||||
}
|
||||
|
||||
parse_versions_rest() {
|
||||
if ! check_param_count "parse_versions_rest" "versions variable" 1 $#; then
|
||||
return 1
|
||||
fi
|
||||
if ! keys=$(echo_versions "Version" "Key"); then
|
||||
log 2 "error getting Version Key values: $keys"
|
||||
return 1
|
||||
fi
|
||||
# shellcheck disable=SC2206
|
||||
version_keys+=($keys)
|
||||
if ! ids=$(echo_versions "Version" "VersionId"); then
|
||||
log 2 "error getting Version VersionId values: $ids"
|
||||
return 1
|
||||
fi
|
||||
# shellcheck disable=SC2206
|
||||
version_ids+=($ids)
|
||||
if ! keys=$(echo_versions "DeleteMarker" "Key"); then
|
||||
log 2 "error getting DeleteMarker Key values: $keys"
|
||||
return 1
|
||||
fi
|
||||
# shellcheck disable=SC2206
|
||||
version_keys+=($keys)
|
||||
if ! ids=$(echo_versions "DeleteMarker" "VersionId"); then
|
||||
log 2 "error getting DeleteMarker VersionId values: $ids"
|
||||
return 1
|
||||
fi
|
||||
# shellcheck disable=SC2206
|
||||
version_ids+=($ids)
|
||||
log 5 "version keys: ${version_keys[*]}"
|
||||
log 5 "version IDs: ${version_ids[*]}"
|
||||
return 0
|
||||
}
|
||||
|
||||
get_and_check_versions_rest() {
|
||||
if [ $# -lt 5 ]; then
|
||||
log 2 "'get_and_check_versionid_null_rest' requires bucket, key, count, expected islatest, expected id equal to null"
|
||||
if ! check_param_count_gt "get_and_check_versions_rest" "bucket, key, count, expected islatest, expected id equal to null" 5 $#; then
|
||||
return 1
|
||||
fi
|
||||
if ! list_object_versions_rest "$1"; then
|
||||
@@ -178,8 +238,7 @@ get_and_check_versions_rest() {
|
||||
}
|
||||
|
||||
check_versions_after_file_deletion() {
|
||||
if [ $# -ne 2 ]; then
|
||||
log 2 "'check_versions_after_file_deletion' requires bucket, key"
|
||||
if ! check_param_count "check_versions_after_file_deletion" "bucket, key" 2 $#; then
|
||||
return 1
|
||||
fi
|
||||
if ! list_object_versions_rest "$1"; then
|
||||
|
||||
Reference in New Issue
Block a user