diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3Test.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3Test.java index c62ee6470b..ef8d60e19f 100644 --- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3Test.java +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/S3Test.java @@ -257,10 +257,10 @@ class S3Test { void deleteBucketTagging() { s3.deleteBucketTagging(DeleteBucketTaggingRequest.builder().bucket(BUCKET).build()); - GetBucketTaggingResponse response = s3.getBucketTagging( - GetBucketTaggingRequest.builder().bucket(BUCKET).build()); - - assertThat(response.tagSet()).isEmpty(); + assertThatThrownBy(() -> s3.getBucketTagging( + GetBucketTaggingRequest.builder().bucket(BUCKET).build())) + .isInstanceOfSatisfying(S3Exception.class, + e -> assertThat(e.awsErrorDetails().errorCode()).isEqualTo("NoSuchTagSet")); } @Test 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 61f5fc4302..276a9cb067 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 @@ -2119,6 +2119,9 @@ public class S3Controller { private Response handleGetBucketTagging(String bucket) { Map tags = s3Service.getBucketTagging(bucket); + if (tags.isEmpty()) { + throw new AwsException("NoSuchTagSet", "The TagSet does not exist", 404); + } return Response.ok(buildTaggingXml(tags)).type(MediaType.APPLICATION_XML).build(); } diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3AuthEnforcementIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3AuthEnforcementIntegrationTest.java index 081102a44e..a352661290 100644 --- a/src/test/java/io/github/hectorvent/floci/services/s3/S3AuthEnforcementIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3AuthEnforcementIntegrationTest.java @@ -1737,8 +1737,8 @@ class S3AuthEnforcementIntegrationTest { .when() .get("/" + BUCKET_CONFIG_BUCKET + "?tagging") .then() - .statusCode(200) - .body(not(containsString("k"))); + .statusCode(404) + .body(containsString("NoSuchTagSet")); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3BucketTaggingIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3BucketTaggingIntegrationTest.java new file mode 100644 index 0000000000..cfc560822e --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3BucketTaggingIntegrationTest.java @@ -0,0 +1,45 @@ +package io.github.hectorvent.floci.services.s3; + +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.containsString; + +@QuarkusTest +class S3BucketTaggingIntegrationTest { + + @Test + void getBucketTaggingOnUntaggedBucketReturnsNoSuchTagSet() { + String bucket = "tagging-never-tagged"; + given().when().put("/" + bucket).then().statusCode(200); + + given() + .when() + .get("/" + bucket + "?tagging") + .then() + .statusCode(404) + .body(containsString("NoSuchTagSet")); + } + + @Test + void getBucketTaggingAfterDeleteBucketTaggingReturnsNoSuchTagSet() { + String bucket = "tagging-tags-deleted"; + given().when().put("/" + bucket).then().statusCode(200); + given() + .contentType("application/xml") + .body("teambackend") + .when() + .put("/" + bucket + "?tagging") + .then() + .statusCode(204); + given().when().delete("/" + bucket + "?tagging").then().statusCode(204); + + given() + .when() + .get("/" + bucket + "?tagging") + .then() + .statusCode(404) + .body(containsString("NoSuchTagSet")); + } +}