85 lines
4.9 KiB
Java
85 lines
4.9 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 {
|
|
private static final String HEADER_SIZE =
|
|
"max-http-request-header-size: ${SERVER_MAX_HTTP_REQUEST_HEADER_SIZE:32KB}";
|
|
|
|
@Test
|
|
void gatewayLocalJwtDefaultsMatchAuthAndLastleg() throws Exception {
|
|
String gatewayApplication = read("gateway-overseas/src/main/resources/application.yml");
|
|
String lastlegApplication = read("lastleg-service/src/main/resources/application.yml");
|
|
String localGateway = read("config/nacos/local/gateway-overseas.yml");
|
|
String localLastleg = read("config/nacos/local/lastleg-service.yml");
|
|
String localWarehouse = read("config/nacos/local/warehouse-overseas-service.yml");
|
|
String remoteGateway = read("config/nacos/overseas/gateway-overseas.yml");
|
|
String remoteLastleg = read("config/nacos/overseas/lastleg-service.yml");
|
|
String remoteWarehouse = read("config/nacos/overseas/warehouse-overseas-service.yml");
|
|
|
|
for (String source : new String[]{gatewayApplication, lastlegApplication, localGateway, localLastleg, localWarehouse}) {
|
|
assertThat(source)
|
|
.contains("${JWT_ISSUER:auth-service}")
|
|
.contains("${JWT_AUDIENCE:lastleg-api}")
|
|
.contains("${JWT_JWK_SET_URI:http://127.0.0.1:9100/api/auth/.well-known/jwks.json}");
|
|
}
|
|
assertThat(gatewayApplication).doesNotContain("auth.example.com");
|
|
assertThat(localGateway)
|
|
.contains("${AUTH_SESSION_VALIDATION_URL:http://127.0.0.1:9100}")
|
|
.contains("${LASTLEG_SECURITY_SERVICE_URL:http://127.0.0.1:9303}");
|
|
assertThat(localLastleg).contains("${WAREHOUSE_OVERSEAS_SERVICE_URL:http://127.0.0.1:9305}");
|
|
assertThat(localWarehouse).contains("${DOMESTIC_WAREHOUSE_URL:http://127.0.0.1:9205}");
|
|
assertThat(remoteGateway + remoteLastleg + remoteWarehouse)
|
|
.doesNotContain("127.0.0.1", "root", "123456");
|
|
assertThat(remoteGateway).contains("${LASTLEG_SECURITY_SERVICE_URL:http://lastleg-service:9303}");
|
|
assertThat(remoteLastleg).contains("${LASTLEG_DB_URL}", "${LASTLEG_DB_USERNAME}", "${LASTLEG_DB_PASSWORD}");
|
|
assertThat(remoteWarehouse).contains("${WAREHOUSE_DB_URL}", "${WAREHOUSE_DB_USERNAME}", "${WAREHOUSE_DB_PASSWORD}");
|
|
}
|
|
|
|
@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");
|
|
}
|
|
|
|
@Test
|
|
void overseasAuthorizationSnapshotHeadersFitEveryServletService() throws Exception {
|
|
assertThat(read("config/nacos/overseas/baiyue-common.yml")).contains(HEADER_SIZE);
|
|
assertThat(read("lastleg-service/src/main/resources/application.yml")).contains(HEADER_SIZE);
|
|
assertThat(read("warehouse-overseas-service/src/main/resources/application.yml")).contains(HEADER_SIZE);
|
|
assertThat(read("deploy/docker-compose.overseas.yml"))
|
|
.contains("SERVER_MAX_HTTP_REQUEST_HEADER_SIZE: ${SERVER_MAX_HTTP_REQUEST_HEADER_SIZE:-32KB}");
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|