IndexClosedException to return 400 rather than 403 (#25752)

403 can be confused with security. If an API doesn't support working against closed indices and closed indices are referred to in a request, that is a bad request, hence 400 is more appropriate.
This commit is contained in:
Luca Cavanna 2017-07-18 10:26:32 +02:00 committed by GitHub
parent 194f267110
commit 0d8b753325
6 changed files with 38 additions and 8 deletions

View File

@ -42,6 +42,6 @@ public class IndexClosedException extends ElasticsearchException {
@Override @Override
public RestStatus status() { public RestStatus status() {
return RestStatus.FORBIDDEN; return RestStatus.BAD_REQUEST;
} }
} }

View File

@ -107,8 +107,15 @@ $ curl -v -XPOST 'localhost:9200/my_index/_settings'
* Connection #0 to host localhost left intact * Connection #0 to host localhost left intact
-------------------------------------------- --------------------------------------------
==== Dissallow using `_cache` and `_cache_key` ==== Disallow using `_cache` and `_cache_key`
The `_cache` and `_cache_key` options in queries have been deprecated since version 2.0.0 and The `_cache` and `_cache_key` options in queries have been deprecated since version 2.0.0 and
have been ignored since then, issuing a deprecation warning. These options have now been completely have been ignored since then, issuing a deprecation warning. These options have now been completely
removed, so using them now will throw an error. removed, so using them now will throw an error.
==== IndexClosedException to return 400 status code
An `IndexClosedException` is returned whenever an api that doesn't support
closed indices (e.g. search) is called passing closed indices as parameters
and `ignore_unavailable` is set to `false`. The response status code returned
in such case changed from `403` to `400`

View File

@ -86,6 +86,10 @@
--- ---
"Test cat segments on closed index behaviour": "Test cat segments on closed index behaviour":
- skip:
version: " - 5.99.99"
reason: status code on closed indices changed in 6.0.0 from 403 to 400
- do: - do:
indices.create: indices.create:
index: index1 index: index1
@ -99,7 +103,7 @@
index: index1 index: index1
- do: - do:
catch: forbidden catch: request
cat.segments: cat.segments:
index: index1 index: index1

View File

@ -1,5 +1,9 @@
--- ---
"Basic test for index open/close": "Basic test for index open/close":
- skip:
version: " - 5.99.99"
reason: status code on closed indices changed in 6.0.0 from 403 to 400
- do: - do:
indices.create: indices.create:
index: test_index index: test_index
@ -16,7 +20,7 @@
index: test_index index: test_index
- do: - do:
catch: forbidden catch: request
search: search:
index: test_index index: test_index

View File

@ -23,12 +23,16 @@ setup:
--- ---
"All indices": "All indices":
- skip:
version: " - 5.99.99"
reason: status code on closed indices changed in 6.0.0 from 403 to 400
- do: - do:
indices.close: indices.close:
index: _all index: _all
- do: - do:
catch: forbidden catch: request
search: search:
index: test_index2 index: test_index2
@ -46,12 +50,16 @@ setup:
--- ---
"Trailing wildcard": "Trailing wildcard":
- skip:
version: " - 5.99.99"
reason: status code on closed indices changed in 6.0.0 from 403 to 400
- do: - do:
indices.close: indices.close:
index: test_* index: test_*
- do: - do:
catch: forbidden catch: request
search: search:
index: test_index2 index: test_index2
@ -69,12 +77,16 @@ setup:
--- ---
"Only wildcard": "Only wildcard":
- skip:
version: " - 5.99.99"
reason: status code on closed indices changed in 6.0.0 from 403 to 400
- do: - do:
indices.close: indices.close:
index: '*' index: '*'
- do: - do:
catch: forbidden catch: request
search: search:
index: test_index3 index: test_index3

View File

@ -43,6 +43,9 @@
--- ---
"closed segments test": "closed segments test":
- skip:
version: " - 5.99.99"
reason: status code on closed indices changed in 6.0.0 from 403 to 400
- do: - do:
indices.create: indices.create:
@ -63,7 +66,7 @@
index: index1 index: index1
- do: - do:
catch: forbidden catch: request
indices.segments: indices.segments:
index: index1 index: index1