Light, fluffy, and always free - The AWS Local Emulator alternative
fix(ecs): reject negative desiredCount in CreateService and UpdateService (#1409)
Konda Balaji Rao16b58b99c178
diff --git a/src/main/java/io/github/hectorvent/floci/services/ecs/EcsService.java b/src/main/java/io/github/hectorvent/floci/services/ecs/EcsService.javaindex 808e67b0df..35ff575324 100644--- a/src/main/java/io/github/hectorvent/floci/services/ecs/EcsService.java+++ b/src/main/java/io/github/hectorvent/floci/services/ecs/EcsService.java@@ -590,6 +590,9 @@ public class EcsService {svc.setClusterArn(cluster.getClusterArn());svc.setTaskDefinition(taskDefinition);svc.setLaunchType(launchType != null ? launchType : LaunchType.FARGATE);+ if (desiredCount < 0) {+ throw new AwsException("InvalidParameterException", "desiredCount cannot be a negative number.", 400);+ }svc.setDesiredCount(desiredCount);svc.setLoadBalancers(loadBalancers);svc.setNetworkConfiguration(networkConfiguration);@@ -623,6 +626,9 @@ public class EcsService {"Service " + serviceName + " is not active.", 400);}if (desiredCount != null) {+ if (desiredCount < 0) {+ throw new AwsException("InvalidParameterException", "desiredCount cannot be a negative number.", 400);+ }svc.setDesiredCount(desiredCount);}if (networkConfiguration != null) {diff --git a/src/test/java/io/github/hectorvent/floci/services/ecs/EcsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ecs/EcsIntegrationTest.javaindex 89ea8c527b..7d4f763b81 100644--- a/src/test/java/io/github/hectorvent/floci/services/ecs/EcsIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ecs/EcsIntegrationTest.java@@ -646,6 +646,70 @@ class EcsIntegrationTest {.body("message", containsString("Creation of service was not idempotent."));}+ // ── Negative desiredCount validation (issue #1382) ───────────────────────++ @Test+ @Order(36)+ void createServiceRejectsNegativeDesiredCount() {+ ecs("CreateService")+ .body("""+ {+ "cluster": "%s",+ "serviceName": "negative-count-svc",+ "taskDefinition": "%s",+ "desiredCount": -5,+ "launchType": "FARGATE"+ }+ """.formatted(CLUSTER_NAME, TASK_DEF_FAMILY))+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body("__type", containsString("InvalidParameterException"))+ .body("message", containsString("desiredCount cannot be a negative number."));+ }++++ @Test+ @Order(38)+ void updateServiceRejectsNegativeDesiredCount() {+ ecs("UpdateService")+ .body("""+ {+ "cluster": "%s",+ "service": "%s",+ "desiredCount": -3+ }+ """.formatted(CLUSTER_NAME, SERVICE_NAME))+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body("__type", containsString("InvalidParameterException"))+ .body("message", containsString("desiredCount cannot be a negative number."));+ }++ @Test+ @Order(39)+ void createServiceAcceptsZeroDesiredCount() {+ ecs("CreateService")+ .body("""+ {+ "cluster": "%s",+ "serviceName": "zero-count-svc",+ "taskDefinition": "%s",+ "desiredCount": 0,+ "launchType": "FARGATE"+ }+ """.formatted(CLUSTER_NAME, TASK_DEF_FAMILY))+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body("service.desiredCount", equalTo(0));+ }+// ── Tags ─────────────────────────────────────────────────────────────────@Test