mirror of
https://github.com/versity/versitygw.git
synced 2026-08-16 12:16:14 +00:00
124 lines
4.0 KiB
Bash
Executable File
124 lines
4.0 KiB
Bash
Executable File
#!/usr/bin/env bats
|
|
|
|
# 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.
|
|
|
|
load ./bats-support/load
|
|
load ./bats-assert/load
|
|
|
|
source ./tests/commands/put_public_access_block.sh
|
|
source ./tests/drivers/create_bucket/create_bucket_rest.sh
|
|
source ./tests/drivers/put_bucket_website/put_bucket_website_rest.sh
|
|
source ./tests/drivers/cloudfront.sh
|
|
source ./tests/drivers/string.sh
|
|
source ./tests/setup.sh
|
|
|
|
@test "PutBucketWebsite - empty payload" {
|
|
local bucket_name
|
|
|
|
run setup_bucket_v3 "$BUCKET_ONE_NAME"
|
|
assert_success
|
|
bucket_name="$output"
|
|
|
|
run send_rest_go_command_expect_error "400" "MissingRequestBodyError" "Request Body is empty" "-bucketName" "$bucket_name" "-method" "PUT" "-query" "website"
|
|
assert_success
|
|
}
|
|
|
|
@test "PutBucketWebsite - XML message with empty WebsiteConfiguration struct" {
|
|
if [ "$DIRECT" != "true" ]; then
|
|
skip "https://github.com/versity/versitygw/issues/2260"
|
|
fi
|
|
local bucket_name
|
|
|
|
run setup_bucket_v3 "$BUCKET_ONE_NAME"
|
|
assert_success
|
|
bucket_name="$output"
|
|
|
|
run send_rest_go_command_expect_error "400" "InvalidArgument" "A value for IndexDocument Suffix must be provided if RedirectAllRequestsTo is empty" \
|
|
"-commandType" "putBucketWebsiteConfiguration" "-bucketName" "$bucket_name" "-websiteConfiguration" "{}"
|
|
assert_success
|
|
}
|
|
|
|
@test "PutBucketWebsite - HTTP call with HTTPS enabled does not return empty response" {
|
|
if [ "$DIRECT" != "true" ]; then
|
|
skip "https://github.com/versity/versitygw/issues/2261"
|
|
fi
|
|
distribution_created=false
|
|
|
|
local bucket_name policy_file distribution_domain http_domain
|
|
|
|
run setup_bucket_v3 "$BUCKET_ONE_NAME"
|
|
assert_success
|
|
bucket_name="$output"
|
|
|
|
run create_website_with_random_string "$bucket_name"
|
|
assert_success
|
|
random_string="$output"
|
|
|
|
if [ "$DIRECT" == "true" ]; then
|
|
run put_public_access_block "$bucket_name" "BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false"
|
|
assert_success
|
|
fi
|
|
|
|
run setup_policy_with_single_statement_v2 "2012-10-17" "Allow" "*" "s3:GetObject" "arn:aws:s3:::$bucket_name/*"
|
|
assert_success
|
|
policy_file="$output"
|
|
|
|
run put_bucket_policy "rest" "$bucket_name" "$TEST_FILE_FOLDER"/"$policy_file"
|
|
assert_success
|
|
|
|
if [ "$DIRECT" == "true" ]; then
|
|
run create_cloudfront_distribution "$bucket_name" "index.html" "${bucket_name}.s3-website.us-east-1.amazonaws.com"
|
|
assert_success
|
|
# shellcheck disable=SC2034
|
|
distribution_created=true
|
|
distribution_domain="$output"
|
|
http_domain="${distribution_domain/https:\/\//http:\/\/}"
|
|
else
|
|
http_domain="${AWS_ENDPOINT_URL/https:\/\//http:\/\/}"
|
|
fi
|
|
|
|
run curl -ks "${http_domain}"
|
|
assert_success
|
|
assert_output -p "301 Moved Permanently"
|
|
}
|
|
|
|
@test "PutBucketWebsite - IndexDocument suffix" {
|
|
local bucket_name policy_file random_string
|
|
|
|
run setup_bucket_v3 "$BUCKET_ONE_NAME"
|
|
assert_success
|
|
bucket_name="$output"
|
|
|
|
run create_website_with_random_string "$bucket_name"
|
|
assert_success
|
|
random_string="$output"
|
|
|
|
if [ "$DIRECT" == "true" ]; then
|
|
run put_public_access_block "$bucket_name" "BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false"
|
|
assert_success
|
|
fi
|
|
|
|
run setup_policy_with_single_statement_v2 "2012-10-17" "Allow" "*" "s3:GetObject" "arn:aws:s3:::$bucket_name/*"
|
|
assert_success
|
|
policy_file="$output"
|
|
|
|
run put_bucket_policy "rest" "$bucket_name" "$TEST_FILE_FOLDER"/"$policy_file"
|
|
assert_success
|
|
|
|
run curl -ks "https://${bucket_name}.${WEBSITE_DOMAIN}${WEBSITE}"
|
|
assert_success
|
|
assert_output "$random_string"
|
|
}
|