Support paths without a beginning slash when setting the root path

Closes #16002
This commit is contained in:
Pedro Igor
2023-01-31 10:05:38 -03:00
committed by Václav Muzikář
parent 51bed81814
commit 263e86e434
4 changed files with 20 additions and 16 deletions

View File

@@ -49,7 +49,7 @@ public interface TransactionalSessionHandler {
* @param session a transactional session
*/
default void close(KeycloakSession session) {
if (DefaultKeycloakSession.class.cast(session).isClosed()) {
if (session == null || DefaultKeycloakSession.class.cast(session).isClosed()) {
return;
}

View File

@@ -30,7 +30,7 @@ quarkus.package.include-dependency-list=false
quarkus.devservices.enabled=false
# We want to expose non-application paths (e.g. health) at the root path
quarkus.http.non-application-root-path=${quarkus.http.root-path}
quarkus.http.non-application-root-path=/${quarkus.http.root-path}
# Disable specific categories from logs
quarkus.log.category."io.quarkus.config".level=off

View File

@@ -69,7 +69,7 @@ public class HealthDistTest {
@Test
void testUsingRelativePath(KeycloakDistribution distribution) {
for (String relativePath : List.of("/auth", "/auth/")) {
for (String relativePath : List.of("/auth", "/auth/", "auth")) {
distribution.run("start-dev", "--health-enabled=true", "--http-relative-path=" + relativePath);
if (!relativePath.endsWith("/")) {
relativePath = relativePath + "/";
@@ -81,7 +81,7 @@ public class HealthDistTest {
@Test
void testMultipleRequests(KeycloakDistribution distribution) throws Exception {
for (String relativePath : List.of("/", "/auth/")) {
for (String relativePath : List.of("/", "/auth/", "auth")) {
distribution.run("start-dev", "--health-enabled=true", "--http-relative-path=" + relativePath);
CompletableFuture future = CompletableFuture.completedFuture(null);
@@ -90,7 +90,13 @@ public class HealthDistTest {
@Override
public void run() {
for (int i = 0; i < 200; i++) {
when().get(relativePath + "health").then().statusCode(200);
String healthPath = "health";
if (!relativePath.endsWith("/")) {
healthPath = "/" + healthPath;
}
when().get(relativePath + healthPath).then().statusCode(200);
}
}
}), future);

View File

@@ -67,14 +67,6 @@ public class MetricsDistTest {
.body(containsString("vendor_cache_manager_keycloak_cache_"));
}
@Test
@Launch({ "start-dev", "--http-relative-path=/auth", "--metrics-enabled=true" })
void testMetricsEndpointUsingRelativePath() {
when().get("/auth/metrics").then()
.statusCode(200)
.body(containsString("jvm_gc_"));
}
@Test
@Launch({ "start-dev", "--metrics-enabled=true" })
void testMetricsEndpointDoesNotEnableHealth() {
@@ -84,7 +76,7 @@ public class MetricsDistTest {
@Test
void testUsingRelativePath(KeycloakDistribution distribution) {
for (String relativePath : List.of("/auth", "/auth/")) {
for (String relativePath : List.of("/auth", "/auth/", "auth")) {
distribution.run("start-dev", "--metrics-enabled=true", "--http-relative-path=" + relativePath);
if (!relativePath.endsWith("/")) {
relativePath = relativePath + "/";
@@ -96,7 +88,7 @@ public class MetricsDistTest {
@Test
void testMultipleRequests(KeycloakDistribution distribution) throws Exception {
for (String relativePath : List.of("/", "/auth/")) {
for (String relativePath : List.of("/", "/auth/", "auth")) {
distribution.run("start-dev", "--metrics-enabled=true", "--http-relative-path=" + relativePath);
CompletableFuture future = CompletableFuture.completedFuture(null);
@@ -105,7 +97,13 @@ public class MetricsDistTest {
@Override
public void run() {
for (int i = 0; i < 200; i++) {
when().get(relativePath + "metrics").then().statusCode(200);
String metricsPath = "metrics";
if (!relativePath.endsWith("/")) {
metricsPath = "/" + metricsPath;
}
when().get(relativePath + metricsPath).then().statusCode(200);
}
}
}), future);