Files
floci/compatibility-tests/sdk-test-awscli/test/s3.bats
T
Chiara Forresi 96d16de998 feat(s3): add Intelligent-Tiering configuration CRUD (#2997)
* feat(s3): add Intelligent-Tiering configuration CRUD

Add AWS S3 Intelligent-Tiering configuration management through the
real REST XML subresource (?intelligent-tiering), mirroring the existing
metrics configuration pattern.

Operations:
- PutBucketIntelligentTieringConfiguration (PUT, 204)
- GetBucketIntelligentTieringConfiguration (GET by id)
- ListBucketIntelligentTieringConfigurations (GET without id)
- DeleteBucketIntelligentTieringConfiguration (DELETE, 204)

The parser validates Id, Status (Enabled/Disabled), optional Filter
(Prefix/Tag/And), and one or more Tiering entries (AccessTier + positive
Days), re-serializing through XmlBuilder/XmlParser/AwsNamespaces.S3 so
responses are built by floci rather than echoing the request body.
Malformed bodies return MalformedXML; missing configurations return
NoSuchConfiguration.

Configurations are stored on the Bucket model keyed by id (nullable map
for backward-compatible deserialization of older snapshots), persisted
through StorageFactory, and synchronized on the bucket monitor with the
same requireSameRecord guard as metrics to survive concurrent puts and
bucket delete/recreate races.

Tests:
- S3IntelligentTieringConfigurationTest: parser unit tests
- S3ServiceTest: service lifecycle, isolation, persistence, concurrency
- S3IntelligentTieringConfigurationIntegrationTest: REST integration
- compatibility-tests/sdk-test-awscli: AWS CLI bats coverage

* refactor(s3): rename METRICS_XML_DECLARATION to S3_XML_DECLARATION

The XML declaration constant is shared by both metrics and
intelligent-tiering configuration responses, so the name should reflect
its S3-wide scope rather than implying it is metrics-specific.

* fix(s3): enforce auth and validate Days overflow on intelligent-tiering

Address review feedback on PR #2997:

- PUT and DELETE ?intelligent-tiering now enforce S3 authorization via
  a new authorizeBucketWrite method, closing the bypass where mutations
  skipped the auth applied to reads.
- Days values above Integer.MAX_VALUE no longer throw NumberFormatException
  and return 500 InternalError; they are rejected as 400 MalformedXML.
- A PUT without a request body returns 400 MalformedXML instead of NPE/500.

Tests: unit coverage for Days overflow, integration coverage for empty body.

* fix(s3): enforce tier-specific Days range on intelligent-tiering

AWS enforces a tier-specific Days range for S3 Intelligent-Tiering:
- ARCHIVE_ACCESS: 90 to 730 days
- DEEP_ARCHIVE_ACCESS: 180 to 730 days

Out-of-range values now return InvalidArgument with ArgumentName and
ArgumentValue in the XML error body, matching the real S3 error shape.

Add unit and integration tests covering below-minimum, above-maximum,
boundary acceptance, and the full XML error response.

* refactor(s3): extract Days range constants in intelligent-tiering

Replace repeated magic numbers (90, 180, 730) with named constants
ARCHIVE_ACCESS_MIN_DAYS, DEEP_ARCHIVE_ACCESS_MIN_DAYS, and MAX_DAYS.
Pass min into daysOutOfRange instead of recomputing it, and use an
import for LinkedHashMap.
2026-09-04 09:06:15 -04:00

397 lines
13 KiB
Bash

#!/usr/bin/env bats
# S3 tests
setup() {
load 'test_helper/common-setup'
BUCKET="bats-test-bucket-$(unique_name)"
}
teardown() {
# Clean up all objects in bucket
aws_cmd s3 rm "s3://$BUCKET" --recursive >/dev/null 2>&1 || true
aws_cmd s3api delete-bucket --bucket "$BUCKET" >/dev/null 2>&1 || true
}
@test "S3: create bucket" {
run aws_cmd s3api create-bucket --bucket "$BUCKET"
assert_success
}
@test "S3: list buckets" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
run aws_cmd s3api list-buckets
assert_success
found=$(echo "$output" | jq --arg name "$BUCKET" '.Buckets | any(.Name == $name)')
[ "$found" = "true" ]
}
@test "S3: put object" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
local body_file
body_file=$(mktemp)
echo -n "hello-s3-bats" > "$body_file"
run aws_cmd s3api put-object --bucket "$BUCKET" --key "test.txt" --body "$body_file"
assert_success
rm -f "$body_file"
}
@test "S3: get object" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
local body_file get_file
body_file=$(mktemp)
get_file=$(mktemp)
echo -n "hello-s3-bats" > "$body_file"
aws_cmd s3api put-object --bucket "$BUCKET" --key "test.txt" --body "$body_file" >/dev/null
run aws_cmd s3api get-object --bucket "$BUCKET" --key "test.txt" "$get_file"
assert_success
content=$(cat "$get_file")
[ "$content" = "hello-s3-bats" ]
rm -f "$body_file" "$get_file"
}
@test "S3: head object" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
local body_file
body_file=$(mktemp)
echo -n "hello-s3-bats" > "$body_file"
aws_cmd s3api put-object --bucket "$BUCKET" --key "test.txt" --body "$body_file" >/dev/null
run aws_cmd s3api head-object --bucket "$BUCKET" --key "test.txt"
assert_success
length=$(json_get "$output" '.ContentLength')
[ "$length" = "13" ]
rm -f "$body_file"
}
@test "S3: list objects" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
local body_file
body_file=$(mktemp)
echo -n "hello" > "$body_file"
aws_cmd s3api put-object --bucket "$BUCKET" --key "test.txt" --body "$body_file" >/dev/null
run aws_cmd s3api list-objects-v2 --bucket "$BUCKET"
assert_success
found=$(echo "$output" | jq '.Contents | any(.Key == "test.txt")')
[ "$found" = "true" ]
rm -f "$body_file"
}
@test "S3: copy object" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
local body_file
body_file=$(mktemp)
echo -n "hello" > "$body_file"
aws_cmd s3api put-object --bucket "$BUCKET" --key "src.txt" --body "$body_file" >/dev/null
run aws_cmd s3api copy-object --bucket "$BUCKET" --copy-source "$BUCKET/src.txt" --key "dst.txt"
assert_success
rm -f "$body_file"
}
@test "S3: put and get object tagging" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
local body_file
body_file=$(mktemp)
echo -n "hello" > "$body_file"
aws_cmd s3api put-object --bucket "$BUCKET" --key "test.txt" --body "$body_file" >/dev/null
run aws_cmd s3api put-object-tagging \
--bucket "$BUCKET" \
--key "test.txt" \
--tagging 'TagSet=[{Key=env,Value=test}]'
assert_success
run aws_cmd s3api get-object-tagging --bucket "$BUCKET" --key "test.txt"
assert_success
found=$(echo "$output" | jq '.TagSet | any(.Key == "env" and .Value == "test")')
[ "$found" = "true" ]
rm -f "$body_file"
}
@test "S3: delete object" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
local body_file
body_file=$(mktemp)
echo -n "hello" > "$body_file"
aws_cmd s3api put-object --bucket "$BUCKET" --key "test.txt" --body "$body_file" >/dev/null
run aws_cmd s3api delete-object --bucket "$BUCKET" --key "test.txt"
assert_success
rm -f "$body_file"
}
@test "S3: delete bucket" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
run aws_cmd s3api delete-bucket --bucket "$BUCKET"
assert_success
}
# --- S3 Versioning Tests ---
@test "S3: put bucket versioning" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
run aws_cmd s3api put-bucket-versioning \
--bucket "$BUCKET" \
--versioning-configuration Status=Enabled
assert_success
}
@test "S3: versioned objects have version IDs" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
aws_cmd s3api put-bucket-versioning \
--bucket "$BUCKET" \
--versioning-configuration Status=Enabled >/dev/null
local body_file
body_file=$(mktemp)
echo -n "version-one" > "$body_file"
run aws_cmd s3api put-object --bucket "$BUCKET" --key "ver.txt" --body "$body_file"
assert_success
v1=$(json_get "$output" '.VersionId')
[ -n "$v1" ]
echo -n "version-two" > "$body_file"
run aws_cmd s3api put-object --bucket "$BUCKET" --key "ver.txt" --body "$body_file"
assert_success
v2=$(json_get "$output" '.VersionId')
[ -n "$v2" ]
[ "$v1" != "$v2" ]
rm -f "$body_file"
}
# --- S3 Multipart Upload Tests ---
@test "S3: create multipart upload" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
run aws_cmd s3api create-multipart-upload \
--bucket "$BUCKET" \
--key "multipart.bin"
assert_success
upload_id=$(json_get "$output" '.UploadId')
[ -n "$upload_id" ]
# Cleanup: abort the upload
aws_cmd s3api abort-multipart-upload \
--bucket "$BUCKET" \
--key "multipart.bin" \
--upload-id "$upload_id" >/dev/null 2>&1 || true
}
@test "S3: upload part" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
output=$(aws_cmd s3api create-multipart-upload \
--bucket "$BUCKET" \
--key "multipart.bin")
upload_id=$(json_get "$output" '.UploadId')
local part_file
part_file=$(mktemp)
echo -n "part-one-data" > "$part_file"
run aws_cmd s3api upload-part \
--bucket "$BUCKET" \
--key "multipart.bin" \
--upload-id "$upload_id" \
--part-number 1 \
--body "$part_file"
assert_success
etag=$(json_get "$output" '.ETag')
[ -n "$etag" ]
rm -f "$part_file"
aws_cmd s3api abort-multipart-upload \
--bucket "$BUCKET" \
--key "multipart.bin" \
--upload-id "$upload_id" >/dev/null 2>&1 || true
}
@test "S3: complete multipart upload" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
output=$(aws_cmd s3api create-multipart-upload \
--bucket "$BUCKET" \
--key "multipart.bin")
upload_id=$(json_get "$output" '.UploadId')
local part1_file part2_file
part1_file=$(mktemp)
part2_file=$(mktemp)
echo -n "part-one" > "$part1_file"
echo -n "part-two" > "$part2_file"
output=$(aws_cmd s3api upload-part \
--bucket "$BUCKET" \
--key "multipart.bin" \
--upload-id "$upload_id" \
--part-number 1 \
--body "$part1_file")
etag1=$(json_get "$output" '.ETag')
output=$(aws_cmd s3api upload-part \
--bucket "$BUCKET" \
--key "multipart.bin" \
--upload-id "$upload_id" \
--part-number 2 \
--body "$part2_file")
etag2=$(json_get "$output" '.ETag')
local mp_file
mp_file=$(mktemp)
cat > "$mp_file" <<EOF
{
"Parts": [
{ "ETag": $etag1, "PartNumber": 1 },
{ "ETag": $etag2, "PartNumber": 2 }
]
}
EOF
run aws_cmd s3api complete-multipart-upload \
--bucket "$BUCKET" \
--key "multipart.bin" \
--upload-id "$upload_id" \
--multipart-upload "file://$mp_file"
assert_success
rm -f "$part1_file" "$part2_file" "$mp_file"
}
# --- S3 Large File Test ---
@test "S3: put object 25 MB" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
local large_file
large_file=$(mktemp)
dd if=/dev/zero of="$large_file" bs=1048576 count=25 2>/dev/null
run aws_cmd s3api put-object \
--bucket "$BUCKET" \
--key "large-25mb.bin" \
--body "$large_file"
assert_success
run aws_cmd s3api head-object \
--bucket "$BUCKET" \
--key "large-25mb.bin"
assert_success
length=$(json_get "$output" '.ContentLength')
[ "$length" = "26214400" ]
rm -f "$large_file"
}
@test "S3: metrics configurations round-trip and never touch the bucket" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
run aws_cmd s3api put-bucket-metrics-configuration \
--bucket "$BUCKET" --id EntireBucket --metrics-configuration 'Id=EntireBucket'
assert_success
run aws_cmd s3api get-bucket-metrics-configuration --bucket "$BUCKET" --id EntireBucket
assert_success
[ "$(json_get "$output" '.MetricsConfiguration.Id')" = "EntireBucket" ]
run aws_cmd s3api put-bucket-metrics-configuration \
--bucket "$BUCKET" --id Filtered \
--metrics-configuration 'Id=Filtered,Filter={And={Prefix=logs/,Tags=[{Key=env,Value=prod}]}}'
assert_success
run aws_cmd s3api list-bucket-metrics-configurations --bucket "$BUCKET"
assert_success
[ "$(json_get "$output" '.MetricsConfigurationList | length')" = "2" ]
[ "$(json_get "$output" '.MetricsConfigurationList[1].Filter.And.Prefix')" = "logs/" ]
[ "$(json_get "$output" '.MetricsConfigurationList[1].Filter.And.Tags[0].Key')" = "env" ]
# A sub-resource DELETE removes only that configuration; the bucket must survive it.
run aws_cmd s3api delete-bucket-metrics-configuration --bucket "$BUCKET" --id EntireBucket
assert_success
run aws_cmd s3api head-bucket --bucket "$BUCKET"
assert_success
run aws_cmd s3api get-bucket-metrics-configuration --bucket "$BUCKET" --id EntireBucket
assert_failure
assert_output --partial "NoSuchConfiguration"
}
@test "S3: intelligent-tiering configurations round-trip and never touch the bucket" {
aws_cmd s3api create-bucket --bucket "$BUCKET" >/dev/null
run aws_cmd s3api put-bucket-intelligent-tiering-configuration \
--bucket "$BUCKET" --id EntireBucket \
--intelligent-tiering-configuration 'Id=EntireBucket,Status=Enabled,Tierings=[{AccessTier=ARCHIVE_ACCESS,Days=90}]'
assert_success
run aws_cmd s3api get-bucket-intelligent-tiering-configuration --bucket "$BUCKET" --id EntireBucket
assert_success
[ "$(json_get "$output" '.IntelligentTieringConfiguration.Id')" = "EntireBucket" ]
[ "$(json_get "$output" '.IntelligentTieringConfiguration.Status')" = "Enabled" ]
[ "$(json_get "$output" '.IntelligentTieringConfiguration.Tierings[0].AccessTier')" = "ARCHIVE_ACCESS" ]
[ "$(json_get "$output" '.IntelligentTieringConfiguration.Tierings[0].Days')" = "90" ]
run aws_cmd s3api put-bucket-intelligent-tiering-configuration \
--bucket "$BUCKET" --id Filtered \
--intelligent-tiering-configuration 'Id=Filtered,Filter={And={Prefix=logs/,Tags=[{Key=env,Value=prod}]}},Status=Disabled,Tierings=[{AccessTier=ARCHIVE_ACCESS,Days=90},{AccessTier=DEEP_ARCHIVE_ACCESS,Days=180}]'
assert_success
run aws_cmd s3api list-bucket-intelligent-tiering-configurations --bucket "$BUCKET"
assert_success
[ "$(json_get "$output" '.IntelligentTieringConfigurationList | length')" = "2" ]
[ "$(json_get "$output" '.IntelligentTieringConfigurationList[1].Filter.And.Prefix')" = "logs/" ]
[ "$(json_get "$output" '.IntelligentTieringConfigurationList[1].Filter.And.Tags[0].Key')" = "env" ]
[ "$(json_get "$output" '.IntelligentTieringConfigurationList[1].Status')" = "Disabled" ]
[ "$(json_get "$output" '.IntelligentTieringConfigurationList[1].Tierings | length')" = "2" ]
# Putting the same id replaces rather than duplicates.
run aws_cmd s3api put-bucket-intelligent-tiering-configuration \
--bucket "$BUCKET" --id EntireBucket \
--intelligent-tiering-configuration 'Id=EntireBucket,Status=Disabled,Tierings=[{AccessTier=DEEP_ARCHIVE_ACCESS,Days=180}]'
assert_success
run aws_cmd s3api get-bucket-intelligent-tiering-configuration --bucket "$BUCKET" --id EntireBucket
assert_success
[ "$(json_get "$output" '.IntelligentTieringConfiguration.Status')" = "Disabled" ]
[ "$(json_get "$output" '.IntelligentTieringConfiguration.Tierings[0].AccessTier')" = "DEEP_ARCHIVE_ACCESS" ]
run aws_cmd s3api list-bucket-intelligent-tiering-configurations --bucket "$BUCKET"
assert_success
[ "$(json_get "$output" '.IntelligentTieringConfigurationList | length')" = "2" ]
# A sub-resource DELETE removes only that configuration; the bucket must survive it.
run aws_cmd s3api delete-bucket-intelligent-tiering-configuration --bucket "$BUCKET" --id EntireBucket
assert_success
run aws_cmd s3api head-bucket --bucket "$BUCKET"
assert_success
run aws_cmd s3api get-bucket-intelligent-tiering-configuration --bucket "$BUCKET" --id EntireBucket
assert_failure
assert_output --partial "NoSuchConfiguration"
}