fix: 修复 TSF header 兼容测试与 polaris-config endpoint 测试的 CI 失败 (#1820)

* 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 <cursoragent@cursor.com>

* chore(docs): 将 CHANGELOG 链接更新为 PR 1820

Co-authored-by: Cursor <cursoragent@cursor.com>

* 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 <cursoragent@cursor.com>

* 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 <cursoragent@cursor.com>

---------

Co-authored-by: evelynwei <evelynwei@tencent.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2025.1
evelynwei 2 days ago committed by GitHub
parent 396928d34d
commit c581e9d961
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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)

@ -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

@ -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<String, Object> content = new HashMap<>();
@ -81,19 +80,23 @@ public class PolarisConfigEndpointTest {
PolarisConfigEndpoint endpoint = new PolarisConfigEndpoint(properties);
Map<String, Object> info = endpoint.polarisConfig();
assertThat(info.get("ClientId")).isNull();
assertThat(info.get("PolarisConfigProperties")).isInstanceOf(Map.class);
Map<String, Object> configProperties = (Map<String, Object>) info.get("PolarisConfigProperties");
assertThat(configProperties).doesNotContainKey("token");
List<Map<String, Object>> sources = (List<Map<String, Object>>) 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<String>) 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

@ -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

Loading…
Cancel
Save