mirror of
https://github.com/versity/versitygw.git
synced 2025-12-23 05:05:16 +00:00
test: s3cmd user, fix for non-bucket creating testing
This commit is contained in:
@@ -67,18 +67,24 @@ fi
|
||||
case $command_type in
|
||||
aws)
|
||||
"$HOME"/bin/bats ./tests/test_aws.sh || exit_code=$?
|
||||
if [[ $exit_code -eq 0 ]]; then
|
||||
"$HOME"/bin/bats ./tests/test_user_aws.sh || exit_code=$?
|
||||
fi
|
||||
;;
|
||||
aws-posix)
|
||||
"$HOME"/bin/bats ./tests/test_aws_posix.sh || exit_code=$?
|
||||
;;
|
||||
s3cmd)
|
||||
"$HOME"/bin/bats ./tests/test_s3cmd.sh || exit_code=$?
|
||||
if [[ $exit_code -eq 0 ]]; then
|
||||
"$HOME"/bin/bats ./tests/test_user_s3cmd.sh || exit_code=$?
|
||||
fi
|
||||
;;
|
||||
mc)
|
||||
"$HOME"/bin/bats ./tests/test_mc.sh || exit_code=$?
|
||||
;;
|
||||
user)
|
||||
"$HOME"/bin/bats ./tests/test_user.sh || exit_code=$?
|
||||
"$HOME"/bin/bats ./tests/test_user_aws.sh || exit_code=$?
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
@@ -4,6 +4,11 @@ if [[ -z "$VERSITYGW_TEST_ENV" ]]; then
|
||||
echo "Error: VERSITYGW_TEST_ENV parameter must be set"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck source=./.env.default
|
||||
source "$VERSITYGW_TEST_ENV"
|
||||
export RECREATE_BUCKETS
|
||||
|
||||
if ! ./tests/run.sh aws; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
source ./tests/setup.sh
|
||||
source ./tests/util.sh
|
||||
source ./tests/util_aws.sh
|
||||
source ./tests/util_bucket_create.sh
|
||||
source ./tests/util_file.sh
|
||||
source ./tests/test_common.sh
|
||||
@@ -82,7 +83,6 @@ source ./tests/test_common.sh
|
||||
|
||||
# test ability to delete multiple objects from bucket
|
||||
@test "test_delete_objects" {
|
||||
|
||||
local object_one="test-file-one"
|
||||
local object_two="test-file-two"
|
||||
|
||||
@@ -120,7 +120,6 @@ source ./tests/test_common.sh
|
||||
|
||||
# test v1 s3api list objects command
|
||||
@test "test-s3api-list-objects-v1" {
|
||||
|
||||
local object_one="test-file-one"
|
||||
local object_two="test-file-two"
|
||||
local object_two_data="test data\n"
|
||||
@@ -151,7 +150,6 @@ source ./tests/test_common.sh
|
||||
|
||||
# test v2 s3api list objects command
|
||||
@test "test-s3api-list-objects-v2" {
|
||||
|
||||
local object_one="test-file-one"
|
||||
local object_two="test-file-two"
|
||||
local object_two_data="test data\n"
|
||||
@@ -187,7 +185,6 @@ source ./tests/test_common.sh
|
||||
|
||||
# test multi-part upload
|
||||
@test "test-multi-part-upload" {
|
||||
|
||||
local bucket_file="bucket-file"
|
||||
bucket_file_data="test file\n"
|
||||
|
||||
@@ -210,7 +207,6 @@ source ./tests/test_common.sh
|
||||
|
||||
# test multi-part upload abort
|
||||
@test "test-multi-part-upload-abort" {
|
||||
|
||||
local bucket_file="bucket-file"
|
||||
bucket_file_data="test file\n"
|
||||
|
||||
@@ -232,7 +228,6 @@ source ./tests/test_common.sh
|
||||
|
||||
# test multi-part upload list parts command
|
||||
@test "test-multipart-upload-list-parts" {
|
||||
|
||||
local bucket_file="bucket-file"
|
||||
local bucket_file_data="test file\n"
|
||||
|
||||
@@ -280,10 +275,14 @@ source ./tests/test_common.sh
|
||||
|
||||
# test listing of active uploads
|
||||
@test "test-multipart-upload-list-uploads" {
|
||||
|
||||
local bucket_file_one="bucket-file-one"
|
||||
local bucket_file_two="bucket-file-two"
|
||||
|
||||
if [[ $RECREATE_BUCKETS == false ]]; then
|
||||
abort_all_multipart_uploads "$BUCKET_ONE_NAME" || local abort_result=$?
|
||||
[[ $abort_result -eq 0 ]] || fail "error aborting all uploads"
|
||||
fi
|
||||
|
||||
create_test_files "$bucket_file_one" "$bucket_file_two" || local created=$?
|
||||
[[ $created -eq 0 ]] || fail "Error creating test files"
|
||||
setup_bucket "aws" "$BUCKET_ONE_NAME" || local result=$?
|
||||
@@ -294,6 +293,7 @@ source ./tests/test_common.sh
|
||||
|
||||
local key_one
|
||||
local key_two
|
||||
log 5 "$uploads"
|
||||
key_one=$(echo "$uploads" | jq '.Uploads[0].Key')
|
||||
key_two=$(echo "$uploads" | jq '.Uploads[1].Key')
|
||||
key_one=${key_one//\"/}
|
||||
|
||||
@@ -34,6 +34,7 @@ test_common_put_object_with_data() {
|
||||
create_test_files "$object_name" || local create_result=$?
|
||||
[[ $create_result -eq 0 ]] || fail "Error creating test file"
|
||||
echo "test data" > "$test_file_folder"/"$object_name"
|
||||
test_common_put_object "$1" "$object_name"
|
||||
}
|
||||
|
||||
test_common_put_object_no_data() {
|
||||
|
||||
19
tests/test_user_aws.sh
Executable file
19
tests/test_user_aws.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
source ./tests/test_user_common.sh
|
||||
|
||||
@test "test_admin_user_aws" {
|
||||
test_admin_user "aws"
|
||||
}
|
||||
|
||||
@test "test_create_user_already_exists_aws" {
|
||||
test_create_user_already_exists "aws"
|
||||
}
|
||||
|
||||
@test "test_user_user_aws" {
|
||||
test_user_user "aws"
|
||||
}
|
||||
|
||||
@test "test_userplus_operation_aws" {
|
||||
test_userplus_operation "aws"
|
||||
}
|
||||
@@ -5,7 +5,11 @@ source ./tests/util_users.sh
|
||||
source ./tests/util.sh
|
||||
source ./tests/util_bucket_create.sh
|
||||
|
||||
@test "test_admin_user" {
|
||||
test_admin_user() {
|
||||
if [[ $# -ne 1 ]]; then
|
||||
fail "test admin user command requires command type"
|
||||
fi
|
||||
|
||||
admin_username="ABCDEF"
|
||||
user_username="GHIJKL"
|
||||
admin_password="123456"
|
||||
@@ -57,7 +61,11 @@ source ./tests/util_bucket_create.sh
|
||||
delete_user "$admin_username"
|
||||
}
|
||||
|
||||
@test "test_create_user_already_exists" {
|
||||
test_create_user_already_exists() {
|
||||
if [[ $# -ne 1 ]]; then
|
||||
fail "test admin user command requires command type"
|
||||
fi
|
||||
|
||||
username="ABCDEG"
|
||||
password="123456"
|
||||
|
||||
@@ -76,7 +84,11 @@ source ./tests/util_bucket_create.sh
|
||||
delete_user "$username"
|
||||
}
|
||||
|
||||
@test "test_user_user" {
|
||||
test_user_user() {
|
||||
if [[ $# -ne 1 ]]; then
|
||||
fail "test admin user command requires command type"
|
||||
fi
|
||||
|
||||
username="ABCDEG"
|
||||
password="123456"
|
||||
|
||||
@@ -121,7 +133,11 @@ source ./tests/util_bucket_create.sh
|
||||
delete_user "$username"
|
||||
}
|
||||
|
||||
@test "test_userplus_operation" {
|
||||
test_userplus_operation() {
|
||||
if [[ $# -ne 1 ]]; then
|
||||
fail "test admin user command requires command type"
|
||||
fi
|
||||
|
||||
username="ABCDEG"
|
||||
password="123456"
|
||||
|
||||
@@ -159,4 +175,4 @@ source ./tests/util_bucket_create.sh
|
||||
delete_bucket "aws" "versity-gwtest-admin-bucket"
|
||||
delete_user "$username" || delete_result=$?
|
||||
[[ $delete_result -eq 0 ]] || fail "error deleting user"
|
||||
}
|
||||
}
|
||||
19
tests/test_user_s3cmd.sh
Executable file
19
tests/test_user_s3cmd.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
source ./tests/test_user_common.sh
|
||||
|
||||
@test "test_admin_user_s3cmd" {
|
||||
test_admin_user "s3cmd"
|
||||
}
|
||||
|
||||
@test "test_create_user_already_exists_s3cmd" {
|
||||
test_create_user_already_exists "s3cmd"
|
||||
}
|
||||
|
||||
@test "test_user_user_s3cmd" {
|
||||
test_user_user "s3cmd"
|
||||
}
|
||||
|
||||
@test "test_userplus_operation_s3cmd" {
|
||||
test_userplus_operation "s3cmd"
|
||||
}
|
||||
40
tests/util_aws.sh
Normal file
40
tests/util_aws.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
abort_all_multipart_uploads() {
|
||||
if [[ $# -ne 1 ]]; then
|
||||
echo "abort all multipart uploads command missing bucket name"
|
||||
return 1
|
||||
fi
|
||||
|
||||
upload_list=$(aws --no-verify-ssl s3api list-multipart-uploads --bucket "$1" 2>&1) || list_result=$?
|
||||
if [[ $list_result -ne 0 ]]; then
|
||||
echo "error listing multipart uploads: $upload_list"
|
||||
return 1
|
||||
fi
|
||||
log 5 "$upload_list"
|
||||
while IFS= read -r line; do
|
||||
if [[ $line != *"InsecureRequestWarning"* ]]; then
|
||||
modified_upload_list+=("$line")
|
||||
fi
|
||||
done <<< "$upload_list"
|
||||
|
||||
log 5 "Modified upload list: ${modified_upload_list[*]}"
|
||||
has_uploads=$(echo "${modified_upload_list[*]}" | jq 'has("Uploads")')
|
||||
if [[ $has_uploads != false ]]; then
|
||||
lines=$(echo "${modified_upload_list[*]}" | jq -r '.Uploads[] | "--key \(.Key) --upload-id \(.UploadId)"') || lines_result=$?
|
||||
if [[ $lines_result -ne 0 ]]; then
|
||||
echo "error getting lines for multipart upload delete: $lines"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log 5 "$lines"
|
||||
while read -r line; do
|
||||
error=$(aws --no-verify-ssl s3api abort-multipart-upload --bucket "$1" $line 2>&1) || abort_result=$?
|
||||
if [[ $abort_result -ne 0 ]]; then
|
||||
echo "error aborting multipart upload: $error"
|
||||
return 1
|
||||
fi
|
||||
done <<< "$lines"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user