test: util code cleanup

This commit is contained in:
Luke McCrone
2026-05-08 18:27:59 -03:00
parent fe3cfbfce9
commit 37d6ca03ed
14 changed files with 87 additions and 72 deletions

View File

@@ -17,7 +17,7 @@
source ./tests/commands/list_objects_v2.sh
source ./tests/drivers/list_object_versions/list_object_versions_rest.sh
source ./tests/drivers/xml.sh
source ./tests/util/util_legal_hold.sh
source ./tests/drivers/get_object_legal_hold/get_object_legal_hold_rest.sh
list_and_delete_objects() {
log 6 "list_and_delete_objects: '$1'"

View File

@@ -101,3 +101,22 @@ get_check_acl_after_second_put() {
fi
return 0
}
get_bucket_acl_and_check_owner() {
if ! check_param_count_v2 "client, bucket name" 2 $#; then
return 1
fi
if ! get_bucket_acl "$1" "$2"; then
log 2 "error getting bucket acl"
return 1
fi
# shellcheck disable=SC2154
log 5 "ACL: $acl"
id=$(echo "$acl" | jq -r '.Owner.ID')
if [[ "$id" != "$AWS_ACCESS_KEY_ID" ]]; then
log 2 "Acl mismatch"
return 1
fi
return 0
}

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Copyright 2024 Versity Software
# Copyright 2026 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

View File

@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# Copyright 2026 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.
get_and_check_legal_hold() {
if ! check_param_count_v2 "client, bucket, key, expected status" 4 $#; then
return 1
fi
if ! head_object "$1" "$2" "$3"; then
log 2 "error getting object metadata"
return 1
fi
# shellcheck disable=SC2154
raw_metadata=$(echo "$metadata" | grep -v "InsecureRequestWarning")
log 5 "raw metadata: $raw_metadata"
if ! hold_status=$(echo "$raw_metadata" | jq -r ".ObjectLockLegalHoldStatus // empty" 2>&1); then
log 2 "error retrieving hold status: $hold_status"
return 1
fi
modified_hold_status="${hold_status:-OFF}"
if [[ "$modified_hold_status" != "$4" ]]; then
log 2 "hold status mismatch (expected '$4', actual '$modified_hold_status')"
return 1
fi
return 0
}

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Copyright 2024 Versity Software
# Copyright 2026 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
@@ -14,28 +14,6 @@
# specific language governing permissions and limitations
# under the License.
get_and_check_legal_hold() {
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
log 2 "error getting object metadata"
return 1
fi
# shellcheck disable=SC2154
raw_metadata=$(echo "$metadata" | grep -v "InsecureRequestWarning")
log 5 "raw metadata: $raw_metadata"
if ! hold_status=$(echo "$raw_metadata" | jq -r ".ObjectLockLegalHoldStatus" 2>&1); then
log 2 "error retrieving hold status: $hold_status"
return 1
fi
if [[ "$hold_status" != "$4" ]]; then
log 2 "hold status mismatch ($hold_status, $4)"
return 1
fi
return 0
}
check_legal_hold_without_lock_enabled() {
if ! check_param_count_v2 "bucket, key, expected error" 3 $#; then
return 1

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Copyright 2024 Versity Software
# Copyright 2026 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

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Copyright 2024 Versity Software
# Copyright 2026 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
@@ -14,18 +14,18 @@
# specific language governing permissions and limitations
# under the License.
get_bucket_acl_and_check_owner() {
if [ $# -ne 2 ]; then
log 2 "'get_acl_and_check_owner' requires client, bucket name"
bucket_info_contains_bucket() {
if ! check_param_count_v2 "client, bucket" 2 $#; then
return 1
fi
if ! get_bucket_acl "$1" "$2"; then
log 2 "error getting bucket acl"
if ! head_bucket "mc" "$BUCKET_ONE_NAME"; then
log 2 "error getting bucket info"
return 1
fi
# shellcheck disable=SC2154
log 5 "ACL: $acl"
id=$(echo "$acl" | jq -r '.Owner.ID')
[[ $id == "$AWS_ACCESS_KEY_ID" ]] || fail "Acl mismatch"
}
if [[ "$bucket_info" != *"$BUCKET_ONE_NAME"* ]]; then
return 1
fi
return 0
}

View File

@@ -51,3 +51,15 @@ check_for_empty_region() {
fi
return 0
}
bucket_info_without_bucket() {
if head_bucket "s3api" "$BUCKET_ONE_NAME"; then
log 2 "able to get bucket info for non-existent bucket"
return 1
fi
if [[ $bucket_info != *"404"* ]]; then
log 2 "404 not returned for non-existent bucket info"
return 1
fi
return 0
}

View File

@@ -29,7 +29,6 @@ source ./tests/drivers/get_bucket_tagging/get_bucket_tagging.sh
source ./tests/drivers/get_bucket_tagging/get_bucket_tagging_rest.sh
source ./tests/drivers/get_object_tagging/get_object_tagging.sh
source ./tests/drivers/put_bucket_ownership_controls/put_bucket_ownership_controls_rest.sh
source ./tests/util/util_head_bucket.sh
export RUN_MC=true

View File

@@ -53,7 +53,6 @@ source ./tests/drivers/get_bucket_tagging/get_bucket_tagging_rest.sh
source ./tests/drivers/head_bucket/head_bucket_rest.sh
source ./tests/drivers/head_bucket/head_bucket_s3api.sh
source ./tests/drivers/put_bucket_ownership_controls/put_bucket_ownership_controls_rest.sh
source ./tests/util/util_head_bucket.sh
source ./tests/util/util_lock_config.sh
source ./tests/util/util_object.sh

View File

@@ -25,6 +25,7 @@ source ./tests/commands/put_object.sh
source ./tests/drivers/file.sh
source ./tests/drivers/head_object/head_object_s3api.sh
source ./tests/drivers/create_bucket/create_bucket_rest.sh
source ./tests/drivers/get_object_legal_hold/get_object_legal_hold.sh
source ./tests/drivers/get_object_tagging/get_object_tagging.sh
source ./tests/drivers/put_bucket_ownership_controls/put_bucket_ownership_controls_rest.sh
source ./tests/util/util_multipart.sh

View File

@@ -43,6 +43,9 @@ source ./tests/commands/put_object_retention.sh
source ./tests/commands/put_public_access_block.sh
source ./tests/commands/select_object_content.sh
source ./tests/drivers/copy_object/copy_object_rest.sh
source ./tests/drivers/get_object_attributes/get_object_attributes_s3api.sh
source ./tests/drivers/get_object_legal_hold/get_object_legal_hold.sh
source ./tests/drivers/get_object_retention/get_object_retention_s3api.sh
source ./tests/drivers/get_object_tagging/get_object_tagging.sh
source ./tests/drivers/list_buckets/list_buckets_rest.sh
source ./tests/drivers/put_bucket_ownership_controls/put_bucket_ownership_controls_rest.sh

View File

@@ -18,10 +18,6 @@ source ./tests/commands/delete_objects.sh
source ./tests/commands/list_objects_v2.sh
source ./tests/commands/list_parts.sh
source ./tests/drivers/put_object/put_object.sh
source ./tests/util/util_get_bucket_acl.sh
source ./tests/util/util_get_object_attributes.sh
source ./tests/util/util_get_object_retention.sh
source ./tests/util/util_legal_hold.sh
source ./tests/util/util_list_objects.sh
test_delete_objects_s3api_root() {

View File

@@ -1,30 +0,0 @@
#!/usr/bin/env bash
bucket_info_contains_bucket() {
if [ $# -ne 2 ]; then
log 2 "'bucket_info_contains_bucket' requires client, bucket"
return 1
fi
if ! head_bucket "mc" "$BUCKET_ONE_NAME"; then
log 2 "error getting bucket info"
return 1
fi
# shellcheck disable=SC2154
if [[ "$bucket_info" != *"$BUCKET_ONE_NAME"* ]]; then
return 1
fi
return 0
}
bucket_info_without_bucket() {
if head_bucket "s3api" "$BUCKET_ONE_NAME"; then
log 2 "able to get bucket info for non-existent bucket"
return 1
fi
if [[ $bucket_info != *"404"* ]]; then
log 2 "404 not returned for non-existent bucket info"
return 1
fi
return 0
}