-
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.
Signed-off-by: Phillip Kruger <[email protected]>
- Loading branch information
1 parent
e9c57ea
commit 646100d
Showing
4 changed files
with
233 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
194 changes: 194 additions & 0 deletions
194
...nsions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devui/DevUICorsTest.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,194 @@ | ||
package io.quarkus.vertx.http.devui; | ||
|
||
import static org.hamcrest.Matchers.emptyOrNullString; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class DevUICorsTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusDevModeTest config = new QuarkusDevModeTest() | ||
.withEmptyApplication(); | ||
|
||
@Test | ||
public void testPreflightHttpLocalhostOrigin() { | ||
String origin = "http://localhost:8080"; | ||
String methods = "GET,POST"; | ||
RestAssured.given() | ||
.header("Origin", origin) | ||
.header("Access-Control-Request-Method", methods) | ||
.when() | ||
.options("q/dev-ui/configuration-form-editor").then() | ||
.statusCode(200) | ||
.header("Access-Control-Allow-Origin", origin) | ||
.header("Access-Control-Allow-Methods", methods) | ||
.body(emptyOrNullString()); | ||
} | ||
|
||
@Test | ||
public void testPreflightHttpLocalhostIpOrigin() { | ||
String origin = "http://127.0.0.1:8080"; | ||
String methods = "GET,POST"; | ||
RestAssured.given() | ||
.header("Origin", origin) | ||
.header("Access-Control-Request-Method", methods) | ||
.when() | ||
.options("q/dev-ui/configuration-form-editor").then() | ||
.statusCode(200) | ||
.header("Access-Control-Allow-Origin", origin) | ||
.header("Access-Control-Allow-Methods", methods) | ||
.body(emptyOrNullString()); | ||
} | ||
|
||
@Test | ||
public void testPreflightHttpsLocalhostOrigin() { | ||
String origin = "https://localhost:8443"; | ||
String methods = "GET,POST"; | ||
RestAssured.given() | ||
.header("Origin", origin) | ||
.header("Access-Control-Request-Method", methods) | ||
.when() | ||
.options("q/dev-ui/configuration-form-editor").then() | ||
.statusCode(200) | ||
.header("Access-Control-Allow-Origin", origin) | ||
.header("Access-Control-Allow-Methods", methods) | ||
.body(emptyOrNullString()); | ||
} | ||
|
||
@Test | ||
public void testPreflightHttpsLocalhostIpOrigin() { | ||
String origin = "https://127.0.0.1:8443"; | ||
String methods = "GET,POST"; | ||
RestAssured.given() | ||
.header("Origin", origin) | ||
.header("Access-Control-Request-Method", methods) | ||
.when() | ||
.options("q/dev-ui/configuration-form-editor").then() | ||
.statusCode(200) | ||
.header("Access-Control-Allow-Origin", origin) | ||
.header("Access-Control-Allow-Methods", methods) | ||
.body(emptyOrNullString()); | ||
} | ||
|
||
@Test | ||
public void testPreflightNonLocalhostOrigin() { | ||
String methods = "GET,POST"; | ||
RestAssured.given() | ||
.header("Origin", "https://quarkus.io/http://localhost") | ||
.header("Access-Control-Request-Method", methods) | ||
.when() | ||
.options("q/dev-ui/configuration-form-editor").then() | ||
.statusCode(403) | ||
.header("Access-Control-Allow-Origin", nullValue()) | ||
.header("Access-Control-Allow-Methods", nullValue()) | ||
.body(emptyOrNullString()); | ||
} | ||
|
||
@Test | ||
public void testPreflightBadLocalhostOrigin() { | ||
String methods = "GET,POST"; | ||
RestAssured.given() | ||
.header("Origin", "http://localhost:8080/devui") | ||
.header("Access-Control-Request-Method", methods) | ||
.when() | ||
.options("q/dev-ui/configuration-form-editor").then() | ||
.statusCode(403) | ||
.header("Access-Control-Allow-Origin", nullValue()) | ||
.body(emptyOrNullString()); | ||
} | ||
|
||
@Test | ||
public void testPreflightBadLocalhostIpOrigin() { | ||
String methods = "GET,POST"; | ||
RestAssured.given() | ||
.header("Origin", "http://127.0.0.1:8080/devui") | ||
.header("Access-Control-Request-Method", methods) | ||
.when() | ||
.options("q/dev-ui/configuration-form-editor").then() | ||
.statusCode(403) | ||
.header("Access-Control-Allow-Origin", nullValue()) | ||
.body(emptyOrNullString()); | ||
} | ||
|
||
@Test | ||
public void testPreflightLocalhostOriginWithoutPort() { | ||
String methods = "GET,POST"; | ||
RestAssured.given() | ||
.header("Origin", "http://localhost") | ||
.header("Access-Control-Request-Method", methods) | ||
.when() | ||
.options("q/dev-ui/configuration-form-editor").then() | ||
.statusCode(403) | ||
.header("Access-Control-Allow-Origin", nullValue()) | ||
.body(emptyOrNullString()); | ||
} | ||
|
||
@Test | ||
public void testSimpleRequestHttpLocalhostOrigin() { | ||
String origin = "http://localhost:8080"; | ||
RestAssured.given() | ||
.header("Origin", origin) | ||
.when() | ||
.get("q/dev-ui/configuration-form-editor").then() | ||
.statusCode(200) | ||
.header("Access-Control-Allow-Origin", origin) | ||
.header("Access-Control-Allow-Methods", nullValue()) | ||
.body(not(emptyOrNullString())); | ||
} | ||
|
||
@Test | ||
public void testSimpleRequestHttpLocalhostIpOrigin() { | ||
String origin = "http://127.0.0.1:8080"; | ||
RestAssured.given() | ||
.header("Origin", origin) | ||
.when() | ||
.get("q/dev-ui/configuration-form-editor").then() | ||
.statusCode(200) | ||
.header("Access-Control-Allow-Origin", origin) | ||
.header("Access-Control-Allow-Methods", nullValue()) | ||
.body(not(emptyOrNullString())); | ||
} | ||
|
||
@Test | ||
public void testSimpleRequestHttpsLocalhostOrigin() { | ||
String origin = "https://localhost:8443"; | ||
RestAssured.given() | ||
.header("Origin", origin) | ||
.when() | ||
.get("q/dev-ui/configuration-form-editor").then() | ||
.statusCode(200) | ||
.header("Access-Control-Allow-Origin", origin) | ||
.header("Access-Control-Allow-Methods", nullValue()) | ||
.body(not(emptyOrNullString())); | ||
} | ||
|
||
@Test | ||
public void testSimpleRequestHttpsLocalhostIpOrigin() { | ||
String origin = "https://127.0.0.1:8443"; | ||
RestAssured.given() | ||
.header("Origin", origin) | ||
.when() | ||
.get("q/dev-ui/configuration-form-editor").then() | ||
.statusCode(200) | ||
.header("Access-Control-Allow-Origin", origin) | ||
.header("Access-Control-Allow-Methods", nullValue()) | ||
.body(not(emptyOrNullString())); | ||
} | ||
|
||
@Test | ||
public void testSimpleRequestNonLocalhostOrigin() { | ||
RestAssured.given() | ||
.header("Origin", "https://quarkus.io/http://localhost") | ||
.when() | ||
.get("q/dev-ui/configuration-form-editor").then() | ||
.statusCode(403) | ||
.header("Access-Control-Allow-Origin", nullValue()) | ||
.body(emptyOrNullString()); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
.../vertx-http/deployment/src/test/java/io/quarkus/vertx/http/devui/DevUIRemoteCorsTest.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,39 @@ | ||
package io.quarkus.vertx.http.devui; | ||
|
||
import static org.hamcrest.Matchers.emptyOrNullString; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
import java.net.Inet4Address; | ||
import java.net.UnknownHostException; | ||
|
||
public class DevUIRemoteCorsTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusDevModeTest config = new QuarkusDevModeTest() | ||
.setBuildSystemProperty("quarkus.http.host", "0.0.0.0") | ||
.withEmptyApplication(); | ||
|
||
@Test | ||
public void test() throws UnknownHostException { | ||
String origin = Inet4Address.getLocalHost().toString(); | ||
if(origin.contains("/")){ | ||
origin = "http://" + origin.split("/")[1] + ":8080"; | ||
} | ||
String methods = "GET,POST"; | ||
RestAssured.given() | ||
.header("Origin", origin) | ||
.header("Access-Control-Request-Method", methods) | ||
.when() | ||
.options("q/dev-ui/configuration-form-editor").then() | ||
.statusCode(403) | ||
.body(emptyOrNullString()); | ||
} | ||
|
||
|
||
} |