-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added dynamic configuration property for maxHeaderSize (#370)
* Added dynamic configuration property for maxHeaderSize * Add test
- Loading branch information
1 parent
c4f8f98
commit acc55f6
Showing
4 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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
104 changes: 104 additions & 0 deletions
104
carapace-server/src/test/java/org/carapaceproxy/core/MaxHeaderSizeTest.java
This file contains 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,104 @@ | ||
package org.carapaceproxy.core; | ||
|
||
import com.github.tomakehurst.wiremock.junit.WireMockRule; | ||
import org.carapaceproxy.api.UseAdminServer; | ||
import org.carapaceproxy.utils.TestUtils; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import java.net.URI; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.util.Properties; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class MaxHeaderSizeTest extends UseAdminServer { | ||
|
||
@Rule | ||
public WireMockRule wireMockRule = new WireMockRule(0); | ||
|
||
private Properties config; | ||
|
||
@Test | ||
public void test() throws Exception { | ||
|
||
stubFor(get(urlEqualTo("/index.html")) | ||
.willReturn(aResponse() | ||
.withStatus(200) | ||
.withHeader("Content-Type", "text/html") | ||
.withHeader("Content-Length", "it <b>works</b> !!".length() + "") | ||
.withBody("it <b>works</b> !!"))); | ||
|
||
config = new Properties(HTTP_ADMIN_SERVER_CONFIG); | ||
startServer(config); | ||
|
||
// Default certificate | ||
String defaultCertificate = TestUtils.deployResource("ia.p12", tmpDir.getRoot()); | ||
config.put("certificate.1.hostname", "*"); | ||
config.put("certificate.1.file", defaultCertificate); | ||
config.put("certificate.1.password", "changeit"); | ||
|
||
// Listeners | ||
config.put("listener.1.host", "localhost"); | ||
config.put("listener.1.port", "8086"); | ||
config.put("listener.1.enabled", "true"); | ||
config.put("listener.1.defaultcertificate", "*"); | ||
|
||
// Backends | ||
config.put("backend.1.id", "localhost"); | ||
config.put("backend.1.enabled", "true"); | ||
config.put("backend.1.host", "localhost"); | ||
config.put("backend.1.port", wireMockRule.port() + ""); | ||
|
||
config.put("backend.2.id", "localhost2"); | ||
config.put("backend.2.enabled", "true"); | ||
config.put("backend.2.host", "localhost2"); | ||
config.put("backend.2.port", wireMockRule.port() + ""); | ||
|
||
// Default director | ||
config.put("director.1.id", "*"); | ||
config.put("director.1.backends", "localhost"); | ||
config.put("director.1.enabled", "true"); | ||
|
||
// Default route | ||
config.put("route.100.id", "default"); | ||
config.put("route.100.enabled", "true"); | ||
config.put("route.100.match", "all"); | ||
config.put("route.100.action", "proxy-all"); | ||
|
||
changeDynamicConfiguration(config); | ||
|
||
|
||
HttpClient httpClient = HttpClient.newBuilder() | ||
.version(HttpClient.Version.HTTP_1_1) | ||
.build(); | ||
|
||
HttpRequest request = HttpRequest.newBuilder() | ||
.GET() | ||
.uri(URI.create("http://localhost:" + 8086 +"/index.html")) | ||
.setHeader("custom-header", "test") | ||
.setHeader("token", "eyJhbGciOiJIUzI1NiJ9.eyJSb") | ||
.setHeader("token1", "eyJhbGciOiJIUzI1NiJ9.eyJSb") | ||
.setHeader("token2", "eyJhbGciOiJIUzI1NiJ9.eyJSb") | ||
.setHeader("token3", "eyJhbGciOiJIUzI1NiJ9.eyJSb") | ||
.build(); | ||
|
||
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); | ||
|
||
assertEquals(200, response.statusCode()); | ||
|
||
config.put("carapace.maxheadersize", "1"); | ||
changeDynamicConfiguration(config); | ||
|
||
HttpClient httpClient2 = HttpClient.newBuilder() | ||
.version(HttpClient.Version.HTTP_1_1) | ||
.build(); | ||
|
||
HttpResponse<String> response2 = httpClient2.send(request, HttpResponse.BodyHandlers.ofString()); | ||
|
||
assertEquals(413, response2.statusCode()); | ||
} | ||
} |