43 lines
2.2 KiB
Java
43 lines
2.2 KiB
Java
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 OverseasSecurityValidationDeploymentContractTest {
|
||
|
|
@Test
|
||
|
|
void gatewayAndEventBridgeUseLastlegSecurityEndpointsWithoutTheRetiredService() throws Exception {
|
||
|
|
String client = read("gateway-overseas/src/main/java/com/baiyue/gateway/filter/HttpOverseasSecurityValidationClient.java");
|
||
|
|
String gatewayApplication = read("gateway-overseas/src/main/resources/application.yml");
|
||
|
|
String gatewayNacos = read("config/nacos/overseas/gateway-overseas.yml");
|
||
|
|
String bridgeApplication = read("event-bridge-service/src/main/resources/application.yml");
|
||
|
|
String bridgeNacos = read("config/nacos/overseas/event-bridge-service.yml");
|
||
|
|
String compose = read("deploy/docker-compose.overseas.yml");
|
||
|
|
|
||
|
|
assertThat(client).contains("/internal/lastleg/security/v1/validate")
|
||
|
|
.contains("new Request(userId, tenantId, permissionVersion)")
|
||
|
|
.doesNotContain("new Request(userId, tenantId, tokenVersion")
|
||
|
|
.doesNotContain("/internal/overseas-security/");
|
||
|
|
for (String source : new String[]{gatewayApplication, gatewayNacos, compose}) {
|
||
|
|
assertThat(source).contains("LASTLEG_SECURITY_SERVICE_URL", "http://lastleg-service:9303");
|
||
|
|
}
|
||
|
|
for (String source : new String[]{bridgeApplication, bridgeNacos, compose}) {
|
||
|
|
assertThat(source).contains("LASTLEG_SECURITY_EVENT_CONSUMER_URL",
|
||
|
|
"/internal/lastleg/security/v1/events");
|
||
|
|
}
|
||
|
|
assertThat(gatewayApplication + gatewayNacos + bridgeApplication + bridgeNacos + compose)
|
||
|
|
.doesNotContain("overseas-security-service", "9307", "OVERSEAS_SECURITY_DB_URL",
|
||
|
|
"OVERSEAS_SECURITY_SERVICE_URL", "OVERSEAS_SECURITY_EVENT_CONSUMER_URL");
|
||
|
|
}
|
||
|
|
|
||
|
|
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);
|
||
|
|
}
|
||
|
|
}
|