Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(transfer): allow DeleteServer regardless of server state (#2897)

BingEdwarde7256f555670
diff --git a/compatibility-tests/compat-opentofu/main.tf b/compatibility-tests/compat-opentofu/main.tf
index e942776d49..0a7a40e512 100644
--- a/compatibility-tests/compat-opentofu/main.tf
+++ b/compatibility-tests/compat-opentofu/main.tf
@@ -661,3 +661,17 @@ output "guardduty_detector_id" {
output "large_object_checksum_sha256" {
value = aws_s3_object.large.checksum_sha256
}
+
+# -- Transfer Family Server (issue #2802) --------------------------------------
+# Never stopped, so destroy exercises DeleteServer against an ONLINE server.
+resource "aws_transfer_server" "compat" {
+ protocols = ["SFTP"]
+
+ tags = {
+ Environment = "compat-test"
+ }
+}
+
+output "transfer_server_id" {
+ value = aws_transfer_server.compat.id
+}
diff --git a/compatibility-tests/compat-opentofu/test/opentofu.bats b/compatibility-tests/compat-opentofu/test/opentofu.bats
index 20c8f4762d..494162cf46 100644
--- a/compatibility-tests/compat-opentofu/test/opentofu.bats
+++ b/compatibility-tests/compat-opentofu/test/opentofu.bats
@@ -443,3 +443,9 @@ sha256_composite_by_sizes() {
assert_success
assert_output "ALL"
}
+
+@test "OpenTofu: Transfer Family server created and ONLINE" {
+ run aws_cmd transfer list-servers --query "Servers[0].State" --output text
+ assert_success
+ assert_output "ONLINE"
+}
diff --git a/compatibility-tests/compat-terraform/main.tf b/compatibility-tests/compat-terraform/main.tf
index 9023d91fff..c656a7714f 100644
--- a/compatibility-tests/compat-terraform/main.tf
+++ b/compatibility-tests/compat-terraform/main.tf
@@ -838,3 +838,17 @@ output "guardduty_detector_arn" {
output "large_object_checksum_sha256" {
value = aws_s3_object.large.checksum_sha256
}
+
+# -- Transfer Family Server (issue #2802) --------------------------------------
+# Never stopped, so destroy exercises DeleteServer against an ONLINE server.
+resource "aws_transfer_server" "compat" {
+ protocols = ["SFTP"]
+
+ tags = {
+ Environment = "compat-test"
+ }
+}
+
+output "transfer_server_id" {
+ value = aws_transfer_server.compat.id
+}
diff --git a/compatibility-tests/compat-terraform/test/terraform.bats b/compatibility-tests/compat-terraform/test/terraform.bats
index fb79293ef9..66c2de5486 100644
--- a/compatibility-tests/compat-terraform/test/terraform.bats
+++ b/compatibility-tests/compat-terraform/test/terraform.bats
@@ -608,3 +608,9 @@ sha256_composite_by_sizes() {
fi
[ "$status" -eq 0 ]
}
+
+@test "Terraform: Transfer Family server created and ONLINE" {
+ run aws_cmd transfer list-servers --query "Servers[0].State" --output text
+ assert_success
+ assert_output "ONLINE"
+}
diff --git a/docs/services/transfer.md b/docs/services/transfer.md
index 4fbfd446c7..70144d5d4e 100644
--- a/docs/services/transfer.md
+++ b/docs/services/transfer.md
@@ -15,7 +15,7 @@ AWS Transfer Family managed file transfer server management. This implementation
| `CreateServer` | Create a managed file transfer server |
| `DescribeServer` | Get server metadata and configuration |
| `UpdateServer` | Update protocols, endpoint type, logging role, security policy |
-| `DeleteServer` | Delete a server (must be in `OFFLINE` state) |
+| `DeleteServer` | Delete a server in any state, along with its users |
| `ListServers` | Paginated list of servers |
| `StartServer` | Transition server from `OFFLINE` to `ONLINE` |
| `StopServer` | Transition server from `ONLINE` to `OFFLINE` |
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 aa921c369e..fa918afb58 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
@@ -63,6 +63,7 @@ public class TransferHandler {
// ── Server handlers ───────────────────────────────────────────────────────
private Response createServer(JsonNode req, String region) {
+ String domain = textOrNull(req, "Domain");
List<String> protocols = jsonStringList(req.path("Protocols"));
String endpointType = textOrNull(req, "EndpointType");
Map<String, Object> endpointDetails = jsonObjectMap(req.path("EndpointDetails"));
@@ -72,7 +73,7 @@ public class TransferHandler {
String securityPolicyName = textOrNull(req, "SecurityPolicyName");
Map<String, String> tags = parseTags(req.path("Tags"));
- Server server = service.createServer(region, protocols, endpointType, endpointDetails,
+ Server server = service.createServer(region, domain, protocols, endpointType, endpointDetails,
identityProviderType, identityProviderDetails, loggingRole, securityPolicyName, tags);
ObjectNode resp = objectMapper.createObjectNode();
@@ -277,6 +278,7 @@ public class TransferHandler {
node.put("ServerId", s.getServerId());
node.put("Arn", s.getArn());
node.put("State", s.getState());
+ node.put("Domain", s.getDomain());
node.put("EndpointType", s.getEndpointType());
node.put("IdentityProviderType", s.getIdentityProviderType());
node.put("SecurityPolicyName", s.getSecurityPolicyName());
@@ -304,6 +306,7 @@ public class TransferHandler {
private ObjectNode buildServerListEntry(Server s) {
ObjectNode node = objectMapper.createObjectNode();
node.put("Arn", s.getArn());
+ node.put("Domain", s.getDomain());
node.put("EndpointType", s.getEndpointType());
node.put("IdentityProviderType", s.getIdentityProviderType());
node.put("ServerId", s.getServerId());
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 7ac88e7fc5..d6bef83ea6 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
@@ -44,6 +44,7 @@ public class TransferService {
// ── Servers ───────────────────────────────────────────────────────────────
public Server createServer(String region,
+ String domain,
List<String> protocols,
String endpointType,
Map<String, Object> endpointDetails,
@@ -59,6 +60,7 @@ public class TransferService {
server.setServerId(serverId);
server.setArn(arn);
server.setState("ONLINE");
+ server.setDomain(domain != null ? domain : "S3");
server.setProtocols(protocols != null && !protocols.isEmpty() ? protocols : List.of("SFTP"));
server.setEndpointType(endpointType != null ? endpointType : "PUBLIC");
server.setEndpointDetails(endpointDetails);
@@ -86,11 +88,9 @@ public class TransferService {
}
public synchronized void deleteServer(String serverId) {
- Server server = getServer(serverId);
- if (!"OFFLINE".equals(server.getState())) {
- throw new AwsException("ConflictException",
- "Server must be in OFFLINE state to be deleted.", 409);
- }
+ // AWS deletes a server in any state: the DeleteServer API defines no
+ // state precondition (and no ConflictException at all).
+ getServer(serverId);
serverStore.delete(serverId);
tagStore.delete("server/" + serverId);
for (User user : userStore.scan(k -> k.startsWith(serverId + "/"))) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/transfer/model/Server.java b/src/main/java/io/github/hectorvent/floci/services/transfer/model/Server.java
index 0ae9a8df60..8034292db8 100644
--- a/src/main/java/io/github/hectorvent/floci/services/transfer/model/Server.java
+++ b/src/main/java/io/github/hectorvent/floci/services/transfer/model/Server.java
@@ -12,6 +12,7 @@ public class Server {
private String serverId;
private String arn;
private String state;
+ private String domain;
private List<String> protocols;
private String endpointType;
private Map<String, Object> endpointDetails;
@@ -34,6 +35,9 @@ public class Server {
public String getState() { return state; }
public void setState(String state) { this.state = state; }
+ public String getDomain() { return domain; }
+ public void setDomain(String domain) { this.domain = domain; }
+
public List<String> getProtocols() { return protocols; }
public void setProtocols(List<String> protocols) { this.protocols = protocols; }
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
new file mode 100644
index 0000000000..e6602d0a82
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/transfer/TransferServerLifecycleIntegrationTest.java
@@ -0,0 +1,185 @@
+package io.github.hectorvent.floci.services.transfer;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.startsWith;
+
+/**
+ * Server lifecycle conformance (#2802): AWS's DeleteServer has no state
+ * precondition (terraform destroy deletes running servers directly, without
+ * calling StopServer first), and a newly created server ends up ONLINE
+ * (terraform's post-create waiter expects STARTING -> ONLINE, never OFFLINE).
+ */
+@QuarkusTest
+class TransferServerLifecycleIntegrationTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private String createServer() {
+ return given()
+ .header("X-Amz-Target", "TransferService.CreateServer")
+ .contentType(CONTENT_TYPE)
+ .body("{}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("ServerId", startsWith("s-"))
+ .extract().jsonPath().getString("ServerId");
+ }
+
+ @Test
+ void createServerComesUpOnline() {
+ String serverId = createServer();
+
+ given()
+ .header("X-Amz-Target", "TransferService.DescribeServer")
+ .contentType(CONTENT_TYPE)
+ .body("{\"ServerId\": \"" + serverId + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("Server.ServerId", equalTo(serverId))
+ .body("Server.State", equalTo("ONLINE"));
+ }
+
+ // terraform-provider-aws reads Domain back from DescribeServer into a
+ // ForceNew attribute defaulting to S3; a missing field re-plans as a
+ // replacement on every run.
+ @Test
+ void describeServerReportsDomain() {
+ String defaulted = createServer();
+
+ given()
+ .header("X-Amz-Target", "TransferService.DescribeServer")
+ .contentType(CONTENT_TYPE)
+ .body("{\"ServerId\": \"" + defaulted + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("Server.Domain", equalTo("S3"));
+
+ String efs = given()
+ .header("X-Amz-Target", "TransferService.CreateServer")
+ .contentType(CONTENT_TYPE)
+ .body("{\"Domain\": \"EFS\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .extract().jsonPath().getString("ServerId");
+
+ given()
+ .header("X-Amz-Target", "TransferService.DescribeServer")
+ .contentType(CONTENT_TYPE)
+ .body("{\"ServerId\": \"" + efs + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("Server.Domain", equalTo("EFS"));
+ }
+
+ @Test
+ void deleteServerWhileOnline() {
+ String serverId = createServer();
+
+ // Never stopped, so still ONLINE - deletion must succeed anyway.
+ given()
+ .header("X-Amz-Target", "TransferService.DeleteServer")
+ .contentType(CONTENT_TYPE)
+ .body("{\"ServerId\": \"" + serverId + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ given()
+ .header("X-Amz-Target", "TransferService.DescribeServer")
+ .contentType(CONTENT_TYPE)
+ .body("{\"ServerId\": \"" + serverId + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(404)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ @Test
+ void deleteServerWhileOffline() {
+ String serverId = createServer();
+
+ given()
+ .header("X-Amz-Target", "TransferService.StopServer")
+ .contentType(CONTENT_TYPE)
+ .body("{\"ServerId\": \"" + serverId + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ given()
+ .header("X-Amz-Target", "TransferService.DeleteServer")
+ .contentType(CONTENT_TYPE)
+ .body("{\"ServerId\": \"" + serverId + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+ }
+
+ @Test
+ void deleteServerCascadesToUsers() {
+ String serverId = createServer();
+
+ given()
+ .header("X-Amz-Target", "TransferService.CreateUser")
+ .contentType(CONTENT_TYPE)
+ .body("""
+ {
+ "ServerId": "%s",
+ "UserName": "alice",
+ "Role": "arn:aws:iam::000000000000:role/transfer-role"
+ }
+ """.formatted(serverId))
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ // Users no longer block deletion of a running server.
+ given()
+ .header("X-Amz-Target", "TransferService.DeleteServer")
+ .contentType(CONTENT_TYPE)
+ .body("{\"ServerId\": \"" + serverId + "\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+ }
+
+ @Test
+ void deleteMissingServerReturnsNotFound() {
+ given()
+ .header("X-Amz-Target", "TransferService.DeleteServer")
+ .contentType(CONTENT_TYPE)
+ .body("{\"ServerId\": \"s-00000000000000000\"}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(404)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+}