Skip to content

Commit

Permalink
Fix: handling of boolean value privateDnsEnabled in ec2:VpcEndpoint
Browse files Browse the repository at this point in the history
* Properly coerce `privateDnsEnabled` to boolean value when parsing requests.
* Per AWS spec, default `privateDnsEnabled` request value to `True`.
* Properly serialize `privateDnsEnabled` as boolean value in responses.
* Add test coverage.

Ref: #3540
  • Loading branch information
bpandola committed Dec 16, 2020
1 parent a31599d commit 411e32e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions moto/ec2/responses/vpcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def create_vpc_endpoint(self):
policy_document = self._get_param("PolicyDocument")
client_token = self._get_param("ClientToken")
tag_specifications = self._get_param("TagSpecifications")
private_dns_enabled = self._get_param("PrivateDNSEnabled")
private_dns_enabled = self._get_bool_param("PrivateDNSEnabled", if_none=True)
security_group = self._get_param("SecurityGroup")

vpc_end_point = self.ec2_backend.create_vpc_endpoint(
Expand Down Expand Up @@ -456,6 +456,7 @@ def describe_vpc_endpoints(self):
<item>{{ subnetId }}</item>
{% endfor %}
</subnetIdSet>
<privateDnsEnabled>{{ 'true' if vpc_end_point.private_dns_enabled else 'false' }}</privateDnsEnabled>
<dnsEntrySet>
{% if vpc_end_point.dns_entries %}
{% for entry in vpc_end_point.dns_entries %}
Expand Down Expand Up @@ -511,7 +512,7 @@ def describe_vpc_endpoints(self):
<policyDocument>{{ vpc_end_point.policy_document }}</policyDocument>
{% endif %}
<state>available</state>
<privateDnsEnabled>{{ vpc_end_point.private_dns_enabled }}</privateDnsEnabled>
<privateDnsEnabled>{{ 'true' if vpc_end_point.private_dns_enabled else 'false' }}</privateDnsEnabled>
<serviceName>{{ vpc_end_point.service_name }}</serviceName>
<vpcId>{{ vpc_end_point.vpc_id }}</vpcId>
<vpcEndpointId>{{ vpc_end_point.id }}</vpcEndpointId>
Expand Down
5 changes: 5 additions & 0 deletions tests/test_ec2/test_vpcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,11 @@ def test_describe_vpc_end_points():
)

vpc_endpoints = ec2.describe_vpc_endpoints()
assert (
vpc_endpoints.get("VpcEndpoints")[0].get("PrivateDnsEnabled")
is vpc_end_point.get("VpcEndpoint").get("PrivateDnsEnabled")
is True
)
assert vpc_endpoints.get("VpcEndpoints")[0].get(
"VpcEndpointId"
) == vpc_end_point.get("VpcEndpoint").get("VpcEndpointId")
Expand Down

0 comments on commit 411e32e

Please sign in to comment.