优化
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -26,7 +26,7 @@ class OverseasSecurityProjectionFilterTest {
|
||||
private final OverseasSecurityProjectionFilter filter = new OverseasSecurityProjectionFilter(client, new ObjectMapper());
|
||||
|
||||
@Test void disabledUserFailsWithA0401() {
|
||||
when(client.validate(42, 0, 3, 8)).thenReturn(Mono.just(
|
||||
when(client.validate(42, 0, 8)).thenReturn(Mono.just(
|
||||
new OverseasSecurityValidationClient.Result(false, "USER_DISABLED")));
|
||||
var exchange = exchange("/api/platform/v1/last-leg/orders");
|
||||
StepVerifier.create(filter.filter(exchange, ignored -> Mono.empty())).verifyComplete();
|
||||
@@ -36,7 +36,7 @@ class OverseasSecurityProjectionFilterTest {
|
||||
|
||||
@Test void disabledTenantAndStalePermissionFailWithA0403() {
|
||||
for (String reason : new String[]{"TENANT_DISABLED", "PERMISSION_VERSION_STALE"}) {
|
||||
when(client.validate(42, 0, 3, 8)).thenReturn(Mono.just(
|
||||
when(client.validate(42, 0, 8)).thenReturn(Mono.just(
|
||||
new OverseasSecurityValidationClient.Result(false, reason)));
|
||||
var exchange = exchange("/api/merchant/v1/last-leg/orders");
|
||||
StepVerifier.create(filter.filter(exchange, ignored -> Mono.empty())).verifyComplete();
|
||||
@@ -46,14 +46,14 @@ class OverseasSecurityProjectionFilterTest {
|
||||
}
|
||||
|
||||
@Test void projectionUnavailableFailsClosed() {
|
||||
when(client.validate(42, 0, 3, 8)).thenReturn(Mono.error(new IllegalStateException("down")));
|
||||
when(client.validate(42, 0, 8)).thenReturn(Mono.error(new IllegalStateException("down")));
|
||||
var exchange = exchange("/api/platform/v1/last-leg/orders");
|
||||
StepVerifier.create(filter.filter(exchange, ignored -> Mono.empty())).verifyComplete();
|
||||
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test void acceptedSecurityStateContinuesAndNonApiPathsDoNotCallProjection() {
|
||||
when(client.validate(42, 0, 3, 8)).thenReturn(Mono.just(
|
||||
when(client.validate(42, 0, 8)).thenReturn(Mono.just(
|
||||
new OverseasSecurityValidationClient.Result(true, null)));
|
||||
AtomicBoolean routed = new AtomicBoolean();
|
||||
StepVerifier.create(filter.filter(exchange("/api/platform/v1/last-leg/orders"), ignored -> {
|
||||
|
||||
Reference in New Issue
Block a user