-
Notifications
You must be signed in to change notification settings - Fork 70
Add configurable request header size to the HTTP Listener #393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pacmano1
wants to merge
3
commits into
OpenIntegrationEngine:main
Choose a base branch
from
pacmano1:feat/http-listener-request-header-size
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
server/src/test/java/com/mirth/connect/connectors/http/DefaultHttpConfigurationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| // SPDX-FileCopyrightText: Open Integration Engine | ||
|
|
||
| package com.mirth.connect.connectors.http; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import javax.servlet.ServletException; | ||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpServletResponse; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.apache.http.client.methods.CloseableHttpResponse; | ||
| import org.apache.http.client.methods.HttpGet; | ||
| import org.apache.http.impl.client.CloseableHttpClient; | ||
| import org.apache.http.impl.client.HttpClients; | ||
| import org.eclipse.jetty.http.HttpStatus; | ||
| import org.eclipse.jetty.server.Request; | ||
| import org.eclipse.jetty.server.Server; | ||
| import org.eclipse.jetty.server.ServerConnector; | ||
| import org.eclipse.jetty.server.handler.AbstractHandler; | ||
| import org.junit.After; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
|
|
||
| import com.google.inject.AbstractModule; | ||
| import com.google.inject.Guice; | ||
| import com.google.inject.Injector; | ||
| import com.mirth.connect.server.controllers.ConfigurationController; | ||
| import com.mirth.connect.server.controllers.ControllerFactory; | ||
|
|
||
| /** | ||
| * Exercises the request header size setting against a real Jetty connector, since the whole point | ||
| * of the property is behavior Jetty enforces before any channel code runs. | ||
| */ | ||
| public class DefaultHttpConfigurationTest { | ||
|
|
||
| private static final int LARGE_HEADER_BYTES = 16384; | ||
|
|
||
| private Server server; | ||
|
|
||
| @BeforeClass | ||
| public static void setupBeforeClass() { | ||
| ControllerFactory controllerFactory = mock(ControllerFactory.class); | ||
| when(controllerFactory.createConfigurationController()).thenReturn(mock(ConfigurationController.class)); | ||
|
|
||
| Injector injector = Guice.createInjector(new AbstractModule() { | ||
| @Override | ||
| protected void configure() { | ||
| requestStaticInjection(ControllerFactory.class); | ||
| bind(ControllerFactory.class).toInstance(controllerFactory); | ||
| } | ||
| }); | ||
| injector.getInstance(ControllerFactory.class); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() throws Exception { | ||
| if (server != null) { | ||
| server.stop(); | ||
| server = null; | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testJettyDefaultRejectsOversizedHeader() throws Exception { | ||
| assertEquals(HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE_431, sendLargeHeaderRequest(HttpReceiverProperties.DEFAULT_REQUEST_HEADER_SIZE)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRaisedRequestHeaderSizeAcceptsOversizedHeader() throws Exception { | ||
| assertEquals(HttpStatus.OK_200, sendLargeHeaderRequest(65536)); | ||
| } | ||
|
|
||
| private int sendLargeHeaderRequest(int requestHeaderSize) throws Exception { | ||
| int port = startReceiver(requestHeaderSize); | ||
|
|
||
| try (CloseableHttpClient client = HttpClients.createDefault()) { | ||
| HttpGet get = new HttpGet("http://127.0.0.1:" + port + "/"); | ||
| get.addHeader("X-Large-Header", StringUtils.repeat('a', LARGE_HEADER_BYTES)); | ||
|
|
||
| try (CloseableHttpResponse response = client.execute(get)) { | ||
| return response.getStatusLine().getStatusCode(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private int startReceiver(int requestHeaderSize) throws Exception { | ||
| server = new Server(); | ||
|
|
||
| HttpReceiver receiver = mock(HttpReceiver.class); | ||
| when(receiver.getServer()).thenReturn(server); | ||
| when(receiver.getHost()).thenReturn("127.0.0.1"); | ||
| when(receiver.getPort()).thenReturn(0); | ||
| when(receiver.getTimeout()).thenReturn(30000); | ||
| when(receiver.getRequestHeaderSize()).thenReturn(requestHeaderSize); | ||
|
|
||
| new DefaultHttpConfiguration().configureReceiver(receiver); | ||
|
|
||
| server.setHandler(new AbstractHandler() { | ||
| @Override | ||
| public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { | ||
| baseRequest.setHandled(true); | ||
| response.setStatus(HttpServletResponse.SC_OK); | ||
| } | ||
| }); | ||
|
|
||
| server.start(); | ||
| return ((ServerConnector) server.getConnectors()[0]).getLocalPort(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.