From c581e9d96154183f05347f8610aa929811729655 Mon Sep 17 00:00:00 2001 From: evelynwei <984178308@qq.com> Date: Thu, 10 Sep 2026 11:59:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20TSF=20header=20?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=B5=8B=E8=AF=95=E4=B8=8E=20polaris-config?= =?UTF-8?q?=20endpoint=20=E6=B5=8B=E8=AF=95=E7=9A=84=20CI=20=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=20(#1820)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: exclude gateway classpath warning auto configuration in TSF header compatible test MetadataLocalPropertiesTsfHeaderCompatibleTest was the only @SpringBootTest in spring-cloud-tencent-commons without an inline web-application-type and gateway auto configuration excludes. Because spring-webmvc and spring-cloud-gateway (webflux) coexist on the test classpath, Boot deduced a servlet context and GatewayClassPathWarningAutoConfiguration aborted startup with MvcFoundOnClasspathException. Align the properties with MetadataLocalPropertiesTest. Co-authored-by: Cursor * chore(docs): 将 CHANGELOG 链接更新为 PR 1820 Co-authored-by: Cursor * fix: exclude gateway auto-config in TSF header decode test Prevent servlet-based SpringBootTest from hitting MvcFoundOnClasspathException, which triggered FailedEventApplicationListener.System.exit(0) and aborted the Surefire fork. Co-authored-by: Cursor * fix: drop Jackson 2 dependency from polaris config endpoint test The module has no Jackson on the test classpath and the project has moved to Jackson 3, so importing com.fasterxml.jackson.databind broke testCompile. Assert on the endpoint map directly instead of serializing it. Co-authored-by: Cursor --------- Co-authored-by: evelynwei Co-authored-by: Cursor --- CHANGELOG.md | 1 + ...DecodeTransferTsfHeaderCompatibleTest.java | 3 ++- .../endpoint/PolarisConfigEndpointTest.java | 23 +++++++++++-------- ...ocalPropertiesTsfHeaderCompatibleTest.java | 5 +++- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e66f540dc..747d09435 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,3 +19,4 @@ - [feat: support config effective value ](https://github.com/Tencent/spring-cloud-tencent/pull/1815) - [feat: support encoding and decoding TSF headers without TSF Consul](https://github.com/Tencent/spring-cloud-tencent/pull/1816) - [feat: protect encrypted config values and improve config cache fallback](https://github.com/Tencent/spring-cloud-tencent/pull/1818) +- [fix: exclude gateway classpath warning auto configuration in TSF header compatible test](https://github.com/Tencent/spring-cloud-tencent/pull/1820) diff --git a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/DecodeTransferTsfHeaderCompatibleTest.java b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/DecodeTransferTsfHeaderCompatibleTest.java index a97ff0691..0081845f0 100644 --- a/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/DecodeTransferTsfHeaderCompatibleTest.java +++ b/spring-cloud-starter-tencent-metadata-transfer/src/test/java/com/tencent/cloud/metadata/core/DecodeTransferTsfHeaderCompatibleTest.java @@ -48,7 +48,8 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen properties = {"spring.config.location = classpath:application-test.yml", "spring.main.web-application-type = servlet", "spring.cloud.gateway.enabled = false", - "spring.cloud.tencent.metadata.tsf-header-compatible = true"}) + "spring.cloud.tencent.metadata.tsf-header-compatible = true", + "spring.autoconfigure.exclude=org.springframework.cloud.gateway.config.GatewayAutoConfiguration,org.springframework.cloud.gateway.config.GatewayClassPathWarningAutoConfiguration,org.springframework.cloud.gateway.config.GatewayMetricsAutoConfiguration"}) public class DecodeTransferTsfHeaderCompatibleTest { @Autowired diff --git a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpointTest.java b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpointTest.java index cd184b54a..4a2108095 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpointTest.java +++ b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/endpoint/PolarisConfigEndpointTest.java @@ -21,7 +21,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.fasterxml.jackson.databind.ObjectMapper; import com.tencent.cloud.polaris.config.PolarisConfigSDKContextManager; import com.tencent.cloud.polaris.config.adapter.MockedConfigKVFile; import com.tencent.cloud.polaris.config.adapter.PolarisPropertySource; @@ -67,7 +66,7 @@ public class PolarisConfigEndpointTest { @Test @SuppressWarnings("unchecked") - public void testPolarisConfigEndpoint() throws Exception { + public void testPolarisConfigEndpoint() { PolarisConfigProperties properties = new PolarisConfigProperties(); properties.setToken("endpoint-must-not-expose-this-token"); Map content = new HashMap<>(); @@ -81,19 +80,23 @@ public class PolarisConfigEndpointTest { PolarisConfigEndpoint endpoint = new PolarisConfigEndpoint(properties); Map info = endpoint.polarisConfig(); + assertThat(info.get("ClientId")).isNull(); assertThat(info.get("PolarisConfigProperties")).isInstanceOf(Map.class); + Map configProperties = (Map) info.get("PolarisConfigProperties"); + assertThat(configProperties).doesNotContainKey("token"); List> sources = (List>) info.get("PolarisPropertySource"); assertThat(sources).hasSize(1); assertThat(sources.get(0)).containsEntry("namespace", testNamespace) .containsEntry("group", testServiceName) - .containsEntry("fileName", testFileName); - - // Actuator serializes the return value. Keep it to plain DTO structures and never expose - // property values through this diagnostic endpoint. - String json = new ObjectMapper().writeValueAsString(info); - assertThat(json).contains("\"ClientId\":null", "\"propertyNames\":[") - .doesNotContain("sensitive-value-one", "sensitive-value-two", "sensitive-value-three", - "endpoint-must-not-expose-this-token"); + .containsEntry("fileName", testFileName) + .containsKey("propertyNames") + .doesNotContainKeys("k1", "k2", "k3"); + assertThat((List) sources.get(0).get("propertyNames")).containsExactlyInAnyOrder("k1", "k2", "k3"); + + // Endpoint returns plain maps for actuator serialization and must not leak credentials + // or property values into the diagnostic payload. + assertThat(String.valueOf(info)).doesNotContain("sensitive-value-one", "sensitive-value-two", + "sensitive-value-three", "endpoint-must-not-expose-this-token"); } @Test diff --git a/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/config/MetadataLocalPropertiesTsfHeaderCompatibleTest.java b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/config/MetadataLocalPropertiesTsfHeaderCompatibleTest.java index 068527bda..ef592c33a 100644 --- a/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/config/MetadataLocalPropertiesTsfHeaderCompatibleTest.java +++ b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/metadata/config/MetadataLocalPropertiesTsfHeaderCompatibleTest.java @@ -34,7 +34,10 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = MetadataLocalPropertiesTsfHeaderCompatibleTest.TestApplication.class, properties = {"spring.config.location = classpath:application-test.yml", - "spring.cloud.tencent.metadata.tsf-header-compatible=true"}) + "spring.main.web-application-type = servlet", + "spring.cloud.gateway.enabled = false", + "spring.cloud.tencent.metadata.tsf-header-compatible=true", + "spring.autoconfigure.exclude=org.springframework.cloud.gateway.config.GatewayAutoConfiguration,org.springframework.cloud.gateway.config.GatewayClassPathWarningAutoConfiguration,org.springframework.cloud.gateway.config.GatewayMetricsAutoConfiguration"}) public class MetadataLocalPropertiesTsfHeaderCompatibleTest { @Autowired