mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(s3): persist inline x-amz-tagging header on PutObject (#987)
* fix(s3): persist inline x-amz-tagging header on PutObject PutObject silently dropped tags supplied via the x-amz-tagging request header — the controller did not read the header and tags never reached the object store. Adds a header parameter, parses the URL-encoded key=value tag set (with 10-tag and 8 KB limits), and persists via the existing putObjectTagging path so behavior matches real AWS S3. * test(s3): add negative-path tests for inline x-amz-tagging header Cover malformed pair, empty key, duplicate key, >10 tags, and oversized header. Note in S3Controller that the InvalidArgument and BadRequest codes match observed real-AWS behavior even though they are not in the S3 Smithy service model --------- Signed-off-by: Hector Ventura <hectorvent@gmail.com> Co-authored-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
2da06840e9
commit
8fb07d2654
4 files changed
+169
-1
No files matched your search
@@ -427,4 +427,104 @@ class S3Test {
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(27)
|
||||
void putObjectPersistsInlineTaggingHeader() {
|
||||
String bucket = TestFixtures.uniqueName("inline-tag-bucket");
|
||||
String key = "inline-tagged.txt";
|
||||
s3.createBucket(CreateBucketRequest.builder().bucket(bucket).build());
|
||||
try {
|
||||
s3.putObject(PutObjectRequest.builder()
|
||||
.bucket(bucket).key(key)
|
||||
.tagging(Tagging.builder()
|
||||
.tagSet(
|
||||
software.amazon.awssdk.services.s3.model.Tag.builder().key("env").value("test").build(),
|
||||
software.amazon.awssdk.services.s3.model.Tag.builder().key("project").value("floci").build()
|
||||
)
|
||||
.build())
|
||||
.build(),
|
||||
RequestBody.fromString("inline-tagged content"));
|
||||
|
||||
GetObjectTaggingResponse response = s3.getObjectTagging(
|
||||
GetObjectTaggingRequest.builder().bucket(bucket).key(key).build());
|
||||
|
||||
assertThat(response.tagSet()).hasSize(2);
|
||||
assertThat(response.tagSet())
|
||||
.anyMatch(t -> "env".equals(t.key()) && "test".equals(t.value()))
|
||||
.anyMatch(t -> "project".equals(t.key()) && "floci".equals(t.value()));
|
||||
} finally {
|
||||
try {
|
||||
s3.deleteObject(DeleteObjectRequest.builder().bucket(bucket).key(key).build());
|
||||
} catch (Exception ignored) {}
|
||||
try {
|
||||
s3.deleteBucket(DeleteBucketRequest.builder().bucket(bucket).build());
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(28)
|
||||
void putObjectInlineTaggingRejectsMalformedPair() {
|
||||
assertInlineTaggingHeaderRejected("nokeyhasvalue", 400, "InvalidArgument");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(29)
|
||||
void putObjectInlineTaggingRejectsEmptyKey() {
|
||||
assertInlineTaggingHeaderRejected("=value", 400, "InvalidArgument");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(30)
|
||||
void putObjectInlineTaggingRejectsDuplicateKey() {
|
||||
assertInlineTaggingHeaderRejected("env=a&env=b", 400, "InvalidArgument");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(31)
|
||||
void putObjectInlineTaggingRejectsTooManyTags() {
|
||||
StringBuilder header = new StringBuilder();
|
||||
for (int i = 0; i < 11; i++) {
|
||||
if (i > 0) header.append('&');
|
||||
header.append("k").append(i).append("=v").append(i);
|
||||
}
|
||||
assertInlineTaggingHeaderRejected(header.toString(), 400, "BadRequest");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(32)
|
||||
void putObjectInlineTaggingRejectsOversizedHeader() {
|
||||
// The size check runs before pair parsing, so a single huge value trips it
|
||||
// without first being rejected by the >10-tag rule.
|
||||
String huge = "k=" + "v".repeat(8 * 1024 + 1);
|
||||
assertInlineTaggingHeaderRejected(huge, 400, "InvalidArgument");
|
||||
}
|
||||
|
||||
private void assertInlineTaggingHeaderRejected(String rawTaggingHeader, int expectedStatus, String expectedErrorCode) {
|
||||
String bucket = TestFixtures.uniqueName("inline-tag-reject");
|
||||
String key = "rejected.txt";
|
||||
s3.createBucket(CreateBucketRequest.builder().bucket(bucket).build());
|
||||
try {
|
||||
assertThatThrownBy(() -> s3.putObject(
|
||||
PutObjectRequest.builder()
|
||||
.bucket(bucket).key(key)
|
||||
.overrideConfiguration(o -> o.putHeader("x-amz-tagging", rawTaggingHeader))
|
||||
.build(),
|
||||
RequestBody.fromString("content")))
|
||||
.isInstanceOf(S3Exception.class)
|
||||
.satisfies(e -> {
|
||||
S3Exception s3e = (S3Exception) e;
|
||||
assertThat(s3e.statusCode()).isEqualTo(expectedStatus);
|
||||
assertThat(s3e.awsErrorDetails().errorCode()).isEqualTo(expectedErrorCode);
|
||||
});
|
||||
} finally {
|
||||
try {
|
||||
s3.deleteObject(DeleteObjectRequest.builder().bucket(bucket).key(key).build());
|
||||
} catch (Exception ignored) {}
|
||||
try {
|
||||
s3.deleteBucket(DeleteBucketRequest.builder().bucket(bucket).build());
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user