Skip to content

Commit

Permalink
Replace nio and nitty test endpoint (#475)
Browse files Browse the repository at this point in the history
Signed-off-by: Harold Wang <harowang@amazon.com>
  • Loading branch information
harold-wang authored Mar 31, 2021
1 parent 70cad29 commit 5971a51
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public void dispatchBadRequest(final RestChannel channel,

final Settings settings = createBuilderWithPort()
.put(SETTING_CORS_ENABLED.getKey(), true)
.put(SETTING_CORS_ALLOW_ORIGIN.getKey(), "elastic.co").build();
.put(SETTING_CORS_ALLOW_ORIGIN.getKey(), "test-cors.org").build();

try (Netty4HttpServerTransport transport = new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool,
xContentRegistry(), dispatcher, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS),
Expand All @@ -379,13 +379,13 @@ public void dispatchBadRequest(final RestChannel channel,
// Test pre-flight request
try (Netty4HttpClient client = new Netty4HttpClient()) {
final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/");
request.headers().add(CorsHandler.ORIGIN, "elastic.co");
request.headers().add(CorsHandler.ORIGIN, "test-cors.org");
request.headers().add(CorsHandler.ACCESS_CONTROL_REQUEST_METHOD, "POST");

final FullHttpResponse response = client.send(remoteAddress.address(), request);
try {
assertThat(response.status(), equalTo(HttpResponseStatus.OK));
assertThat(response.headers().get(CorsHandler.ACCESS_CONTROL_ALLOW_ORIGIN), equalTo("elastic.co"));
assertThat(response.headers().get(CorsHandler.ACCESS_CONTROL_ALLOW_ORIGIN), equalTo("test-cors.org"));
assertThat(response.headers().get(CorsHandler.VARY), equalTo(CorsHandler.ORIGIN));
assertTrue(response.headers().contains(CorsHandler.DATE));
} finally {
Expand All @@ -396,7 +396,7 @@ public void dispatchBadRequest(final RestChannel channel,
// Test short-circuited request
try (Netty4HttpClient client = new Netty4HttpClient()) {
final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
request.headers().add(CorsHandler.ORIGIN, "elastic2.co");
request.headers().add(CorsHandler.ORIGIN, "google.com");

final FullHttpResponse response = client.send(remoteAddress.address(), request);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void dispatchBadRequest(final RestChannel channel,

final Settings settings = createBuilderWithPort()
.put(SETTING_CORS_ENABLED.getKey(), true)
.put(SETTING_CORS_ALLOW_ORIGIN.getKey(), "elastic.co")
.put(SETTING_CORS_ALLOW_ORIGIN.getKey(), "test-cors.org")
.build();

try (NioHttpServerTransport transport = new NioHttpServerTransport(settings, networkService, bigArrays, pageRecycler,
Expand All @@ -252,13 +252,13 @@ threadPool, xContentRegistry(), dispatcher, new NioGroupFactory(settings, logger
// Test pre-flight request
try (NioHttpClient client = new NioHttpClient()) {
final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/");
request.headers().add(CorsHandler.ORIGIN, "elastic.co");
request.headers().add(CorsHandler.ORIGIN, "test-cors.org");
request.headers().add(CorsHandler.ACCESS_CONTROL_REQUEST_METHOD, "POST");

final FullHttpResponse response = client.send(remoteAddress.address(), request);
try {
assertThat(response.status(), equalTo(HttpResponseStatus.OK));
assertThat(response.headers().get(CorsHandler.ACCESS_CONTROL_ALLOW_ORIGIN), equalTo("elastic.co"));
assertThat(response.headers().get(CorsHandler.ACCESS_CONTROL_ALLOW_ORIGIN), equalTo("test-cors.org"));
assertThat(response.headers().get(CorsHandler.VARY), equalTo(CorsHandler.ORIGIN));
assertTrue(response.headers().contains(CorsHandler.DATE));
} finally {
Expand All @@ -269,7 +269,7 @@ threadPool, xContentRegistry(), dispatcher, new NioGroupFactory(settings, logger
// Test short-circuited request
try (NioHttpClient client = new NioHttpClient()) {
final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
request.headers().add(CorsHandler.ORIGIN, "elastic2.co");
request.headers().add(CorsHandler.ORIGIN, "google.com");

final FullHttpResponse response = client.send(remoteAddress.address(), request);
try {
Expand Down

0 comments on commit 5971a51

Please sign in to comment.