From b791e045669dafeb38853612dfbd195a613d0733 Mon Sep 17 00:00:00 2001 From: XuJian <265865031+xujiantop-crypto@users.noreply.github.com> Date: Mon, 21 Sep 2026 05:29:58 +0900 Subject: [PATCH] fix(transfer): preserve server detail structures (#3928) * fix(transfer): preserve server detail structures * fix(transfer): preserve endpoint detail value types --- .../services/transfer/TransferHandler.java | 23 ++++- .../services/transfer/TransferService.java | 5 +- ...ransferServerLifecycleIntegrationTest.java | 98 +++++++++++++++++++ .../transfer/TransferServiceTest.java | 19 ++++ 4 files changed, 139 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/transfer/TransferHandler.java b/src/main/java/io/github/hectorvent/floci/services/transfer/TransferHandler.java index fa918afb58..38dbf6cd10 100644 --- a/src/main/java/io/github/hectorvent/floci/services/transfer/TransferHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/transfer/TransferHandler.java @@ -1,5 +1,6 @@ package io.github.hectorvent.floci.services.transfer; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; @@ -125,7 +126,7 @@ public class TransferHandler { List protocols = jsonStringList(req.path("Protocols")); String endpointType = textOrNull(req, "EndpointType"); Map endpointDetails = jsonObjectMap(req.path("EndpointDetails")); - String identityProviderDetails = textOrNull(req, "IdentityProviderDetails"); + Map identityProviderDetails = jsonStringMap(req.path("IdentityProviderDetails")); String loggingRole = textOrNull(req, "LoggingRole"); String securityPolicyName = textOrNull(req, "SecurityPolicyName"); @@ -291,6 +292,14 @@ public class TransferHandler { ArrayNode protocols = node.putArray("Protocols"); s.getProtocols().forEach(protocols::add); } + if (s.getEndpointDetails() != null) { + ObjectNode endpointDetails = objectMapper.valueToTree(s.getEndpointDetails()); + endpointDetails.remove("SecurityGroupIds"); + node.set("EndpointDetails", endpointDetails); + } + if (s.getIdentityProviderDetails() != null) { + node.set("IdentityProviderDetails", objectMapper.valueToTree(s.getIdentityProviderDetails())); + } if (s.getTags() != null && !s.getTags().isEmpty()) { ArrayNode tags = node.putArray("Tags"); s.getTags().forEach((k, v) -> { @@ -385,8 +394,11 @@ public class TransferHandler { } private Map jsonStringMap(JsonNode node) { + if (node == null || node.isMissingNode() || node.isNull()) { + return null; + } Map map = new HashMap<>(); - if (node != null && node.isObject()) { + if (node.isObject()) { node.fields().forEachRemaining(e -> map.put(e.getKey(), e.getValue().asText())); } return map; @@ -396,9 +408,10 @@ public class TransferHandler { if (node == null || node.isMissingNode() || node.isNull()) { return null; } - Map map = new HashMap<>(); - node.fields().forEachRemaining(e -> map.put(e.getKey(), e.getValue().asText())); - return map.isEmpty() ? null : map; + if (!node.isObject()) { + return new HashMap<>(); + } + return objectMapper.convertValue(node, new TypeReference>() {}); } private Map parseTags(JsonNode node) { diff --git a/src/main/java/io/github/hectorvent/floci/services/transfer/TransferService.java b/src/main/java/io/github/hectorvent/floci/services/transfer/TransferService.java index 7bb696d42a..5f1cd8dea1 100644 --- a/src/main/java/io/github/hectorvent/floci/services/transfer/TransferService.java +++ b/src/main/java/io/github/hectorvent/floci/services/transfer/TransferService.java @@ -149,7 +149,7 @@ public class TransferService { List protocols, String endpointType, Map endpointDetails, - String identityProviderDetails, + Map identityProviderDetails, String loggingRole, String securityPolicyName) { Server server = getServer(serverId); @@ -162,6 +162,9 @@ public class TransferService { if (endpointDetails != null) { server.setEndpointDetails(endpointDetails); } + if (identityProviderDetails != null) { + server.setIdentityProviderDetails(identityProviderDetails); + } if (loggingRole != null) { server.setLoggingRole(loggingRole); } diff --git a/src/test/java/io/github/hectorvent/floci/services/transfer/TransferServerLifecycleIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/transfer/TransferServerLifecycleIntegrationTest.java index e6602d0a82..e81d0a66af 100644 --- a/src/test/java/io/github/hectorvent/floci/services/transfer/TransferServerLifecycleIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/transfer/TransferServerLifecycleIntegrationTest.java @@ -5,8 +5,12 @@ import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import java.util.List; + import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.anEmptyMap; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.startsWith; /** @@ -92,6 +96,100 @@ class TransferServerLifecycleIntegrationTest { .body("Server.Domain", equalTo("EFS")); } + @Test + void describeAndUpdateServerPreserveDetailStructures() { + String serverId = given() + .header("X-Amz-Target", "TransferService.CreateServer") + .contentType(CONTENT_TYPE) + .body(""" + { + "EndpointType": "VPC", + "EndpointDetails": { + "VpcId": "vpc-123", + "SubnetIds": ["subnet-a", "subnet-b"] + }, + "IdentityProviderType": "API_GATEWAY", + "IdentityProviderDetails": { + "Url": "https://idp.example.com", + "InvocationRole": "arn:aws:iam::000000000000:role/transfer-idp" + } + } + """) + .when() + .post("/") + .then() + .statusCode(200) + .extract().jsonPath().getString("ServerId"); + + given() + .header("X-Amz-Target", "TransferService.DescribeServer") + .contentType(CONTENT_TYPE) + .body("{\"ServerId\": \"" + serverId + "\"}") + .when() + .post("/") + .then() + .statusCode(200) + .body("Server.EndpointDetails.VpcId", equalTo("vpc-123")) + .body("Server.EndpointDetails.SubnetIds", equalTo(List.of("subnet-a", "subnet-b"))) + .body("Server.IdentityProviderDetails.Url", equalTo("https://idp.example.com")) + .body("Server.IdentityProviderDetails.InvocationRole", + equalTo("arn:aws:iam::000000000000:role/transfer-idp")); + + given() + .header("X-Amz-Target", "TransferService.UpdateServer") + .contentType(CONTENT_TYPE) + .body(""" + { + "ServerId": "%s", + "EndpointDetails": { + "VpcId": "vpc-456", + "SecurityGroupIds": ["sg-a", "sg-b"] + }, + "IdentityProviderDetails": {"Url": "https://other.example.com"} + } + """.formatted(serverId)) + .when() + .post("/") + .then() + .statusCode(200) + .body("ServerId", equalTo(serverId)); + + given() + .header("X-Amz-Target", "TransferService.DescribeServer") + .contentType(CONTENT_TYPE) + .body("{\"ServerId\": \"" + serverId + "\"}") + .when() + .post("/") + .then() + .statusCode(200) + .body("Server.EndpointDetails.VpcId", equalTo("vpc-456")) + .body("Server.EndpointDetails.SecurityGroupIds", nullValue()) + .body("Server.IdentityProviderDetails.Url", equalTo("https://other.example.com")); + + given() + .header("X-Amz-Target", "TransferService.UpdateServer") + .contentType(CONTENT_TYPE) + .body(""" + {"ServerId": "%s", "IdentityProviderDetails": {}} + """.formatted(serverId)) + .when() + .post("/") + .then() + .statusCode(200); + + given() + .header("X-Amz-Target", "TransferService.DescribeServer") + .contentType(CONTENT_TYPE) + .body("{\"ServerId\": \"" + serverId + "\"}") + .when() + .post("/") + .then() + .statusCode(200) + .body("Server.EndpointDetails.VpcId", equalTo("vpc-456")) + .body("Server.EndpointDetails.SecurityGroupIds", nullValue()) + .body("Server.IdentityProviderDetails", anEmptyMap()); + } + @Test void deleteServerWhileOnline() { String serverId = createServer(); diff --git a/src/test/java/io/github/hectorvent/floci/services/transfer/TransferServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/transfer/TransferServiceTest.java index 527e29c1ca..210980326b 100644 --- a/src/test/java/io/github/hectorvent/floci/services/transfer/TransferServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/transfer/TransferServiceTest.java @@ -219,4 +219,23 @@ class TransferServiceTest { assertEquals(Map.of("current", "tag"), service.listTagsForResource(server.getArn())); assertTrue(tagDelegate.get(legacyKey).isEmpty()); } + + @Test + void updateServerPreservesOmittedDetailsAndClearsExplicitEmptyMaps() { + Server server = service.createServer("us-east-1", null, null, "VPC", + Map.of("VpcId", "vpc-123"), "API_GATEWAY", + Map.of("Url", "https://idp.example.com"), null, null, null); + + Server preserved = service.updateServer(server.getServerId(), null, null, null, + null, null, null); + + assertEquals(Map.of("VpcId", "vpc-123"), preserved.getEndpointDetails()); + assertEquals(Map.of("Url", "https://idp.example.com"), preserved.getIdentityProviderDetails()); + + Server cleared = service.updateServer(server.getServerId(), null, null, Map.of(), + Map.of(), null, null); + + assertTrue(cleared.getEndpointDetails().isEmpty()); + assertTrue(cleared.getIdentityProviderDetails().isEmpty()); + } }