mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(core): add opt-in Private Network Access for CORS preflights (#1530)
This commit is contained in:
1 parent
05d050190e
commit
398535ed55
5 files changed
+95
-3
No files matched your search
+60
-1
@@ -41,6 +41,32 @@ class GlobalCorsFilterIntegrationTest {
|
||||
.header("Vary", containsString("Origin"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void preflightRequestingPrivateNetworkAccessIsGranted() {
|
||||
given()
|
||||
.header("Origin", "http://localhost:3000")
|
||||
.header("Access-Control-Request-Method", "POST")
|
||||
.header("Access-Control-Request-Private-Network", "true")
|
||||
.when()
|
||||
.options("/")
|
||||
.then()
|
||||
.statusCode(204)
|
||||
.header("Access-Control-Allow-Origin", equalTo("http://localhost:3000"))
|
||||
.header("Access-Control-Allow-Private-Network", equalTo("true"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void preflightWithoutPrivateNetworkRequestOmitsAllowHeader() {
|
||||
given()
|
||||
.header("Origin", "http://localhost:3000")
|
||||
.header("Access-Control-Request-Method", "POST")
|
||||
.when()
|
||||
.options("/")
|
||||
.then()
|
||||
.statusCode(204)
|
||||
.header("Access-Control-Allow-Private-Network", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void actualRequestFromExtraAllowedOriginGetsCorsHeaders() {
|
||||
given()
|
||||
@@ -77,7 +103,40 @@ class GlobalCorsFilterIntegrationTest {
|
||||
return Map.of(
|
||||
"floci.security.extra-cors-allowed-origins", "http://localhost:3000,https://ui.example.test",
|
||||
"floci.security.extra-cors-allowed-headers", "x-added-header",
|
||||
"floci.security.extra-cors-expose-headers", "x-visible-header");
|
||||
"floci.security.extra-cors-expose-headers", "x-visible-header",
|
||||
"floci.security.cors-allow-private-network", "true");
|
||||
}
|
||||
}
|
||||
|
||||
@QuarkusTest
|
||||
@TestProfile(PrivateNetworkDefaultOffTest.CorsPnaDefaultProfile.class)
|
||||
static class PrivateNetworkDefaultOffTest {
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void privateNetworkAccessNotGrantedByDefault() {
|
||||
given()
|
||||
.header("Origin", "http://localhost:3000")
|
||||
.header("Access-Control-Request-Method", "POST")
|
||||
.header("Access-Control-Request-Private-Network", "true")
|
||||
.when()
|
||||
.options("/")
|
||||
.then()
|
||||
.statusCode(204)
|
||||
.header("Access-Control-Allow-Origin", equalTo("http://localhost:3000"))
|
||||
.header("Access-Control-Allow-Private-Network", nullValue());
|
||||
}
|
||||
|
||||
// Only origins set — cors-allow-private-network left at its (off) default.
|
||||
public static final class CorsPnaDefaultProfile implements QuarkusTestProfile {
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
return Map.of("floci.security.extra-cors-allowed-origins", "http://localhost:3000");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user