mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(ec2): validate CreateSecurityGroup required parameters (#3888)
This commit is contained in:
1 parent
d348763345
commit
37ac2505e8
3 files changed
+44
-3
No files matched your search
@@ -2902,8 +2902,8 @@ public class Ec2QueryHandler {
|
||||
// ─── Security Group handlers ───────────────────────────────────────────────
|
||||
|
||||
private Response handleCreateSecurityGroup(MultivaluedMap<String, String> p, String region) {
|
||||
String groupName = p.getFirst("GroupName");
|
||||
String description = p.getFirst("GroupDescription");
|
||||
String groupName = requireParameter(p, "GroupName");
|
||||
String description = requireParameter(p, "GroupDescription");
|
||||
String vpcId = p.getFirst("VpcId");
|
||||
SecurityGroup sg = service.createSecurityGroup(region, groupName, description, vpcId);
|
||||
applyResourceTags(p, region, "security-group", sg.getGroupId());
|
||||
@@ -2916,6 +2916,17 @@ public class Ec2QueryHandler {
|
||||
return xmlResponse(xml.build());
|
||||
}
|
||||
|
||||
private static String requireParameter(MultivaluedMap<String, String> params, String parameterName) {
|
||||
String value = params.getFirst(parameterName);
|
||||
if (value == null || value.isBlank()) {
|
||||
throw new AwsException(
|
||||
"MissingParameter",
|
||||
"The request must contain the parameter " + parameterName,
|
||||
400);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private Response handleDescribeSecurityGroups(MultivaluedMap<String, String> p, String region) {
|
||||
List<String> groupIds = getList(p, "GroupId");
|
||||
List<String> groupNames = getList(p, "GroupName");
|
||||
|
||||
@@ -4395,7 +4395,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
|
||||
// Check duplicate
|
||||
String finalVpcId = vpcId;
|
||||
boolean exists = securityGroups.scan(k -> true).stream()
|
||||
.anyMatch(sg -> sg.getRegion().equals(region) && sg.getGroupName().equals(groupName)
|
||||
.anyMatch(sg -> sg.getRegion().equals(region) && Objects.equals(sg.getGroupName(), groupName)
|
||||
&& finalVpcId.equals(sg.getVpcId()));
|
||||
if (exists) {
|
||||
throw new AwsException("InvalidGroup.Duplicate", "The security group '" + groupName + "' already exists", 400);
|
||||
|
||||
@@ -1489,6 +1489,36 @@ class Ec2IntegrationTest {
|
||||
.extract().path("CreateSecurityGroupResponse.groupId");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createSecurityGroupMissingGroupName() {
|
||||
given()
|
||||
.formParam("Action", "CreateSecurityGroup")
|
||||
.formParam("GroupDescription", "Test security group")
|
||||
.formParam("VpcId", vpcId)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("MissingParameter"))
|
||||
.body(containsString("GroupName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createSecurityGroupMissingDescription() {
|
||||
given()
|
||||
.formParam("Action", "CreateSecurityGroup")
|
||||
.formParam("GroupName", "test-security-group")
|
||||
.formParam("VpcId", vpcId)
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body(containsString("MissingParameter"))
|
||||
.body(containsString("GroupDescription"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(31)
|
||||
void authorizeSecurityGroupIngress() {
|
||||
|
||||
Reference in new issue
Block a user