|
@@ -60,7 +60,6 @@ import java.util.Set;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
-import static org.elasticsearch.rest.RestController.ELASTIC_INTERNAL_ORIGIN_HTTP_HEADER;
|
|
|
import static org.elasticsearch.rest.RestController.ELASTIC_PRODUCT_HTTP_HEADER;
|
|
|
import static org.elasticsearch.rest.RestController.ELASTIC_PRODUCT_HTTP_HEADER_VALUE;
|
|
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
|
@@ -924,49 +923,23 @@ public class RestControllerTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- * Test that when serverless is enabled, a normal user not using the X-elastic-internal-origin header can only access endpoints
|
|
|
- * annotated with a PUBLIC scope.
|
|
|
+ * Test that when serverless is enabled, a normal user can not access endpoints without a ServerlessScope annotation.
|
|
|
*/
|
|
|
public void testApiProtectionWithServerlessEnabledAsEndUser() {
|
|
|
final RestController restController = new RestController(null, client, circuitBreakerService, new UsageService(), tracer, true);
|
|
|
restController.registerHandler(new PublicRestHandler());
|
|
|
restController.registerHandler(new InternalRestHandler());
|
|
|
restController.registerHandler(new HiddenRestHandler());
|
|
|
- List<String> accessiblePaths = List.of("/public");
|
|
|
- accessiblePaths.forEach(path -> {
|
|
|
- RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withPath(path).build();
|
|
|
- AssertingChannel channel = new AssertingChannel(request, false, RestStatus.OK);
|
|
|
- restController.dispatchRequest(request, channel, new ThreadContext(Settings.EMPTY));
|
|
|
- });
|
|
|
- List<String> inaccessiblePaths = List.of("/internal", "/hidden");
|
|
|
- inaccessiblePaths.forEach(path -> {
|
|
|
- RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withPath(path).build();
|
|
|
- AssertingChannel channel = new AssertingChannel(request, false, RestStatus.BAD_REQUEST);
|
|
|
- restController.dispatchRequest(request, channel, new ThreadContext(Settings.EMPTY));
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- * Test that when serverless is enabled, a system user using the X-elastic-internal-origin header can only access endpoints
|
|
|
- * annotated with a PUBLIC or INTERNAL scope.
|
|
|
- */
|
|
|
- public void testApiProtectionWithServerlessEnabledAsInternalUser() {
|
|
|
- final RestController restController = new RestController(null, client, circuitBreakerService, new UsageService(), tracer, true);
|
|
|
- restController.registerHandler(new PublicRestHandler());
|
|
|
- restController.registerHandler(new InternalRestHandler());
|
|
|
- restController.registerHandler(new HiddenRestHandler());
|
|
|
- Map<String, List<String>> headers = new HashMap<>();
|
|
|
- headers.put(ELASTIC_INTERNAL_ORIGIN_HTTP_HEADER, Collections.singletonList("true"));
|
|
|
List<String> accessiblePaths = List.of("/public", "/internal");
|
|
|
accessiblePaths.forEach(path -> {
|
|
|
- RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withHeaders(headers).withPath(path).build();
|
|
|
+ RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withPath(path).build();
|
|
|
AssertingChannel channel = new AssertingChannel(request, false, RestStatus.OK);
|
|
|
restController.dispatchRequest(request, channel, new ThreadContext(Settings.EMPTY));
|
|
|
});
|
|
|
List<String> inaccessiblePaths = List.of("/hidden");
|
|
|
inaccessiblePaths.forEach(path -> {
|
|
|
- RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withHeaders(headers).withPath(path).build();
|
|
|
- AssertingChannel channel = new AssertingChannel(request, false, RestStatus.BAD_REQUEST);
|
|
|
+ RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withPath(path).build();
|
|
|
+ AssertingChannel channel = new AssertingChannel(request, false, RestStatus.NOT_FOUND);
|
|
|
restController.dispatchRequest(request, channel, new ThreadContext(Settings.EMPTY));
|
|
|
});
|
|
|
}
|