From 446da4821a9577b0bb8642c3e25fc75efa073b59 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Fri, 22 Nov 2024 14:14:40 +0100 Subject: [PATCH] Adjust the default of NonApplicationRootPathBuildItem We will always have the config defined except in some weird cases. Let's make sure we use the safest default in these cases. --- .../NonApplicationRootPathBuildItem.java | 5 ++- .../NonApplicationRootPathBuildItemTest.java | 36 +++++++++---------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/NonApplicationRootPathBuildItem.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/NonApplicationRootPathBuildItem.java index ccec6ea59350d..d9517291e5974 100644 --- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/NonApplicationRootPathBuildItem.java +++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/NonApplicationRootPathBuildItem.java @@ -203,7 +203,10 @@ public static String getManagementUrlPrefix() { */ public static String getManagementUrlPrefix(LaunchModeBuildItem mode) { Config config = ConfigProvider.getConfig(); - var managementHost = config.getOptionalValue("quarkus.management.host", String.class).orElse("0.0.0.0"); + // These will always be defined except when the configuration is not properly set up + // (for instance in NonApplicationRootPathBuildItemTest) + // so we default to the safest behavior possible + var managementHost = config.getOptionalValue("quarkus.management.host", String.class).orElse("localhost"); var managementPort = config.getOptionalValue("quarkus.management.port", Integer.class).orElse(9000); if (mode != null && mode.isTest()) { managementPort = config.getOptionalValue("quarkus.management.test-port", Integer.class).orElse(9001); diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/deployment/NonApplicationRootPathBuildItemTest.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/deployment/NonApplicationRootPathBuildItemTest.java index 90796a00e584c..7cf91d24a5264 100644 --- a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/deployment/NonApplicationRootPathBuildItemTest.java +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/deployment/NonApplicationRootPathBuildItemTest.java @@ -118,13 +118,13 @@ void testResolveManagementPathWithRelativeRootPath() { NonApplicationRootPathBuildItem buildItem = new NonApplicationRootPathBuildItem("/", "q", managementInterfaceBuildTimeConfig.rootPath); Assertions.assertEquals("/management/", buildItem.getManagementRootPath()); - Assertions.assertEquals("http://0.0.0.0:9000/management/foo", + Assertions.assertEquals("http://localhost:9000/management/foo", buildItem.resolveManagementPath("foo", managementInterfaceBuildTimeConfig, launchModeBuildItem)); - Assertions.assertEquals("http://0.0.0.0:9000/management/foo/sub/path", + Assertions.assertEquals("http://localhost:9000/management/foo/sub/path", buildItem.resolveManagementPath("foo/sub/path", managementInterfaceBuildTimeConfig, launchModeBuildItem)); - Assertions.assertEquals("http://0.0.0.0:9000/foo", + Assertions.assertEquals("http://localhost:9000/foo", buildItem.resolveManagementPath("/foo", managementInterfaceBuildTimeConfig, launchModeBuildItem)); - Assertions.assertEquals("http://0.0.0.0:9000/foo/sub/path", + Assertions.assertEquals("http://localhost:9000/foo/sub/path", buildItem.resolveManagementPath("/foo/sub/path", managementInterfaceBuildTimeConfig, launchModeBuildItem)); Assertions.assertThrows(IllegalArgumentException.class, () -> buildItem.resolveManagementPath("../foo", managementInterfaceBuildTimeConfig, launchModeBuildItem)); @@ -144,13 +144,13 @@ void testResolveManagementPathWithRelativeRootPathInTestMode() { NonApplicationRootPathBuildItem buildItem = new NonApplicationRootPathBuildItem("/", "q", managementInterfaceBuildTimeConfig.rootPath); Assertions.assertEquals("/management/", buildItem.getManagementRootPath()); - Assertions.assertEquals("http://0.0.0.0:9001/management/foo", + Assertions.assertEquals("http://localhost:9001/management/foo", buildItem.resolveManagementPath("foo", managementInterfaceBuildTimeConfig, launchModeBuildItem)); - Assertions.assertEquals("http://0.0.0.0:9001/management/foo/sub/path", + Assertions.assertEquals("http://localhost:9001/management/foo/sub/path", buildItem.resolveManagementPath("foo/sub/path", managementInterfaceBuildTimeConfig, launchModeBuildItem)); - Assertions.assertEquals("http://0.0.0.0:9001/foo", + Assertions.assertEquals("http://localhost:9001/foo", buildItem.resolveManagementPath("/foo", managementInterfaceBuildTimeConfig, launchModeBuildItem)); - Assertions.assertEquals("http://0.0.0.0:9001/foo/sub/path", + Assertions.assertEquals("http://localhost:9001/foo/sub/path", buildItem.resolveManagementPath("/foo/sub/path", managementInterfaceBuildTimeConfig, launchModeBuildItem)); Assertions.assertThrows(IllegalArgumentException.class, () -> buildItem.resolveManagementPath("../foo", managementInterfaceBuildTimeConfig, launchModeBuildItem)); @@ -196,13 +196,13 @@ void testResolveManagementPathWithAbsoluteRootPath() { NonApplicationRootPathBuildItem buildItem = new NonApplicationRootPathBuildItem("/", "/q", managementInterfaceBuildTimeConfig.rootPath); Assertions.assertEquals("/management/", buildItem.getManagementRootPath()); - Assertions.assertEquals("http://0.0.0.0:9000/management/foo", + Assertions.assertEquals("http://localhost:9000/management/foo", buildItem.resolveManagementPath("foo", managementInterfaceBuildTimeConfig, launchModeBuildItem)); - Assertions.assertEquals("http://0.0.0.0:9000/management/foo/sub/path", + Assertions.assertEquals("http://localhost:9000/management/foo/sub/path", buildItem.resolveManagementPath("foo/sub/path", managementInterfaceBuildTimeConfig, launchModeBuildItem)); - Assertions.assertEquals("http://0.0.0.0:9000/foo", + Assertions.assertEquals("http://localhost:9000/foo", buildItem.resolveManagementPath("/foo", managementInterfaceBuildTimeConfig, launchModeBuildItem)); - Assertions.assertEquals("http://0.0.0.0:9000/foo/sub/path", + Assertions.assertEquals("http://localhost:9000/foo/sub/path", buildItem.resolveManagementPath("/foo/sub/path", managementInterfaceBuildTimeConfig, launchModeBuildItem)); Assertions.assertThrows(IllegalArgumentException.class, () -> buildItem.resolveManagementPath("../foo", managementInterfaceBuildTimeConfig, launchModeBuildItem)); @@ -222,13 +222,13 @@ void testResolveManagementPathWithEmptyRootPath() { NonApplicationRootPathBuildItem buildItem = new NonApplicationRootPathBuildItem("/", "/q", managementInterfaceBuildTimeConfig.rootPath); Assertions.assertEquals("/", buildItem.getManagementRootPath()); - Assertions.assertEquals("http://0.0.0.0:9000/foo", + Assertions.assertEquals("http://localhost:9000/foo", buildItem.resolveManagementPath("foo", managementInterfaceBuildTimeConfig, launchModeBuildItem)); - Assertions.assertEquals("http://0.0.0.0:9000/foo/sub/path", + Assertions.assertEquals("http://localhost:9000/foo/sub/path", buildItem.resolveManagementPath("foo/sub/path", managementInterfaceBuildTimeConfig, launchModeBuildItem)); - Assertions.assertEquals("http://0.0.0.0:9000/foo", + Assertions.assertEquals("http://localhost:9000/foo", buildItem.resolveManagementPath("/foo", managementInterfaceBuildTimeConfig, launchModeBuildItem)); - Assertions.assertEquals("http://0.0.0.0:9000/foo/sub/path", + Assertions.assertEquals("http://localhost:9000/foo/sub/path", buildItem.resolveManagementPath("/foo/sub/path", managementInterfaceBuildTimeConfig, launchModeBuildItem)); Assertions.assertThrows(IllegalArgumentException.class, () -> buildItem.resolveManagementPath("../foo", managementInterfaceBuildTimeConfig, launchModeBuildItem)); @@ -247,9 +247,9 @@ void testResolveManagementPathWithWithWildcards() { NonApplicationRootPathBuildItem buildItem = new NonApplicationRootPathBuildItem("/", "/q", managementInterfaceBuildTimeConfig.rootPath); - Assertions.assertEquals("http://0.0.0.0:9000/management/foo/*", + Assertions.assertEquals("http://localhost:9000/management/foo/*", buildItem.resolveManagementPath("foo/*", managementInterfaceBuildTimeConfig, launchModeBuildItem)); - Assertions.assertEquals("http://0.0.0.0:9000/foo/*", + Assertions.assertEquals("http://localhost:9000/foo/*", buildItem.resolveManagementPath("/foo/*", managementInterfaceBuildTimeConfig, launchModeBuildItem)); } }