-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure Forwarded and X-Forwarded values are the same
- Loading branch information
1 parent
cbd735f
commit a4d1906
Showing
6 changed files
with
377 additions
and
63 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
...eployment/src/test/java/io/quarkus/vertx/http/AllowForwardedAndXForwardedHeadersTest.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,132 @@ | ||
package io.quarkus.vertx.http; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class AllowForwardedAndXForwardedHeadersTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(ForwardedHandlerInitializer.class) | ||
.addAsResource(new StringAsset("quarkus.http.proxy.proxy-address-forwarding=true\n" + | ||
"quarkus.http.proxy.allow-forwarded=true\n" + | ||
"quarkus.http.proxy.allow-x-forwarded=true\n" + | ||
"quarkus.http.proxy.enable-forwarded-host=true\n" + | ||
"quarkus.http.proxy.enable-forwarded-prefix=true\n" + | ||
"quarkus.http.proxy.forwarded-host-header=X-Forwarded-Server"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void testAllHeaderValuesMatch() { | ||
assertThat(RestAssured.get("/path").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("Forwarded", "proto=https;for=backend2:5555;host=somehost2") | ||
.header("X-Forwarded-Proto", "https") | ||
.header("X-Forwarded-For", "backend2:5555") | ||
.header("X-Forwarded-Server", "somehost2") | ||
.get("/path") | ||
.then() | ||
.body(Matchers.equalTo("https|somehost2|backend2:5555|/path|https://somehost2/path")); | ||
} | ||
|
||
@Test | ||
public void tesProtoHeaderValuesMatch() { | ||
assertThat(RestAssured.get("/path").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("Forwarded", "proto=https;for=backend2:5555;host=somehost2") | ||
.header("X-Forwarded-Proto", "https") | ||
.get("/path") | ||
.then() | ||
.body(Matchers.equalTo("https|somehost2|backend2:5555|/path|https://somehost2/path")); | ||
} | ||
|
||
@Test | ||
public void testForHeaderValuesMatch() { | ||
assertThat(RestAssured.get("/path").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("Forwarded", "proto=https;for=backend2:5555;host=somehost2") | ||
.header("X-Forwarded-For", "backend2:5555") | ||
.get("/path") | ||
.then() | ||
.body(Matchers.equalTo("https|somehost2|backend2:5555|/path|https://somehost2/path")); | ||
} | ||
|
||
@Test | ||
public void testHostHeaderValuesMatch() { | ||
assertThat(RestAssured.get("/path").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("Forwarded", "proto=https;for=backend2:5555;host=somehost2") | ||
.header("X-Forwarded-Server", "somehost2") | ||
.get("/path") | ||
.then() | ||
.body(Matchers.equalTo("https|somehost2|backend2:5555|/path|https://somehost2/path")); | ||
} | ||
|
||
@Test | ||
public void testProtoDoesNotMatch() { | ||
assertThat(RestAssured.get("/path").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("Forwarded", "proto=https;for=backend2:5555;host=somehost2") | ||
.header("X-Forwarded-Proto", "http") | ||
.header("X-Forwarded-For", "backend2:5555") | ||
.header("X-Forwarded-Server", "somehost2") | ||
.get("/path") | ||
.then() | ||
.statusCode(400); | ||
} | ||
|
||
@Test | ||
public void testForHostDoesNotMatch() { | ||
assertThat(RestAssured.get("/path").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("Forwarded", "proto=https;for=backend:5555;host=somehost2") | ||
.header("X-Forwarded-Proto", "http") | ||
.header("X-Forwarded-For", "backend2:5555") | ||
.header("X-Forwarded-Server", "somehost2") | ||
.get("/path") | ||
.then() | ||
.statusCode(400); | ||
} | ||
|
||
@Test | ||
public void testForHostPortDoesNotMatch() { | ||
assertThat(RestAssured.get("/path").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("Forwarded", "proto=https;for=backend2:4444;host=somehost2") | ||
.header("X-Forwarded-Proto", "http") | ||
.header("X-Forwarded-For", "backend2:5555") | ||
.header("X-Forwarded-Server", "somehost2") | ||
.get("/path") | ||
.then() | ||
.statusCode(400); | ||
} | ||
|
||
@Test | ||
public void testHostDoesNotMatch() { | ||
assertThat(RestAssured.get("/path").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("Forwarded", "proto=https;for=backend2:4444;host=somehost") | ||
.header("X-Forwarded-Proto", "http") | ||
.header("X-Forwarded-For", "backend2:5555") | ||
.header("X-Forwarded-Server", "somehost2") | ||
.get("/path") | ||
.then() | ||
.statusCode(400); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...c/test/java/io/quarkus/vertx/http/AllowForwardedHeadersOverrideXForwardedHeadersTest.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,37 @@ | ||
package io.quarkus.vertx.http; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class AllowForwardedHeadersOverrideXForwardedHeadersTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(ForwardedHandlerInitializer.class) | ||
.addAsResource(new StringAsset("quarkus.http.proxy.proxy-address-forwarding=true\n" + | ||
"quarkus.http.proxy.allow-forwarded=true\n" + | ||
"quarkus.http.proxy.allow-x-forwarded=true\n" + | ||
"quarkus.http.proxy.strict-forwarded-control=false\n"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void testXForwardedProtoOverridesForwardedProto() { | ||
assertThat(RestAssured.get("/path").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("Forwarded", "proto=https;for=backend2:5555;host=somehost2") | ||
.header("X-Forwarded-Proto", "http") | ||
.get("/path") | ||
.then() | ||
.body(Matchers.equalTo("https|somehost2|backend2:5555|/path|https://somehost2/path")); | ||
} | ||
|
||
} |
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
Oops, something went wrong.