diff --git a/compatibility-tests/.dockerignore b/compatibility-tests/.dockerignore new file mode 100644 index 0000000000..b4378da295 --- /dev/null +++ b/compatibility-tests/.dockerignore @@ -0,0 +1,8 @@ +node_modules/ +__pycache__/ +target/ +.git/ +*.md +test-results/ +.terraform/ +.terraform.lock.hcl diff --git a/compatibility-tests/.gitignore b/compatibility-tests/.gitignore index 0c755f4da0..b190c11dfc 100644 --- a/compatibility-tests/.gitignore +++ b/compatibility-tests/.gitignore @@ -36,6 +36,7 @@ lib/bats-assert/ # Test results test-results/ +test-results.xml # Rust sdk-test-rust/target/ @@ -45,6 +46,7 @@ sdk-test-go/floci-sdk-test-go # Terraform / OpenTofu .terraform/ +.terraform.lock.hcl *.tfstate *.tfstate.backup *.tfplan diff --git a/compatibility-tests/compat-cdk/run.sh b/compatibility-tests/compat-cdk/run.sh index 06e4767f59..17b1847ee7 100755 --- a/compatibility-tests/compat-cdk/run.sh +++ b/compatibility-tests/compat-cdk/run.sh @@ -1,15 +1,17 @@ #!/bin/bash -set -e +set -euo pipefail # Environment setup for Docker container export AWS_REGION=us-east-1 export AWS_DEFAULT_REGION=us-east-1 -export AWS_ACCESS_KEY_ID=test -export AWS_SECRET_ACCESS_KEY=test -export LOCALSTACK_HOSTNAME=floci -export EDGE_PORT=4566 -export FLOCI_ENDPOINT=http://floci:4566 -export AWS_ENDPOINT_URL=http://floci:4566 +export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID:-test}" +export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY:-test}" +export FLOCI_ENDPOINT="${FLOCI_ENDPOINT:-http://localhost:4566}" +export AWS_ENDPOINT_URL="$FLOCI_ENDPOINT" +# CDK-specific: derive hostname and port from endpoint +export LOCALSTACK_HOSTNAME="${FLOCI_ENDPOINT#http://}" +export LOCALSTACK_HOSTNAME="${LOCALSTACK_HOSTNAME%:*}" +export EDGE_PORT="${FLOCI_ENDPOINT##*:}" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" diff --git a/compatibility-tests/compat-opentofu/.terraform.lock.hcl b/compatibility-tests/compat-opentofu/.terraform.lock.hcl deleted file mode 100644 index cdc1668d41..0000000000 --- a/compatibility-tests/compat-opentofu/.terraform.lock.hcl +++ /dev/null @@ -1,25 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/hashicorp/aws" { - version = "5.100.0" - constraints = "~> 5.0" - hashes = [ - "h1:Ijt7pOlB7Tr7maGQIqtsLFbl7pSMIj06TVdkoSBcYOw=", - "zh:054b8dd49f0549c9a7cc27d159e45327b7b65cf404da5e5a20da154b90b8a644", - "zh:0b97bf8d5e03d15d83cc40b0530a1f84b459354939ba6f135a0086c20ebbe6b2", - "zh:1589a2266af699cbd5d80737a0fe02e54ec9cf2ca54e7e00ac51c7359056f274", - "zh:6330766f1d85f01ae6ea90d1b214b8b74cc8c1badc4696b165b36ddd4cc15f7b", - "zh:7c8c2e30d8e55291b86fcb64bdf6c25489d538688545eb48fd74ad622e5d3862", - "zh:99b1003bd9bd32ee323544da897148f46a527f622dc3971af63ea3e251596342", - "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", - "zh:9f8b909d3ec50ade83c8062290378b1ec553edef6a447c56dadc01a99f4eaa93", - "zh:aaef921ff9aabaf8b1869a86d692ebd24fbd4e12c21205034bb679b9caf883a2", - "zh:ac882313207aba00dd5a76dbd572a0ddc818bb9cbf5c9d61b28fe30efaec951e", - "zh:bb64e8aff37becab373a1a0cc1080990785304141af42ed6aa3dd4913b000421", - "zh:dfe495f6621df5540d9c92ad40b8067376350b005c637ea6efac5dc15028add4", - "zh:f0ddf0eaf052766cfe09dea8200a946519f653c384ab4336e2a4a64fdd6310e9", - "zh:f1b7e684f4c7ae1eed272b6de7d2049bb87a0275cb04dbb7cda6636f600699c9", - "zh:ff461571e3f233699bf690db319dfe46aec75e58726636a0d97dd9ac6e32fb70", - ] -} diff --git a/compatibility-tests/compat-opentofu/Dockerfile b/compatibility-tests/compat-opentofu/Dockerfile index 996d35dfce..0bbfea289c 100644 --- a/compatibility-tests/compat-opentofu/Dockerfile +++ b/compatibility-tests/compat-opentofu/Dockerfile @@ -5,7 +5,7 @@ FROM amazon/aws-cli:2.15.52 # Copy tofu binary from official OpenTofu image COPY --from=opentofu /usr/local/bin/tofu /usr/local/bin/tofu -RUN yum install -y git jq >/dev/null 2>&1 +RUN yum install -y git jq WORKDIR /app diff --git a/compatibility-tests/compat-opentofu/main.tf b/compatibility-tests/compat-opentofu/main.tf index c41dc19b26..6a318b67c5 100644 --- a/compatibility-tests/compat-opentofu/main.tf +++ b/compatibility-tests/compat-opentofu/main.tf @@ -1,3 +1,5 @@ +# NOTE: Keep resource definitions in sync with ../compat-terraform/main.tf + # ── S3 Bucket ────────────────────────────────────────────────────────────── resource "aws_s3_bucket" "app" { bucket = "floci-compat-app" diff --git a/compatibility-tests/compat-opentofu/run.sh b/compatibility-tests/compat-opentofu/run.sh index ce463ee8e2..2678aa3207 100755 --- a/compatibility-tests/compat-opentofu/run.sh +++ b/compatibility-tests/compat-opentofu/run.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -euo pipefail # Environment setup for Docker container export AWS_REGION=us-east-1 diff --git a/compatibility-tests/compat-terraform/Dockerfile b/compatibility-tests/compat-terraform/Dockerfile index 345c667448..53cc87b4d1 100644 --- a/compatibility-tests/compat-terraform/Dockerfile +++ b/compatibility-tests/compat-terraform/Dockerfile @@ -5,7 +5,7 @@ FROM amazon/aws-cli:2.15.52 # Copy terraform binary from official Terraform image COPY --from=terraform /bin/terraform /usr/local/bin/terraform -RUN yum install -y git jq >/dev/null 2>&1 +RUN yum install -y git jq WORKDIR /app diff --git a/compatibility-tests/compat-terraform/main.tf b/compatibility-tests/compat-terraform/main.tf index 9c7bbc2e40..97aa283aa6 100644 --- a/compatibility-tests/compat-terraform/main.tf +++ b/compatibility-tests/compat-terraform/main.tf @@ -1,3 +1,5 @@ +# NOTE: Keep resource definitions in sync with ../compat-opentofu/main.tf + # -- S3 Bucket ------------------------------------------------------------------ resource "aws_s3_bucket" "app" { bucket = "floci-compat-app" diff --git a/compatibility-tests/compat-terraform/run.sh b/compatibility-tests/compat-terraform/run.sh index ce463ee8e2..2678aa3207 100755 --- a/compatibility-tests/compat-terraform/run.sh +++ b/compatibility-tests/compat-terraform/run.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -e +set -euo pipefail # Environment setup for Docker container export AWS_REGION=us-east-1 diff --git a/compatibility-tests/sdk-test-awscli/Dockerfile b/compatibility-tests/sdk-test-awscli/Dockerfile index a77d33090c..89317c184f 100644 --- a/compatibility-tests/sdk-test-awscli/Dockerfile +++ b/compatibility-tests/sdk-test-awscli/Dockerfile @@ -1,6 +1,6 @@ FROM amazon/aws-cli:latest -RUN yum install -y git jq bc >/dev/null 2>&1 +RUN yum install -y git jq bc WORKDIR /app diff --git a/compatibility-tests/sdk-test-node/tests/setup.ts b/compatibility-tests/sdk-test-node/tests/setup.ts index 9219dbbcab..f027fee380 100644 --- a/compatibility-tests/sdk-test-node/tests/setup.ts +++ b/compatibility-tests/sdk-test-node/tests/setup.ts @@ -100,11 +100,12 @@ function makeCrcTable(): Uint32Array { return table; } +const crcTable = makeCrcTable(); + function crc32(buf: Buffer): number { - const table = makeCrcTable(); let crc = 0xffffffff; for (let i = 0; i < buf.length; i++) { - crc = (crc >>> 8) ^ table[(crc ^ buf[i]) & 0xff]; + crc = (crc >>> 8) ^ crcTable[(crc ^ buf[i]) & 0xff]; } return (crc ^ 0xffffffff) >>> 0; } diff --git a/compatibility-tests/sdk-test-python/conftest.py b/compatibility-tests/sdk-test-python/conftest.py index f5126a74d3..6f927e0b0d 100644 --- a/compatibility-tests/sdk-test-python/conftest.py +++ b/compatibility-tests/sdk-test-python/conftest.py @@ -5,9 +5,14 @@ import uuid import io import zipfile +import logging + import boto3 import pytest from botocore.config import Config +from botocore.exceptions import ClientError + +logger = logging.getLogger(__name__) @pytest.fixture(scope="session") @@ -176,8 +181,8 @@ def test_bucket(s3_client, unique_name): for obj in page["Contents"]: s3_client.delete_object(Bucket=bucket_name, Key=obj["Key"]) s3_client.delete_bucket(Bucket=bucket_name) - except Exception: - pass + except ClientError as e: + logger.warning("Failed to clean up S3 bucket %s: %s", bucket_name, e) @pytest.fixture @@ -192,8 +197,8 @@ def test_queue(sqs_client, unique_name): # Cleanup try: sqs_client.delete_queue(QueueUrl=queue_url) - except Exception: - pass + except ClientError as e: + logger.warning("Failed to clean up SQS queue %s: %s", queue_url, e) @pytest.fixture @@ -208,8 +213,8 @@ def test_topic(sns_client, unique_name): # Cleanup try: sns_client.delete_topic(TopicArn=topic_arn) - except Exception: - pass + except ClientError as e: + logger.warning("Failed to clean up SNS topic %s: %s", topic_arn, e) @pytest.fixture @@ -232,5 +237,5 @@ def test_table(dynamodb_client, unique_name): # Cleanup try: dynamodb_client.delete_table(TableName=table_name) - except Exception: - pass + except ClientError as e: + logger.warning("Failed to clean up DynamoDB table %s: %s", table_name, e) diff --git a/compatibility-tests/sdk-test-python/pytest.ini b/compatibility-tests/sdk-test-python/pytest.ini index d3854cf44d..d8a7be7e46 100644 --- a/compatibility-tests/sdk-test-python/pytest.ini +++ b/compatibility-tests/sdk-test-python/pytest.ini @@ -3,3 +3,4 @@ testpaths = tests python_files = test_*.py python_functions = test_* addopts = -v --tb=short --junit-xml=test-results/junit.xml +timeout = 120 diff --git a/compatibility-tests/sdk-test-python/requirements.txt b/compatibility-tests/sdk-test-python/requirements.txt index 2c0b4d68d4..8e04cc9645 100644 --- a/compatibility-tests/sdk-test-python/requirements.txt +++ b/compatibility-tests/sdk-test-python/requirements.txt @@ -1,3 +1,4 @@ boto3==1.37.1 botocore==1.37.1 pytest>=8.0.0 +pytest-timeout>=2.3.0 diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java index c347395902..faf96c3195 100644 --- a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java +++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java @@ -1263,9 +1263,14 @@ public class S3Controller { String source = copySource.startsWith("/") ? copySource.substring(1) : copySource; // URL decode the entire source first, then split - String decodedSource = URLDecoder.decode(source, StandardCharsets.UTF_8); + String decodedSource; + try { + decodedSource = URLDecoder.decode(source, StandardCharsets.UTF_8); + } catch (IllegalArgumentException e) { + throw new AwsException("InvalidArgument", "Invalid copy source: " + copySource, 400); + } int slashIndex = decodedSource.indexOf('/'); - if (slashIndex < 0) { + if (slashIndex <= 0) { throw new AwsException("InvalidArgument", "Invalid copy source: " + copySource, 400); } String sourceBucket = decodedSource.substring(0, slashIndex); @@ -1294,9 +1299,14 @@ public class S3Controller { String source = copySource.startsWith("/") ? copySource.substring(1) : copySource; // URL decode the entire source first, then split. - String decodedSource = URLDecoder.decode(source, StandardCharsets.UTF_8); + String decodedSource; + try { + decodedSource = URLDecoder.decode(source, StandardCharsets.UTF_8); + } catch (IllegalArgumentException e) { + throw new AwsException("InvalidArgument", "Invalid copy source: " + copySource, 400); + } int slashIndex = decodedSource.indexOf('/'); - if (slashIndex < 0) { + if (slashIndex <= 0) { throw new AwsException("InvalidArgument", "Invalid copy source: " + copySource, 400); } String sourceBucket = decodedSource.substring(0, slashIndex); diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java index 1c822f09c3..579752c095 100644 --- a/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3IntegrationTest.java @@ -371,6 +371,30 @@ class S3IntegrationTest { given().delete("/" + bucket); } + @Test + @Order(21) + void copyObjectWithMalformedEncodedSourceReturns400() { + given() + .header("x-amz-copy-source", "/test-bucket/%ZZinvalid") + .when() + .put("/test-bucket/dest-key") + .then() + .statusCode(400) + .body(containsString("InvalidArgument")); + } + + @Test + @Order(22) + void copyObjectWithEmptyBucketReturns400() { + given() + .header("x-amz-copy-source", "/key-only-no-bucket") + .when() + .put("/test-bucket/dest-key") + .then() + .statusCode(400) + .body(containsString("InvalidArgument")); + } + @Test @Order(21) void putLargeObject() {