diff --git a/src/main/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployService.java b/src/main/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployService.java index be03949028..af766faeae 100644 --- a/src/main/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployService.java +++ b/src/main/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployService.java @@ -353,6 +353,14 @@ public class CodeDeployService { } public Application getApplication(String region, String name) { + if (name == null || name.isEmpty()) { + throw new AwsException("ApplicationNameRequiredException", + "The minimum number of required characters for applicationName is 1.", 400); + } + if (name.isBlank()) { + throw new AwsException("InvalidApplicationNameException", + "The application name was specified in an invalid format.", 400); + } Application app = applicationsFor(region).get(name); if (app == null) { throw new AwsException("ApplicationDoesNotExistException", diff --git a/src/test/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployIntegrationTest.java index b1310f9a9f..3f0fcad6e4 100644 --- a/src/test/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployIntegrationTest.java @@ -206,6 +206,20 @@ class CodeDeployIntegrationTest { .body("deploymentGroups", hasItem("my-lambda-dg")); } + @Test + @Order(10) + void listDeploymentGroupsWithoutApplicationNameFails() { + given() + .header("X-Amz-Target", "CodeDeploy_20141006.ListDeploymentGroups") + .contentType(CONTENT_TYPE) + .body("{}") + .when() + .post("/") + .then() + .statusCode(400) + .body("__type", containsString("ApplicationNameRequiredException")); + } + @Test @Order(11) void batchGetDeploymentGroups() { diff --git a/src/test/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployServiceTest.java index 218662aa17..961725fa9c 100644 --- a/src/test/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/codedeploy/CodeDeployServiceTest.java @@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.codedeploy; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.hectorvent.floci.core.common.AwsException; import io.github.hectorvent.floci.core.common.RegionResolver; import io.github.hectorvent.floci.services.codedeploy.model.Deployment; import io.github.hectorvent.floci.services.ec2.Ec2Service; @@ -25,6 +26,7 @@ import java.util.concurrent.atomic.AtomicReference; import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -432,6 +434,32 @@ class CodeDeployServiceTest { return (List>) lambdaTarget.get("lifecycleEvents"); } + @Test + void listDeploymentGroupsWithoutApplicationNameThrowsApplicationNameRequired() { + AwsException missing = assertThrows(AwsException.class, + () -> service.listDeploymentGroups("us-east-1", null)); + assertEquals("ApplicationNameRequiredException", missing.getErrorCode()); + assertEquals(400, missing.getHttpStatus()); + AwsException empty = assertThrows(AwsException.class, + () -> service.listDeploymentGroups("us-east-1", "")); + assertEquals("ApplicationNameRequiredException", empty.getErrorCode()); + } + + @Test + void listDeploymentGroupsWithWhitespaceApplicationNameThrowsInvalidApplicationName() { + AwsException blank = assertThrows(AwsException.class, + () -> service.listDeploymentGroups("us-east-1", " ")); + assertEquals("InvalidApplicationNameException", blank.getErrorCode()); + assertEquals(400, blank.getHttpStatus()); + } + + @Test + void listDeploymentGroupsForUnknownApplicationStillThrowsDoesNotExist() { + AwsException unknown = assertThrows(AwsException.class, + () -> service.listDeploymentGroups("us-east-1", "nope")); + assertEquals("ApplicationDoesNotExistException", unknown.getErrorCode()); + } + @SuppressWarnings("unchecked") private Map diagnosticsOf(Map event) { return (Map) event.get("diagnostics");