diff --git a/moto/ec2/responses/security_groups.py b/moto/ec2/responses/security_groups.py index ab5d3b1eb..ed50c796b 100644 --- a/moto/ec2/responses/security_groups.py +++ b/moto/ec2/responses/security_groups.py @@ -22,7 +22,6 @@ def process_rules_from_querystring(querystring): if 'IpPermissions.1.IpRanges' in key: ip_ranges.append(value[0]) - source_groups = [] source_group_ids = [] @@ -45,7 +44,11 @@ class SecurityGroups(BaseResponse): def create_security_group(self): name = self.querystring.get('GroupName')[0] - description = self.querystring.get('GroupDescription')[0] + try: + description = self.querystring.get('GroupDescription')[0] + except TypeError: + # No description found, return error + return "The request must contain the parameter GroupDescription", dict(status=400) vpc_id = self.querystring.get("VpcId", [None])[0] group = ec2_backend.create_security_group(name, description, vpc_id=vpc_id) if not group: diff --git a/tests/test_ec2/test_security_groups.py b/tests/test_ec2/test_security_groups.py index c48a59b6c..8ae03be4f 100644 --- a/tests/test_ec2/test_security_groups.py +++ b/tests/test_ec2/test_security_groups.py @@ -21,6 +21,12 @@ def test_create_and_describe_security_group(): all_groups[0].name.should.equal('test security group') +@mock_ec2 +def test_create_security_group_without_description_raises_error(): + conn = boto.connect_ec2('the_key', 'the_secret') + conn.create_security_group.when.called_with('test security group', '').should.throw(EC2ResponseError) + + @mock_ec2 def test_create_and_describe_vpc_security_group(): conn = boto.connect_ec2('the_key', 'the_secret')