diff --git a/.github/workflows/system.yml b/.github/workflows/system.yml index fdf7439f..0f35496c 100644 --- a/.github/workflows/system.yml +++ b/.github/workflows/system.yml @@ -33,9 +33,9 @@ jobs: RECREATE_BUCKETS: "true" DELETE_BUCKETS_AFTER_TEST: "true" BACKEND: "posix" - - set: "REST, posix, non-static, not implemented, folder IAM" + - set: "REST, posix, non-static, not implemented|rest-delete-bucket-ownership-controls, folder IAM" IAM_TYPE: folder - RUN_SET: "rest-not-implemented" + RUN_SET: "rest-not-implemented,rest-delete-bucket-ownership-controls" RECREATE_BUCKETS: "true" DELETE_BUCKETS_AFTER_TEST: "true" BACKEND: "posix" diff --git a/tests/README.md b/tests/README.md index bdd0ed11..7e1738d7 100644 --- a/tests/README.md +++ b/tests/README.md @@ -185,6 +185,8 @@ A single instance can be run with `docker-compose -f docker-compose-bats.yml up **MAX_FILE_DOWNLOAD_CHUNK_SIZE**: when set, will divide the download of large files with GetObject into chunks of the given size. Useful for direct testing with slower connections. +**SKIP_USERS_TESTS**: skip versitygw-specific users tests, set to **false** to test against other S3 gateways + ## REST Scripts REST scripts are included for calls to S3's REST API in the `./tests/rest_scripts/` folder. To call a script, the following parameters are needed: diff --git a/tests/commands/get_bucket_ownership_controls.sh b/tests/commands/get_bucket_ownership_controls.sh index 4d3f2bc8..a1235b8f 100644 --- a/tests/commands/get_bucket_ownership_controls.sh +++ b/tests/commands/get_bucket_ownership_controls.sh @@ -61,6 +61,17 @@ get_bucket_ownership_controls_rest() { echo "$rule" } +get_bucket_ownership_controls_expect_error_callback() { + if ! check_param_count_v2 "bucket name, expected HTTP error, expected S3 error, expected message, callback" 5 $#; then + return 1 + fi + if ! send_rest_go_command_expect_error_callback "$2" "$3" "$4" "$5" "-bucketName" "$1" "-query" "ownershipControls="; then + log 2 "error checking ownership controls error and callback" + return 1 + fi + return 0 +} + get_object_ownership_rule() { if [[ -n "$SKIP_BUCKET_OWNERSHIP_CONTROLS" ]]; then log 5 "Skipping get bucket ownership controls" diff --git a/tests/commands/put_bucket_ownership_controls.sh b/tests/commands/put_bucket_ownership_controls.sh index 5e8ecbdc..a93ec8ab 100644 --- a/tests/commands/put_bucket_ownership_controls.sh +++ b/tests/commands/put_bucket_ownership_controls.sh @@ -31,4 +31,20 @@ put_bucket_ownership_controls() { log 2 "error putting bucket ownership controls: $error" return 1 fi -} \ No newline at end of file +} + +put_bucket_ownership_controls_rest() { + if [ $# -ne 2 ]; then + log 2 "'put_bucket_ownership_controls_rest' missing bucket name, ownership" + return 1 + fi + if ! result=$(COMMAND_LOG="$COMMAND_LOG" BUCKET_NAME="$1" OWNERSHIP="$2" OUTPUT_FILE="$TEST_FILE_FOLDER/result.txt" ./tests/rest_scripts/put_bucket_ownership_controls.sh); then + log 2 "error putting bucket ownership controls: $result" + return 1 + fi + if [ "$result" != "200" ]; then + log 2 "put bucket ownership controls returned code $result: $(cat "$TEST_FILE_FOLDER/result.txt")" + return 1 + fi + return 0 +} diff --git a/tests/drivers/get_bucket_ownership_controls/get_bucket_ownership_controls_rest.sh b/tests/drivers/get_bucket_ownership_controls/get_bucket_ownership_controls_rest.sh new file mode 100644 index 00000000..bcc0373d --- /dev/null +++ b/tests/drivers/get_bucket_ownership_controls/get_bucket_ownership_controls_rest.sh @@ -0,0 +1,53 @@ +#!/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. + +get_bucket_ownership_controls_check_error_after_deletion() { + if ! check_param_count_v2 "bucket name" 1 $#; then + return 1 + fi + bucket_name="$1" + if ! get_bucket_ownership_controls_expect_error_callback "$1" "404" "OwnershipControlsNotFoundError" "were not found" "check_error_bucket_name"; then + log 2 "error checking bucket ownership controls error" + return 1 + fi + return 0 +} + +check_error_bucket_name() { + if ! check_param_count_v2 "data file" 1 $#; then + return 1 + fi + if ! check_xml_element_contains "$1" "$bucket_name" "Error" "BucketName"; then + log 2 "error checking BucketName XML element" + return 1 + fi + return 0 +} + +get_and_check_ownership_controls() { + if ! check_param_count "get_and_check_ownership_controls" "bucket, expected result" 2 $#; then + return 1 + fi + if ! rule=$(get_bucket_ownership_controls_rest "$1" 2>&1); then + log 2 "error getting ownership rule: $rule" + return 1 + fi + if [ "$rule" != "$2" ]; then + log 2 "rule mismatch (expected '$2', actual '$rule')" + return 1 + fi + return 0 +} diff --git a/tests/drivers/rest.sh b/tests/drivers/rest.sh index bc22c53f..4d5d23e7 100644 --- a/tests/drivers/rest.sh +++ b/tests/drivers/rest.sh @@ -166,10 +166,22 @@ send_rest_command_expect_success_callback() { send_rest_go_command_expect_error() { if [ $# -lt 3 ] && [ $(($# % 2)) -ne 1 ]; then - log 2 "'send_rest_go_command_expect_error' param count must be 3 or greater, odd (key/value pairs)" + log 2 "'send_rest_go_command_expect_error' param count must be 3 or greater, odd (expected HTTP code, expected error code, expected message, key/value pairs)" return 1 fi - if ! curl_command=$(go run ./tests/rest_scripts/generate_command.go -awsAccessKeyId "$AWS_ACCESS_KEY_ID" -awsSecretAccessKey "$AWS_SECRET_ACCESS_KEY" -url "$AWS_ENDPOINT_URL" "${@:4}" 2>&1); then + if ! send_rest_go_command_expect_error_callback "$1" "$2" "$3" "" "${@:4}"; then + log 2 "error sending go command and checking error" + return 1 + fi + return 0 +} + +send_rest_go_command_expect_error_callback() { + if [ $# -lt 4 ] && [ $(($# % 2)) -eq 1 ]; then + log 2 "'send_rest_go_command_expect_error' param count must be 4 or greater, even (expected HTTP code, expected error code, expected message, callback, key/value pairs)" + return 1 + fi + if ! curl_command=$(go run ./tests/rest_scripts/generate_command.go -awsAccessKeyId "$AWS_ACCESS_KEY_ID" -awsSecretAccessKey "$AWS_SECRET_ACCESS_KEY" -url "$AWS_ENDPOINT_URL" "${@:5}" 2>&1); then log 2 "error: $curl_command" return 1 fi @@ -185,6 +197,10 @@ send_rest_go_command_expect_error() { log 2 "error checking expected header error" return 1 fi + if [ "$4" != "" ] && ! "$4" "$TEST_FILE_FOLDER/result.txt"; then + log 2 "callback error" + return 1 + fi return 0 } diff --git a/tests/run.sh b/tests/run.sh index 80e5bb57..9f2d4198 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -17,35 +17,36 @@ # Function to display help information show_help() { echo "Usage: $0 [option...]" - echo " -h, --help Display this help message and exit" - echo " Separate the below by comma" - echo " s3api Run all tests with s3api cli" - echo " s3api-multipart Run multipart tests with s3api cli" - echo " s3api-bucket Run bucket tests with s3api cli" - echo " s3api-object Run object tests with s3api cli" - echo " s3api-policy Run policy tests with s3api cli" - echo " s3api-user Run user tests with s3api cli" - echo " s3 Run tests with s3 cli" - echo " s3cmd Run tests with s3cmd utility" - echo " s3cmd-user Run user tests with s3cmd utility" - echo " s3cmd-non-user Run non-user tests with s3cmd utility" - echo " s3cmd-file-count Run file count test with s3cmd utility" - echo " mc Run tests with mc utility" - 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 tests" - echo " rest-acl Run REST ACL tests" - echo " rest-chunked Run REST chunked upload tests" - echo " rest-checksum Run REST checksum tests" - echo " rest-create-bucket Run REST create bucket tests" - echo " rest-head-bucket Run REST head bucket tests" - echo " rest-list-buckets Run REST list-buckets tests" - echo " rest-multipart Run REST multipart tests" - echo " rest-not-implemented Run REST multipart tests" - echo " rest-put-object Run REST put-object tests" - echo " rest-versioning Run REST versioning tests" - echo " rest-bucket Run REST bucket tests" + echo " -h, --help Display this help message and exit" + echo " Separate the below by comma" + echo " s3api Run all tests with s3api cli" + echo " s3api-multipart Run multipart tests with s3api cli" + echo " s3api-bucket Run bucket tests with s3api cli" + echo " s3api-object Run object tests with s3api cli" + echo " s3api-policy Run policy tests with s3api cli" + echo " s3api-user Run user tests with s3api cli" + echo " s3 Run tests with s3 cli" + echo " s3cmd Run tests with s3cmd utility" + echo " s3cmd-user Run user tests with s3cmd utility" + echo " s3cmd-non-user Run non-user tests with s3cmd utility" + echo " s3cmd-file-count Run file count test with s3cmd utility" + echo " mc Run tests with mc utility" + 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 tests" + echo " rest-acl Run REST ACL tests" + echo " rest-chunked Run REST chunked upload tests" + echo " rest-checksum Run REST checksum tests" + echo " rest-create-bucket Run REST create bucket tests" + echo " rest-delete-bucket-ownership-controls Run REST delete bucket ownership controls tests" + echo " rest-head-bucket Run REST head bucket tests" + echo " rest-list-buckets Run REST list-buckets tests" + echo " rest-multipart Run REST multipart tests" + echo " rest-not-implemented Run REST multipart tests" + echo " rest-put-object Run REST put-object tests" + echo " rest-versioning Run REST versioning tests" + echo " rest-bucket Run REST bucket tests" } handle_param() { @@ -58,7 +59,7 @@ handle_param() { 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-create-bucket|rest-head-bucket|rest-list-buckets|rest-not-implemented|\ - rest-put-object|rest-versioning|rest-bucket|rest-multipart) + rest-put-object|rest-versioning|rest-bucket|rest-multipart|rest-delete-bucket-ownership-controls) run_suite "$1" ;; *) # Handle unrecognized options or positional arguments @@ -167,6 +168,8 @@ run_suite() { exit_code=1 elif ! "$HOME"/bin/bats ./tests/test_rest_create_bucket.sh; then exit_code=1 + elif ! "$HOME"/bin/bats ./tests/test_rest_delete_bucket_ownership_controls.sh; then + exit_code=1 elif ! "$HOME"/bin/bats ./tests/test_rest_head_bucket.sh; then exit_code=1 elif ! "$HOME"/bin/bats ./tests/test_rest_list_buckets.sh; then @@ -207,6 +210,10 @@ run_suite() { echo "Running REST create bucket tests ..." "$HOME"/bin/bats ./tests/test_rest_create_bucket.sh || exit_code=$? ;; + rest-delete-bucket-ownership-controls) + echo "Running REST delete bucket ownership controls tests ..." + "$HOME"/bin/bats ./tests/test_rest_delete_bucket_ownership_controls.sh || exit_code=$? + ;; rest-head-bucket) echo "Running REST head bucket tests ..." "$HOME"/bin/bats ./tests/test_rest_head_bucket.sh || exit_code=$? diff --git a/tests/test_common_acl.sh b/tests/test_common_acl.sh index 98100e58..8a3cdc11 100644 --- a/tests/test_common_acl.sh +++ b/tests/test_common_acl.sh @@ -14,7 +14,7 @@ # specific language governing permissions and limitations # under the License. -if [ "$SKIP_ACL_TESTING" == "true" ]; then +if [ "$SKIP_ACL_TESTING" == "true" ] || [ "$SKIP_USERS_TESTS" == "true" ]; then skip "Skipping ACL tests" exit 0 fi diff --git a/tests/test_rest.sh b/tests/test_rest.sh index 64020464..ad4d31d3 100755 --- a/tests/test_rest.sh +++ b/tests/test_rest.sh @@ -30,6 +30,7 @@ source ./tests/commands/put_object.sh source ./tests/commands/put_object_retention.sh source ./tests/commands/put_object_tagging.sh source ./tests/drivers/copy_object/copy_object_rest.sh +source ./tests/drivers/get_bucket_ownership_controls/get_bucket_ownership_controls_rest.sh source ./tests/drivers/head_object/head_object_rest.sh source ./tests/drivers/xml.sh source ./tests/logger.sh @@ -44,7 +45,6 @@ source ./tests/util/util_list_parts.sh source ./tests/util/util_lock_config.sh source ./tests/util/util_multipart_before_completion.sh source ./tests/util/util_object.sh -source ./tests/util/util_ownership.sh source ./tests/util/util_policy.sh source ./tests/util/util_public_access_block.sh source ./tests/util/util_rest.sh @@ -282,16 +282,6 @@ test_file="test_file" assert_success } -@test "REST - PutObject - user permission, bad signature" { - run setup_bucket_file_and_user "$BUCKET_ONE_NAME" "$test_file" "$USERNAME_ONE" "$PASSWORD_ONE" "admin" - assert_success - username="${lines[${#lines[@]}-2]}" - password="${lines[${#lines[@]}-1]}" - - run put_object_rest_user_bad_signature "$username" "$password" "$TEST_FILE_FOLDER/$test_file" "$BUCKET_ONE_NAME" "$test_file" - assert_success -} - @test "REST - PutObjectRetention - w/o request body" { run setup_bucket_object_lock_enabled "$BUCKET_ONE_NAME" assert_success diff --git a/tests/test_rest_acl.sh b/tests/test_rest_acl.sh index a5fe2f0b..4753a4a6 100755 --- a/tests/test_rest_acl.sh +++ b/tests/test_rest_acl.sh @@ -28,7 +28,7 @@ source ./tests/util/util_setup.sh export RUN_USERS=true -if [ "$SKIP_ACL_TESTING" == "true" ]; then +if [ "$SKIP_ACL_TESTING" == "true" ] || [ "$SKIP_USERS_TESTS" == "true" ]; then skip "Skipping ACL tests" exit 0 fi diff --git a/tests/test_rest_bucket.sh b/tests/test_rest_bucket.sh index 8f20f303..2c760948 100755 --- a/tests/test_rest_bucket.sh +++ b/tests/test_rest_bucket.sh @@ -21,6 +21,7 @@ source ./tests/commands/get_object_lock_configuration.sh source ./tests/commands/head_bucket.sh source ./tests/commands/list_buckets.sh source ./tests/drivers/create_bucket/create_bucket_rest.sh +source ./tests/drivers/get_bucket_ownership_controls/get_bucket_ownership_controls_rest.sh source ./tests/drivers/list_buckets/list_buckets_rest.sh source ./tests/logger.sh source ./tests/setup.sh @@ -28,7 +29,6 @@ source ./tests/util/util_bucket.sh source ./tests/util/util_delete_object.sh source ./tests/util/util_list_buckets.sh source ./tests/util/util_lock_config.sh -source ./tests/util/util_ownership.sh source ./tests/util/util_public_access_block.sh source ./tests/util/util_rest.sh source ./tests/util/util_tags.sh @@ -151,6 +151,9 @@ export RUN_USERS=true } @test "REST - put policy" { + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip + fi run setup_bucket "$BUCKET_ONE_NAME" assert_success diff --git a/tests/test_rest_delete_bucket_ownership_controls.sh b/tests/test_rest_delete_bucket_ownership_controls.sh new file mode 100755 index 00000000..da4eec0a --- /dev/null +++ b/tests/test_rest_delete_bucket_ownership_controls.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bats + +# 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. + +load ./bats-support/load +load ./bats-assert/load + +source ./tests/drivers/get_bucket_ownership_controls/get_bucket_ownership_controls_rest.sh +source ./tests/drivers/user.sh +source ./tests/setup.sh + +export RUN_USERS=true + +@test "REST - DeleteBucketOwnershipControls - lack permission" { + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip + fi + run setup_bucket "$BUCKET_ONE_NAME" + assert_success + + run create_versitygw_acl_user_or_get_direct_user "$USERNAME_ONE" "$PASSWORD_ONE" + assert_success + username=${lines[2]} + password=${lines[3]} + + run put_bucket_ownership_controls_rest "$BUCKET_ONE_NAME" "BucketOwnerPreferred" + assert_success + + run send_rest_go_command_expect_error "403" "AccessDenied" "Access Denied" "-awsAccessKeyId" "$username" "-awsSecretAccessKey" "$password" \ + "-method" "DELETE" "-bucketName" "$BUCKET_ONE_NAME" "-query" "ownershipControls=" + assert_success +} + +@test "REST - DeleteBucketOwnershipControls - success" { + run setup_bucket "$BUCKET_ONE_NAME" + assert_success + + run put_bucket_ownership_controls_rest "$BUCKET_ONE_NAME" "BucketOwnerPreferred" + assert_success + + run get_bucket_ownership_controls_rest "$BUCKET_ONE_NAME" + assert_success + rule=${output[${#output[@]}-1]} + assert_equal "$rule" "BucketOwnerPreferred" + + run send_rest_go_command "204" "-method" "DELETE" "-bucketName" "$BUCKET_ONE_NAME" "-query" "ownershipControls=" + assert_success + + run get_bucket_ownership_controls_rest "$BUCKET_ONE_NAME" + assert_success + rule=${output[${#output[@]}-1]} + assert_equal "$rule" "" +} + +@test "REST - DeleteBucketOwnershipControls - BucketName is reported in error" { + if [ "$DIRECT" != "true" ]; then + skip "https://github.com/versity/versitygw/issues/1493" + fi + run setup_bucket "$BUCKET_ONE_NAME" + assert_success + + if ! send_rest_go_command "204" \ + "-method" "DELETE" "-bucketName" "$BUCKET_ONE_NAME" "-query" "ownershipControls="; then + log 2 "error deleting ownership controls" + return 1 + fi + + run get_bucket_ownership_controls_check_error_after_deletion "$BUCKET_ONE_NAME" + assert_success +} diff --git a/tests/test_rest_put_object.sh b/tests/test_rest_put_object.sh index 6ea84ee0..35953233 100755 --- a/tests/test_rest_put_object.sh +++ b/tests/test_rest_put_object.sh @@ -42,6 +42,9 @@ export RUN_USERS=true } @test "REST - PutObject with user permission - admin user" { + if [ "$SKIP_USERS_TEST" == "true" ]; then + skip "skipping versity-specific users tests" + fi run setup_bucket_file_and_user "$BUCKET_ONE_NAME" "$test_file" "$USERNAME_ONE" "$PASSWORD_ONE" "admin" assert_success username="${lines[${#lines[@]}-2]}" @@ -53,6 +56,9 @@ export RUN_USERS=true } @test "REST - PutObject with no permission - 'user' user" { + if [ "$SKIP_USERS_TEST" == "true" ]; then + skip "skipping versity-specific users tests" + fi run setup_bucket_file_and_user "$BUCKET_ONE_NAME" "$test_file" "$USERNAME_ONE" "$PASSWORD_ONE" "user" assert_success username="${lines[${#lines[@]}-2]}" @@ -97,7 +103,6 @@ export RUN_USERS=true if [ "$DIRECT" != "true" ]; then skip "https://github.com/versity/versitygw/issues/821" fi - test_file="test_file" run setup_bucket_and_add_file "$BUCKET_ONE_NAME" "$test_file" assert_success @@ -110,7 +115,6 @@ export RUN_USERS=true if [ "$DIRECT" != "true" ]; then skip "https://github.com/versity/versitygw/issues/821" fi - test_file="test_file" run setup_bucket "$BUCKET_ONE_NAME" assert_success @@ -126,7 +130,6 @@ export RUN_USERS=true if [ "$DIRECT" != "true" ]; then skip "https://github.com/versity/versitygw/issues/821" fi - test_file="test_file" run setup_bucket "$BUCKET_ONE_NAME" assert_success @@ -139,7 +142,6 @@ export RUN_USERS=true if [ "$DIRECT" != "true" ]; then skip "https://github.com/versity/versitygw/issues/821" fi - test_file="test_file" run setup_bucket "$BUCKET_ONE_NAME" assert_success @@ -158,7 +160,6 @@ export RUN_USERS=true if [ "$DIRECT" != "true" ]; then skip "https://github.com/versity/versitygw/issues/821" fi - test_file="test_file" run setup_bucket "$BUCKET_ONE_NAME" assert_success @@ -185,7 +186,6 @@ export RUN_USERS=true uppercase_key="CAPITAL" uppercase_value="DUMMY" - test_file="test_file" run setup_bucket "$BUCKET_ONE_NAME" assert_success @@ -199,3 +199,16 @@ export RUN_USERS=true run check_metadata_key_case "$BUCKET_ONE_NAME" "$test_file" "$uppercase_key" "$uppercase_value" assert_success } + +@test "REST - PutObject - user permission, bad signature" { + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip + fi + run setup_bucket_file_and_user "$BUCKET_ONE_NAME" "$test_file" "$USERNAME_ONE" "$PASSWORD_ONE" "admin" + assert_success + username="${lines[${#lines[@]}-2]}" + password="${lines[${#lines[@]}-1]}" + + run put_object_rest_user_bad_signature "$username" "$password" "$TEST_FILE_FOLDER/$test_file" "$BUCKET_ONE_NAME" "$test_file" + assert_success +} diff --git a/tests/test_s3api_bucket.sh b/tests/test_s3api_bucket.sh index 9438d317..001854f9 100755 --- a/tests/test_s3api_bucket.sh +++ b/tests/test_s3api_bucket.sh @@ -24,7 +24,6 @@ source ./tests/util/util_head_bucket.sh source ./tests/util/util_lock_config.sh source ./tests/util/util_object.sh source ./tests/util/util_tags.sh -source ./tests/util/util_users.sh source ./tests/test_s3api_root_inner.sh source ./tests/test_common.sh source ./tests/test_common_acl.sh diff --git a/tests/test_s3api_multipart.sh b/tests/test_s3api_multipart.sh index 9d8e75e2..9a233aba 100755 --- a/tests/test_s3api_multipart.sh +++ b/tests/test_s3api_multipart.sh @@ -70,7 +70,7 @@ export RUN_USERS=true local bucket_file="bucket-file" local expected_content_type="application/zip" - local expected_meta_key="testKey" + local expected_meta_key="testkey" local expected_meta_val="testValue" local expected_hold_status="ON" local expected_retention_mode="GOVERNANCE" diff --git a/tests/test_s3api_object.sh b/tests/test_s3api_object.sh index f27d0147..19e4a936 100755 --- a/tests/test_s3api_object.sh +++ b/tests/test_s3api_object.sh @@ -24,7 +24,6 @@ source ./tests/util/util_lock_config.sh source ./tests/util/util_object.sh source ./tests/util/util_setup.sh source ./tests/util/util_tags.sh -source ./tests/util/util_users.sh source ./tests/test_s3api_root_inner.sh source ./tests/test_common.sh source ./tests/test_common_acl.sh diff --git a/tests/test_s3api_policy.sh b/tests/test_s3api_policy.sh index 5cfbca75..afbb9802 100755 --- a/tests/test_s3api_policy.sh +++ b/tests/test_s3api_policy.sh @@ -39,142 +39,87 @@ source ./tests/drivers/get_bucket_acl/get_bucket_acl_s3api.sh export RUN_USERS=true +if [ -n "$SKIP_POLICY" ] || [ "$SKIP_USERS_TESTS" == "true" ]; then + skip "Skipping ACL tests" + exit 0 +fi + @test "test_policy_abort_multipart_upload" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_abort_multipart_upload } @test "test_policy_allow_deny" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_allow_deny } @test "test_policy_delete" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_delete } @test "test_policy_delete_bucket_policy" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_delete_bucket_policy } @test "test_policy_deny" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_deny } @test "test_policy_get_bucket_acl" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_get_bucket_acl } @test "test_policy_get_bucket_policy" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_get_bucket_policy } @test "test_policy_get_bucket_tagging" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_get_bucket_tagging } @test "test_policy_get_object_file_wildcard" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_get_object_file_wildcard } @test "test_policy_get_object_folder_wildcard" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_get_object_folder_wildcard } @test "test_policy_get_object_specific_file" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_get_object_specific_file } @test "test_policy_get_object_with_user" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_get_object_with_user } @test "test_policy_list_multipart_uploads" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_list_multipart_uploads } @test "test_policy_list_upload_parts" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_list_upload_parts } @test "test_policy_put_acl" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_put_acl } @test "test_policy_put_bucket_policy" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_put_bucket_policy } @test "test_policy_put_bucket_tagging" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_put_bucket_tagging } @test "test_policy_two_principals" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_two_principals } @test "test_policy_put_wildcard" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_put_wildcard } @test "test_put_policy_invalid_action" { - if [[ -n $SKIP_POLICY ]]; then - skip "will not test policy actions with SKIP_POLICY set" - fi test_s3api_policy_invalid_action } diff --git a/tests/test_s3api_root_inner.sh b/tests/test_s3api_root_inner.sh index 2084374a..b8a9c39a 100755 --- a/tests/test_s3api_root_inner.sh +++ b/tests/test_s3api_root_inner.sh @@ -106,6 +106,9 @@ test_get_object_attributes_s3api_root() { } test_get_put_object_legal_hold_s3api_root() { + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip + fi bucket_file="bucket_file" username=$USERNAME_ONE password=$PASSWORD_ONE @@ -140,6 +143,9 @@ test_get_put_object_legal_hold_s3api_root() { } test_get_put_object_retention_s3api_root() { + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip + fi bucket_file="bucket_file" username=$USERNAME_ONE secret_key=$PASSWORD_ONE @@ -176,6 +182,9 @@ test_get_put_object_retention_s3api_root() { } test_retention_bypass_s3api_root() { + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip + fi bucket_file="bucket_file" username=$USERNAME_ONE secret_key=$PASSWORD_ONE diff --git a/tests/test_s3cmd.sh b/tests/test_s3cmd.sh index 0bd71cf8..7dbaa1d5 100755 --- a/tests/test_s3cmd.sh +++ b/tests/test_s3cmd.sh @@ -22,7 +22,6 @@ source ./tests/test_common.sh source ./tests/test_common_acl.sh source ./tests/util/util_create_bucket.sh source ./tests/util/util_object.sh -source ./tests/util/util_users.sh source ./tests/commands/delete_bucket_policy.sh source ./tests/commands/get_bucket_policy.sh source ./tests/commands/put_bucket_policy.sh diff --git a/tests/test_user_aws.sh b/tests/test_user_aws.sh index 09f847a3..ac307330 100755 --- a/tests/test_user_aws.sh +++ b/tests/test_user_aws.sh @@ -34,9 +34,11 @@ export RUN_USERS=true } @test "test_delete_user_no_access_key" { - if delete_user ""; then - fail "delete user with empty access key succeeded" + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip fi + run delete_user "" + assert_failure } @test "test_user_user_aws" { @@ -48,6 +50,9 @@ export RUN_USERS=true } @test "test_user_get_object" { + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip + fi test_file="test_file" run setup_user_versitygw_or_direct "$USERNAME_ONE" "$PASSWORD_ONE" "user" "$BUCKET_ONE_NAME" @@ -72,6 +77,9 @@ export RUN_USERS=true } @test "test_userplus_get_object" { + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip + fi test_file="test_file" run setup_user_versitygw_or_direct "$USERNAME_ONE" "$PASSWORD_ONE" "userplus" "$BUCKET_ONE_NAME" @@ -96,6 +104,9 @@ export RUN_USERS=true } @test "test_user_delete_object" { + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip + fi test_file="test_file" run setup_user_versitygw_or_direct "$USERNAME_ONE" "$PASSWORD_ONE" "user" "$BUCKET_ONE_NAME" @@ -120,6 +131,9 @@ export RUN_USERS=true } @test "test_admin_put_get_object" { + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip + fi test_file="test_file" run setup_user_versitygw_or_direct "$USERNAME_ONE" "$PASSWORD_ONE" "admin" "$BUCKET_ONE_NAME" @@ -148,6 +162,9 @@ export RUN_USERS=true } @test "test_user_create_multipart_upload" { + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip + fi test_file="test_file" run setup_user_versitygw_or_direct "$USERNAME_TWO" "$PASSWORD_TWO" "user" "$BUCKET_ONE_NAME" diff --git a/tests/test_user_common.sh b/tests/test_user_common.sh index 2fd4c619..54935e0f 100755 --- a/tests/test_user_common.sh +++ b/tests/test_user_common.sh @@ -23,6 +23,9 @@ source ./tests/util/util_users.sh source ./tests/commands/list_buckets.sh test_admin_user() { + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip + fi admin_username="$USERNAME_ONE" admin_password="$PASSWORD_ONE" user_username="$USERNAME_TWO" @@ -59,6 +62,9 @@ test_admin_user() { } test_create_user_already_exists() { + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip + fi username="$USERNAME_ONE" password="$PASSWORD_ONE" @@ -70,6 +76,9 @@ test_create_user_already_exists() { } test_user_user() { + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip + fi if [ "$RECREATE_BUCKETS" == "false" ]; then skip "test not valid for static buckets" fi @@ -106,6 +115,9 @@ test_user_user() { } test_userplus_operation() { + if [ "$SKIP_USERS_TESTS" == "true" ]; then + skip + fi username="$USERNAME_ONE" password="$PASSWORD_ONE" diff --git a/tests/util/util_chunked_upload.sh b/tests/util/util_chunked_upload.sh index 515ddc5d..3a17c403 100644 --- a/tests/util/util_chunked_upload.sh +++ b/tests/util/util_chunked_upload.sh @@ -257,7 +257,7 @@ chunked_upload_trailer_incorrect_checksum() { log 2 "error creating test file" return 1 fi - if ! checksum=$(calculate_incorrect_checksum "$1" "$test_file"); then + if ! checksum=$(calculate_incorrect_checksum "$1" "$TEST_FILE_FOLDER/$test_file"); then log 2 "error calculating incorrect checksum" return 1 fi diff --git a/tests/util/util_object.sh b/tests/util/util_object.sh index 9669a2a6..858ebf64 100644 --- a/tests/util/util_object.sh +++ b/tests/util/util_object.sh @@ -46,6 +46,7 @@ source ./tests/commands/put_object_lock_configuration.sh source ./tests/commands/upload_part_copy.sh source ./tests/commands/upload_part.sh source ./tests/drivers/head_object/head_object_rest.sh +source ./tests/drivers/openssl.sh source ./tests/util/util_users.sh # params: bucket, object name @@ -286,7 +287,7 @@ check_checksum_rest_incorrect() { fi error_cs_str="$(echo "$1" | tr '[:lower:]' '[:upper:]')" error_message="The $error_cs_str you specified did not match the calculated checksum." - if ! calculate_incorrect_checksum "$1" "$(cat "$TEST_FILE_FOLDER/$test_file")"; then + if ! calculate_incorrect_checksum "$1" "$TEST_FILE_FOLDER/$test_file"; then log 2 "error calculating incorrect checksum" return 1 fi @@ -298,35 +299,18 @@ check_checksum_rest_incorrect() { } calculate_incorrect_checksum() { - if ! check_param_count "calculate_incorrect_checksum" "checksum type, data" 2 $#; then + if ! check_param_count "calculate_incorrect_checksum" "checksum type, data file" 2 $#; then return 1 fi - case "$1" in - "sha1") - incorrect_checksum="$(echo -n "$2"a | sha1sum | awk '{print $1}' | xxd -r -p | base64)" - ;; - "sha256") - incorrect_checksum="$(echo -n "$2"a | sha256sum | awk '{print $1}' | xxd -r -p | base64)" - ;; - "crc32") - incorrect_checksum="$(echo -n "$2"a | gzip -c -1 | tail -c8 | od -t x4 -N 4 -A n | awk '{print $1}' | xxd -r -p | base64)" - ;; - "crc32c") - if ! incorrect_checksum=$(DATA_FILE=<(echo -n "$2"a) TEST_FILE_FOLDER="$TEST_FILE_FOLDER" CHECKSUM_TYPE="crc32c" ./tests/rest_scripts/calculate_checksum.sh 2>&1); then - log 2 "error calculating checksum: $incorrect_checksum" - return 1 - fi - ;; - "crc64nvme") - if ! incorrect_checksum=$(DATA_FILE=<(echo -n "$2"a) TEST_FILE_FOLDER="$TEST_FILE_FOLDER" CHECKSUM_TYPE="crc64nvme" ./tests/rest_scripts/calculate_checksum.sh 2>&1); then - log 2 "error calculating checksum: $incorrect_checksum" - return 1 - fi - ;; - *) - log 2 "invalid checksum type: $1" + if ! checksum=$(DATA_FILE="$2" CHECKSUM_TYPE="$1" TEST_FILE_FOLDER="$TEST_FILE_FOLDER" ./tests/rest_scripts/calculate_checksum.sh 2>&1); then + log 2 "error calculating checksum: $checksum" return 1 - esac + fi + if [ "${checksum:0:1}" == "a" ]; then + incorrect_checksum="A${checksum:1}" + else + incorrect_checksum="a${checksum:1}" + fi echo "$incorrect_checksum" return 0 } diff --git a/tests/util/util_ownership.sh b/tests/util/util_ownership.sh deleted file mode 100644 index 1369f75f..00000000 --- a/tests/util/util_ownership.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash - -get_and_check_ownership_controls() { - if ! check_param_count "get_and_check_ownership_controls" "bucket, expected result" 2 $#; then - return 1 - fi - if ! rule=$(get_bucket_ownership_controls_rest "$1" 2>&1); then - log 2 "error getting ownership rule: $rule" - return 1 - fi - if [ "$rule" != "$2" ]; then - log 2 "rule mismatch (expected '$2', actual '$rule')" - return 1 - fi - return 0 -} - -put_bucket_ownership_controls_rest() { - if [ $# -ne 2 ]; then - log 2 "'put_bucket_ownership_controls_rest' missing bucket name, ownership" - return 1 - fi - if ! result=$(COMMAND_LOG="$COMMAND_LOG" BUCKET_NAME="$1" OWNERSHIP="$2" OUTPUT_FILE="$TEST_FILE_FOLDER/result.txt" ./tests/rest_scripts/put_bucket_ownership_controls.sh); then - log 2 "error putting bucket ownership controls: $result" - return 1 - fi - if [ "$result" != "200" ]; then - log 2 "put bucket ownership controls returned code $result: $(cat "$TEST_FILE_FOLDER/result.txt")" - return 1 - fi - return 0 -} \ No newline at end of file