Skip to content

Commit 0209582

Browse files
committed
S3 fixture should report 404 on unknown bucket (#31782)
Today, `AmazonS3Fixture` returns 403 on attempts to access any inappropriate bucket, whether known or otherwise. In fact, S3 reports 404 on nonexistent buckets and 403 on inaccessible ones. This change enhances `AmazonS3Fixture` to distinguish these cases.
1 parent 08fd489 commit 0209582

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/AmazonS3Fixture.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,13 @@ protected Response handle(final Request request) throws IOException {
9696
if (handler != null) {
9797
final String bucket = request.getParam("bucket");
9898
if (bucket != null && permittedBucket.equals(bucket) == false) {
99-
// allow a null bucket to support bucket-free APIs
100-
return newError(request.getId(), RestStatus.FORBIDDEN, "AccessDenied", "Bad bucket", "");
99+
// allow a null bucket to support the multi-object-delete API which
100+
// passes the bucket name in the host header instead of the URL.
101+
if (buckets.containsKey(bucket)) {
102+
return newError(request.getId(), RestStatus.FORBIDDEN, "AccessDenied", "Bad bucket", "");
103+
} else {
104+
return newBucketNotFoundError(request.getId(), bucket);
105+
}
101106
}
102107
return handler.handle(request);
103108
} else {

plugins/repository-s3/src/test/resources/rest-api-spec/test/repository_s3/20_repository_permanent_credentials.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ setup:
183183
---
184184
"Register a repository with a non existing bucket":
185185

186-
- skip:
187-
version: all
188-
reason: to be fixed
189-
190186
- do:
191187
catch: /repository_exception/
192188
snapshot.create_repository:

plugins/repository-s3/src/test/resources/rest-api-spec/test/repository_s3/30_repository_temporary_credentials.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ setup:
183183
---
184184
"Register a repository with a non existing bucket":
185185

186-
- skip:
187-
version: all
188-
reason: to be fixed
189-
190186
- do:
191187
catch: /repository_exception/
192188
snapshot.create_repository:

0 commit comments

Comments
 (0)