Skip to content

Commit cf81b6d

Browse files
authored
Remove leading slash in header value for ARNs in CopySourceInterceptor (#3526)
* Update CopySourceInterceptor to remove leading slash in header value for ARN source buckets * Updated changelong entry
1 parent bd75326 commit cf81b6d

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "Amazon S3",
4+
"contributor": "",
5+
"description": "Update CopySourceInterceptor to remove leading slash in header value for ARN source buckets"
6+
}

services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/handlers/CopySourceInterceptor.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static software.amazon.awssdk.utils.http.SdkHttpUtils.urlEncodeIgnoreSlashes;
1919

20+
import java.util.Optional;
2021
import software.amazon.awssdk.annotations.SdkInternalApi;
2122
import software.amazon.awssdk.core.SdkRequest;
2223
import software.amazon.awssdk.core.interceptor.Context.ModifyRequest;
@@ -97,9 +98,12 @@ private static SdkRequest modifyUploadPartCopyRequest(UploadPartCopyRequest requ
9798

9899
private static String constructCopySource(String sourceBucket, String sourceKey, String sourceVersionId) {
99100
StringBuilder copySource = new StringBuilder();
100-
copySource.append("/");
101+
Optional<S3ResourceType> arnTypeOptional = S3ArnUtils.getArnType(sourceBucket);
102+
if (!arnTypeOptional.isPresent()) {
103+
copySource.append("/");
104+
}
101105
copySource.append(urlEncodeIgnoreSlashes(sourceBucket));
102-
S3ArnUtils.getArnType(sourceBucket).ifPresent(arnType -> {
106+
arnTypeOptional.ifPresent(arnType -> {
103107
if (arnType == S3ResourceType.ACCESS_POINT || arnType == S3ResourceType.OUTPOST) {
104108
copySource.append("/object");
105109
}

services/s3/src/test/java/software/amazon/awssdk/services/s3/internal/handlers/CopySourceInterceptorTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void modifyRequest_insertsSlashObject_whenAccessPointArn() {
154154
.modifyRequest(() -> originalRequest, new ExecutionAttributes());
155155

156156
assertThat(modifiedRequest.copySource()).isEqualTo(
157-
"/arn%3Aaws%3As3%3Aus-west-2%3A123456789012%3Aaccesspoint/my-access-point/object/my-key");
157+
"arn%3Aaws%3As3%3Aus-west-2%3A123456789012%3Aaccesspoint/my-access-point/object/my-key");
158158
}
159159

160160
@Test
@@ -168,6 +168,6 @@ public void modifyRequest_insertsSlashObject_whenOutpostArn() {
168168
.modifyRequest(() -> originalRequest, new ExecutionAttributes());
169169

170170
assertThat(modifiedRequest.copySource()).isEqualTo(
171-
"/arn%3Aaws%3As3-outposts%3Aus-west-2%3A123456789012%3Aoutpost/my-outpost/bucket/my-bucket/object/my-key");
171+
"arn%3Aaws%3As3-outposts%3Aus-west-2%3A123456789012%3Aoutpost/my-outpost/bucket/my-bucket/object/my-key");
172172
}
173173
}

0 commit comments

Comments
 (0)