package com.baiyue.gateway.config; import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import static org.assertj.core.api.Assertions.assertThat; class PdaSessionValidationDeploymentContractTest { @Test void nacosComposeAndJenkinsDeploymentRequireOnlyEnvironmentBackedAuthCoordinates() throws Exception { String application = read("gateway-overseas/src/main/resources/application.yml"); String nacos = read("config/nacos/overseas/baiyue-common.yml"); String compose = read("deploy/docker-compose.overseas.yml"); String deployServices = read("deploy/scripts/deploy-services.sh"); String deployBuiltService = read("deploy/scripts/deploy-built-service.sh"); String jenkins = read("Jenkinsfile"); for (String source : new String[]{application, nacos, compose}) { assertThat(source).contains("AUTH_SESSION_VALIDATION_URL", "INTERNAL_SERVICE_TOKEN", "PDA_SESSION_VALIDATION_TIMEOUT"); } assertThat(deployServices).contains("gateway-overseas", "AUTH_SESSION_VALIDATION_URL"); assertThat(deployBuiltService).contains("gateway-overseas", "AUTH_SESSION_VALIDATION_URL"); assertThat(jenkins).contains("'gateway-overseas': 'SERVICE_GATEWAY_OVERSEAS'", "'auth': 'SERVICE_AUTH'", "'iam': 'SERVICE_IAM'"); assertThat(application).doesNotContain("/internal/auth/accounts/overseas-session/validate"); assertThat(read("gateway-overseas/src/main/resources/application-overseas.yml")) .doesNotContain("/internal/auth/**", "/internal/auth/accounts/overseas-session/validate"); assertThat(read("gateway-overseas/src/main/java/com/baiyue/gateway/filter/HttpPdaSessionValidationClient.java")) .contains("new Request(userId, tokenVersion, overseasWarehouseId)", ".header(\"X-Internal-Service-Token\"") .doesNotContain("Authorization", "accessToken", "rawToken", "getTokenValue"); } private static String read(String relative) throws Exception { Path path = Path.of(relative); if (!Files.exists(path)) path = Path.of("..").resolve(relative); return Files.readString(path, StandardCharsets.UTF_8); } }