Skip to content

Commit

Permalink
fix: get direct tests working against a non-versitygw endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
benmcclelland committed Sep 12, 2024
1 parent 2d9a7cc commit d500274
Show file tree
Hide file tree
Showing 17 changed files with 166 additions and 91 deletions.
2 changes: 1 addition & 1 deletion Dockerfile_test_bats
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RUN curl https://dl.min.io/client/mc/release/${MC_FOLDER}/mc \
--create-dirs \
-o /usr/local/minio-binaries/mc && \
chmod -R 755 /usr/local/minio-binaries
ENV PATH="/usr/local/minio-binaries":${PATH}
ENV PATH=/usr/local/minio-binaries:${PATH}

# Download Go 1.21 (adjust the version and platform as needed)
RUN wget https://golang.org/dl/${GO_LIBRARY}
Expand Down
2 changes: 0 additions & 2 deletions docker-compose-bats.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
no_certs:
build:
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3"
services:
posix:
build:
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/delete_bucket_policy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ delete_bucket_policy() {
return 1
fi
local delete_result=0
if [[ $1 == 'aws' ]] || [[ $1 == 's3api' ]]; then
if [[ $1 == 'aws' ]] || [[ $1 == 's3api' ]] || [[ $1 == 's3' ]]; then
error=$(aws --no-verify-ssl s3api delete-bucket-policy --bucket "$2" 2>&1) || delete_result=$?
elif [[ $1 == 's3cmd' ]]; then
error=$(s3cmd "${S3CMD_OPTS[@]}" --no-check-certificate delpolicy "s3://$2" 2>&1) || delete_result=$?
Expand Down
10 changes: 10 additions & 0 deletions tests/commands/get_bucket_ownership_controls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
# under the License.

get_bucket_ownership_controls() {
if [[ -n "$SKIP_BUCKET_OWNERSHIP_CONTROLS" ]]; then
log 5 "Skipping get bucket ownership controls"
return 0
fi

record_command "get-bucket-ownership-controls" "client:s3api"
if [[ $# -ne 1 ]]; then
log 2 "'get bucket ownership controls' command requires bucket name"
Expand All @@ -32,6 +37,11 @@ get_bucket_ownership_controls() {
}

get_object_ownership_rule() {
if [[ -n "$SKIP_BUCKET_OWNERSHIP_CONTROLS" ]]; then
log 5 "Skipping get bucket ownership controls"
return 0
fi

if [[ $# -ne 1 ]]; then
log 2 "'get object ownership rule' command requires bucket name"
return 1
Expand Down
4 changes: 2 additions & 2 deletions tests/commands/put_bucket_acl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ reset_bucket_acl() {
return 1
fi
# shellcheck disable=SC2154
cat <<EOF > "$test_file_folder/$acl_file"
cat <<EOF > "$TEST_FILE_FOLDER/$acl_file"
{
"Grants": [
{
Expand All @@ -73,7 +73,7 @@ reset_bucket_acl() {
}
}
EOF
if ! put_bucket_acl_s3api "$BUCKET_ONE_NAME" "$test_file_folder/$acl_file"; then
if ! put_bucket_acl_s3api "$BUCKET_ONE_NAME" "$TEST_FILE_FOLDER/$acl_file"; then
log 2 "error putting bucket acl (s3api)"
return 1
fi
Expand Down
5 changes: 5 additions & 0 deletions tests/commands/put_bucket_ownership_controls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

# fail if unable to put bucket ownership controls
put_bucket_ownership_controls() {
if [[ -n "$SKIP_BUCKET_OWNERSHIP_CONTROLS" ]]; then
log 5 "Skipping get bucket ownership controls"
return 0
fi

log 6 "put_bucket_ownership_controls"
record_command "put-bucket-ownership-controls" "client:s3api"
assert [ $# -eq 2 ]
Expand Down
25 changes: 9 additions & 16 deletions tests/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,12 @@ if [[ -z "$VERSITYGW_TEST_ENV" ]] && [[ $BYPASS_ENV_FILE != "true" ]]; then
exit 1
fi

if ! ./tests/run.sh aws; then
exit 1
fi
if ! ./tests/run.sh s3; then
exit 1
fi
if ! ./tests/run.sh s3cmd; then
exit 1
fi
if ! ./tests/run.sh mc; then
exit 1
fi
if ! ./tests/run.sh rest; then
exit 1
fi
exit 0
status=0

for cmd in aws s3 s3cmd mc rest; do
if ! ./tests/run.sh "$cmd"; then
status=1
fi
done

exit $status
4 changes: 2 additions & 2 deletions tests/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ setup() {
# bats teardown function
teardown() {
# shellcheck disable=SC2154
if ! delete_bucket_or_contents_if_exists "$BUCKET_ONE_NAME"; then
if ! delete_bucket_or_contents_if_exists "s3api" "$BUCKET_ONE_NAME"; then
log 3 "error deleting bucket $BUCKET_ONE_NAME or contents"
fi
if ! delete_bucket_or_contents_if_exists "$BUCKET_TWO_NAME"; then
if ! delete_bucket_or_contents_if_exists "s3api" "$BUCKET_TWO_NAME"; then
log 3 "error deleting bucket $BUCKET_TWO_NAME or contents"
fi
if [ "$REMOVE_TEST_FILE_FOLDER" == "true" ]; then
Expand Down
50 changes: 25 additions & 25 deletions tests/test_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ test_common_copy_object() {
assert_success

if [[ $1 == 's3' ]]; then
copy_object "$1" "$test_file_folder/$object_name" "$BUCKET_ONE_NAME" "$object_name" || fail "failed to copy object to bucket one"
copy_object "$1" "$TEST_FILE_FOLDER/$object_name" "$BUCKET_ONE_NAME" "$object_name" || fail "failed to copy object to bucket one"
else
put_object "$1" "$test_file_folder/$object_name" "$BUCKET_ONE_NAME" "$object_name" || fail "failed to put object to bucket one"
put_object "$1" "$TEST_FILE_FOLDER/$object_name" "$BUCKET_ONE_NAME" "$object_name" || fail "failed to put object to bucket one"
fi
if [[ $1 == 's3' ]]; then
copy_object "$1" "s3://$BUCKET_ONE_NAME/$object_name" "$BUCKET_TWO_NAME" "$object_name" || fail "object not copied to bucket two"
Expand Down Expand Up @@ -151,7 +151,7 @@ test_common_put_object() {
assert_success
fi

run put_object "$1" "$test_file_folder/$2" "$BUCKET_ONE_NAME" "$2"
run put_object "$1" "$TEST_FILE_FOLDER/$2" "$BUCKET_ONE_NAME" "$2"
assert_success

if [ "$1" == 's3' ]; then
Expand Down Expand Up @@ -185,9 +185,9 @@ test_common_put_get_object() {
assert_success

if [[ $1 == 's3' ]]; then
copy_object "$1" "$test_file_folder/$object_name" "$BUCKET_ONE_NAME" "$object_name" || fail "failed to add object to bucket"
copy_object "$1" "$TEST_FILE_FOLDER/$object_name" "$BUCKET_ONE_NAME" "$object_name" || fail "failed to add object to bucket"
else
put_object "$1" "$test_file_folder/$object_name" "$BUCKET_ONE_NAME" "$object_name" || fail "failed to add object to bucket"
put_object "$1" "$TEST_FILE_FOLDER/$object_name" "$BUCKET_ONE_NAME" "$object_name" || fail "failed to add object to bucket"
fi
object_exists "$1" "$BUCKET_ONE_NAME" "$object_name" || fail "object not added to bucket"

Expand Down Expand Up @@ -268,15 +268,15 @@ test_common_list_objects() {
run create_test_files $object_one $object_two
assert_success

echo "test data" > "$test_file_folder"/"$object_one"
echo "test data 2" > "$test_file_folder"/"$object_two"
echo "test data" > "$TEST_FILE_FOLDER"/"$object_one"
echo "test data 2" > "$TEST_FILE_FOLDER"/"$object_two"

run setup_bucket "$1" "$BUCKET_ONE_NAME"
assert_success

put_object "$1" "$test_file_folder"/$object_one "$BUCKET_ONE_NAME" "$object_one" || local result_two=$?
put_object "$1" "$TEST_FILE_FOLDER"/$object_one "$BUCKET_ONE_NAME" "$object_one" || local result_two=$?
[[ result_two -eq 0 ]] || fail "Error adding object one"
put_object "$1" "$test_file_folder"/$object_two "$BUCKET_ONE_NAME" "$object_two" || local result_three=$?
put_object "$1" "$TEST_FILE_FOLDER"/$object_two "$BUCKET_ONE_NAME" "$object_two" || local result_three=$?
[[ result_three -eq 0 ]] || fail "Error adding object two"

list_objects "$1" "$BUCKET_ONE_NAME"
Expand Down Expand Up @@ -355,7 +355,7 @@ test_common_set_get_object_tags() {
run setup_bucket "$1" "$BUCKET_ONE_NAME"
assert_success

put_object "$1" "$test_file_folder"/"$bucket_file" "$BUCKET_ONE_NAME" "$bucket_file" || fail "Failed to add object to bucket '$BUCKET_ONE_NAME'"
put_object "$1" "$TEST_FILE_FOLDER"/"$bucket_file" "$BUCKET_ONE_NAME" "$bucket_file" || fail "Failed to add object to bucket '$BUCKET_ONE_NAME'"

get_object_tagging "$1" "$BUCKET_ONE_NAME" $bucket_file || fail "Error getting object tags"
if [[ $1 == 'aws' ]]; then
Expand Down Expand Up @@ -393,25 +393,25 @@ test_common_presigned_url_utf8_chars() {

run create_test_file "$bucket_file"
assert_success
dd if=/dev/urandom of="$test_file_folder/$bucket_file" bs=5M count=1 || fail "error creating test file"
dd if=/dev/urandom of="$TEST_FILE_FOLDER/$bucket_file" bs=5M count=1 || fail "error creating test file"

run setup_bucket "$1" "$BUCKET_ONE_NAME"
assert_success

put_object "$1" "$test_file_folder"/"$bucket_file" "$BUCKET_ONE_NAME" "$bucket_file" || put_result=$?
put_object "$1" "$TEST_FILE_FOLDER"/"$bucket_file" "$BUCKET_ONE_NAME" "$bucket_file" || put_result=$?
[[ $put_result -eq 0 ]] || fail "Failed to add object $bucket_file"

create_presigned_url "$1" "$BUCKET_ONE_NAME" "$bucket_file" || presigned_result=$?
[[ $presigned_result -eq 0 ]] || fail "presigned url creation failure"

error=$(curl -k -v "$presigned_url" -o "$test_file_folder"/"$bucket_file_copy") || curl_result=$?
error=$(curl -k -v "$presigned_url" -o "$TEST_FILE_FOLDER"/"$bucket_file_copy") || curl_result=$?
if [[ $curl_result -ne 0 ]]; then
fail "error downloading file with curl: $error"
fi
compare_files "$test_file_folder"/"$bucket_file" "$test_file_folder"/"$bucket_file_copy" || compare_result=$?
compare_files "$TEST_FILE_FOLDER"/"$bucket_file" "$TEST_FILE_FOLDER"/"$bucket_file_copy" || compare_result=$?
if [[ $compare_result -ne 0 ]]; then
echo "file one: $(cat "$test_file_folder"/"$bucket_file")"
echo "file two: $(cat "$test_file_folder"/"$bucket_file_copy")"
echo "file one: $(cat "$TEST_FILE_FOLDER"/"$bucket_file")"
echo "file two: $(cat "$TEST_FILE_FOLDER"/"$bucket_file_copy")"
fail "files don't match"
fi

Expand All @@ -430,7 +430,7 @@ test_common_list_objects_file_count() {
run setup_bucket "$1" "$BUCKET_ONE_NAME"
assert_success

put_object_multiple "$1" "$test_file_folder/file_*" "$BUCKET_ONE_NAME" || local put_result=$?
put_object_multiple "$1" "$TEST_FILE_FOLDER/file_*" "$BUCKET_ONE_NAME" || local put_result=$?
[[ $put_result -eq 0 ]] || fail "Failed to copy files to bucket"
list_objects "$1" "$BUCKET_ONE_NAME"
if [[ $LOG_LEVEL -ge 5 ]]; then
Expand All @@ -454,7 +454,7 @@ test_common_delete_object_tagging() {
run setup_bucket "$1" "$BUCKET_ONE_NAME"
assert_success

put_object "$1" "$test_file_folder"/"$bucket_file" "$BUCKET_ONE_NAME" "$bucket_file" || fail "Failed to add object to bucket"
put_object "$1" "$TEST_FILE_FOLDER"/"$bucket_file" "$BUCKET_ONE_NAME" "$bucket_file" || fail "Failed to add object to bucket"

put_object_tagging "$1" "$BUCKET_ONE_NAME" "$bucket_file" "$tag_key" "$tag_value" || fail "failed to add tags to object"

Expand Down Expand Up @@ -563,7 +563,7 @@ test_common_put_bucket_acl() {
grantee="{\"ID\": \"$username\", \"Type\": \"CanonicalUser\"}"
fi

cat <<EOF > "$test_file_folder"/"$acl_file"
cat <<EOF > "$TEST_FILE_FOLDER"/"$acl_file"
{
"Grants": [
{
Expand All @@ -578,15 +578,15 @@ cat <<EOF > "$test_file_folder"/"$acl_file"
EOF

log 6 "before 1st put acl"
put_bucket_acl_s3api "$BUCKET_ONE_NAME" "$test_file_folder"/"$acl_file" || fail "error putting first acl"
put_bucket_acl_s3api "$BUCKET_ONE_NAME" "$TEST_FILE_FOLDER"/"$acl_file" || fail "error putting first acl"
get_bucket_acl "$1" "$BUCKET_ONE_NAME" || fail "error retrieving second ACL"

log 5 "Acls after 1st put: $acl"
public_grants=$(echo "$acl" | grep -v "InsecureRequestWarning" | jq -r '.Grants[1]' 2>&1) || fail "error getting public grants: $public_grants"
permission=$(echo "$public_grants" | jq -r '.Permission' 2>&1) || fail "error getting permission: $permission"
[[ $permission == "READ" ]] || fail "incorrect permission ($permission)"

cat <<EOF > "$test_file_folder"/"$acl_file"
cat <<EOF > "$TEST_FILE_FOLDER"/"$acl_file"
{
"Grants": [
{
Expand All @@ -603,7 +603,7 @@ cat <<EOF > "$test_file_folder"/"$acl_file"
}
EOF

put_bucket_acl_s3api "$BUCKET_ONE_NAME" "$test_file_folder"/"$acl_file" || fail "error putting second acl"
put_bucket_acl_s3api "$BUCKET_ONE_NAME" "$TEST_FILE_FOLDER"/"$acl_file" || fail "error putting second acl"
get_bucket_acl "$1" "$BUCKET_ONE_NAME" || fail "error retrieving second ACL"

log 5 "Acls after 2nd put: $acl"
Expand Down Expand Up @@ -634,7 +634,7 @@ test_common_get_put_delete_bucket_policy() {
action="s3:GetObject"
resource="arn:aws:s3:::$BUCKET_ONE_NAME/*"

cat <<EOF > "$test_file_folder"/$policy_file
cat <<EOF > "$TEST_FILE_FOLDER"/$policy_file
{
"Version": "2012-10-17",
"Statement": [
Expand All @@ -647,14 +647,14 @@ test_common_get_put_delete_bucket_policy() {
]
}
EOF
log 5 "POLICY: $(cat "$test_file_folder/$policy_file")"
log 5 "POLICY: $(cat "$TEST_FILE_FOLDER/$policy_file")"

run setup_bucket "$1" "$BUCKET_ONE_NAME"
assert_success

check_for_empty_policy "$1" "$BUCKET_ONE_NAME" || fail "policy not empty"

put_bucket_policy "$1" "$BUCKET_ONE_NAME" "$test_file_folder"/"$policy_file" || fail "error putting bucket policy"
put_bucket_policy "$1" "$BUCKET_ONE_NAME" "$TEST_FILE_FOLDER"/"$policy_file" || fail "error putting bucket policy"

get_bucket_policy "$1" "$BUCKET_ONE_NAME" || fail "error getting bucket policy after setting"

Expand Down
3 changes: 3 additions & 0 deletions tests/test_mc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export RUN_MC=true

# delete-bucket-policy
@test "test_get_put_delete_bucket_policy" {
if [[ -n $SKIP_POLICY ]]; then
skip "will not test policy actions with SKIP_POLICY set"
fi
test_common_get_put_delete_bucket_policy "mc"
}

Expand Down
Loading

0 comments on commit d500274

Please sign in to comment.