-
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.
Merge pull request #10266 from ejba/x-forwarded-prefix
Enable forwarded for prefix header configuration
- Loading branch information
Showing
8 changed files
with
248 additions
and
4 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
42 changes: 42 additions & 0 deletions
42
...tx-http/deployment/src/test/java/io/quarkus/vertx/http/ConfigureForwardedHeadersTest.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,42 @@ | ||
package io.quarkus.vertx.http; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class ConfigureForwardedHeadersTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(ForwardedHandlerInitializer.class) | ||
.addAsResource(new StringAsset("quarkus.http.proxy-address-forwarding=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\n" + | ||
"quarkus.http.proxy.forwarded-prefix-header=X-Envoy-Path\n"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void test() { | ||
assertThat(RestAssured.get("/path").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("X-Forwarded-Proto", "https") | ||
.header("X-Forwarded-For", "backend:4444") | ||
.header("X-Forwarded-Server", "somehost") | ||
.header("X-Envoy-Path", "/prefix") | ||
.get("/path") | ||
.then() | ||
.body(Matchers.equalTo("https|somehost|backend:4444|/prefix/path|https://somehost/prefix/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
90 changes: 90 additions & 0 deletions
90
.../vertx-http/deployment/src/test/java/io/quarkus/vertx/http/ForwardedPrefixHeaderTest.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,90 @@ | ||
package io.quarkus.vertx.http; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class ForwardedPrefixHeaderTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(ForwardedHandlerInitializer.class) | ||
.addAsResource(new StringAsset("quarkus.http.proxy-address-forwarding=true\n" + | ||
"quarkus.http.proxy.enable-forwarded-prefix=true\n"), | ||
"application.properties")); | ||
|
||
@Test | ||
public void test() { | ||
assertThat(RestAssured.get("/path").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("X-Forwarded-Proto", "https") | ||
.header("X-Forwarded-For", "backend:4444") | ||
.header("X-Forwarded-Prefix", "/prefix") | ||
.get("/path") | ||
.then() | ||
.body(Matchers.equalTo("https|localhost|backend:4444|/prefix/path|https://localhost/prefix/path")); | ||
} | ||
|
||
@Test | ||
public void testWithASlashAtEnding() { | ||
assertThat(RestAssured.get("/path").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("X-Forwarded-Proto", "https") | ||
.header("X-Forwarded-For", "backend:4444") | ||
.header("X-Forwarded-Prefix", "/prefix/") | ||
.get("/path") | ||
.then() | ||
.body(Matchers.equalTo("https|localhost|backend:4444|/prefix/path|https://localhost/prefix/path")); | ||
} | ||
|
||
@Test | ||
public void testWhenPrefixIsEmpty() { | ||
assertThat(RestAssured.get("/path").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("X-Forwarded-Proto", "https") | ||
.header("X-Forwarded-For", "backend:4444") | ||
.header("X-Forwarded-Prefix", "") | ||
.get("/path") | ||
.then() | ||
.body(Matchers.equalTo("https|localhost|backend:4444|/path|https://localhost/path")); | ||
} | ||
|
||
@Test | ||
public void testWhenPrefixIsASlash() { | ||
assertThat(RestAssured.get("/path").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("X-Forwarded-Proto", "https") | ||
.header("X-Forwarded-For", "backend:4444") | ||
.header("X-Forwarded-Prefix", "/") | ||
.get("/path") | ||
.then() | ||
.body(Matchers.equalTo("https|localhost|backend:4444|/path|https://localhost/path")); | ||
} | ||
|
||
@Test | ||
public void testWhenPrefixIsADoubleSlash() { | ||
assertThat(RestAssured.get("/path").asString()).startsWith("http|"); | ||
|
||
RestAssured.given() | ||
.header("X-Forwarded-Proto", "https") | ||
.header("X-Forwarded-For", "backend:4444") | ||
.header("X-Forwarded-Prefix", "//") | ||
.get("/path") | ||
.then() | ||
.body(Matchers.equalTo("https|localhost|backend:4444|/path|https://localhost/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
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