diff --git a/moto/route53/responses.py b/moto/route53/responses.py index e831820e..f804fa30 100644 --- a/moto/route53/responses.py +++ b/moto/route53/responses.py @@ -53,10 +53,9 @@ class Route53(BaseResponse): dnsname = query_params.get("dnsname") if dnsname: - dnsname = dnsname[ - 0 - ] # parse_qs gives us a list, but this parameter doesn't repeat - # return all zones with that name (there can be more than one) + dnsname = dnsname[0] + if dnsname[-1] != ".": + dnsname += "." zones = [ zone for zone in route53_backend.get_all_hosted_zones() @@ -76,7 +75,7 @@ class Route53(BaseResponse): zones = sorted(zones, key=sort_key) template = Template(LIST_HOSTED_ZONES_BY_NAME_RESPONSE) - return 200, headers, template.render(zones=zones) + return 200, headers, template.render(zones=zones, dnsname=dnsname) def get_or_delete_hostzone_response(self, request, full_url, headers): self.setup_class(request, full_url, headers) @@ -354,6 +353,9 @@ LIST_HOSTED_ZONES_RESPONSE = """ + {% if dnsname %} + {{ dnsname }} + {% endif %} {% for zone in zones %} diff --git a/tests/test_route53/test_route53.py b/tests/test_route53/test_route53.py index 8ce5272e..135f411e 100644 --- a/tests/test_route53/test_route53.py +++ b/tests/test_route53/test_route53.py @@ -506,6 +506,54 @@ def test_list_hosted_zones_by_name(): zones["HostedZones"][2]["Name"].should.equal("test.a.org.") +@mock_route53 +def test_list_hosted_zones_by_dns_name(): + conn = boto3.client("route53", region_name="us-east-1") + conn.create_hosted_zone( + Name="test.b.com.", + CallerReference=str(hash("foo")), + HostedZoneConfig=dict(PrivateZone=True, Comment="test com"), + ) + conn.create_hosted_zone( + Name="test.a.org.", + CallerReference=str(hash("bar")), + HostedZoneConfig=dict(PrivateZone=True, Comment="test org"), + ) + conn.create_hosted_zone( + Name="test.a.org.", + CallerReference=str(hash("bar")), + HostedZoneConfig=dict(PrivateZone=True, Comment="test org 2"), + ) + conn.create_hosted_zone( + Name="my.test.net.", + CallerReference=str(hash("baz")), + HostedZoneConfig=dict(PrivateZone=False, Comment="test net"), + ) + + # test lookup + zones = conn.list_hosted_zones_by_name(DNSName="test.b.com.") + len(zones["HostedZones"]).should.equal(1) + zones["DNSName"].should.equal("test.b.com.") + zones = conn.list_hosted_zones_by_name(DNSName="test.a.org.") + len(zones["HostedZones"]).should.equal(2) + zones["DNSName"].should.equal("test.a.org.") + zones["DNSName"].should.equal("test.a.org.") + zones = conn.list_hosted_zones_by_name(DNSName="my.test.net.") + len(zones["HostedZones"]).should.equal(1) + zones["DNSName"].should.equal("my.test.net.") + zones = conn.list_hosted_zones_by_name(DNSName="my.test.net") + len(zones["HostedZones"]).should.equal(1) + zones["DNSName"].should.equal("my.test.net.") + + # test sort order + zones = conn.list_hosted_zones_by_name() + len(zones["HostedZones"]).should.equal(4) + zones["HostedZones"][0]["Name"].should.equal("test.b.com.") + zones["HostedZones"][1]["Name"].should.equal("my.test.net.") + zones["HostedZones"][2]["Name"].should.equal("test.a.org.") + zones["HostedZones"][3]["Name"].should.equal("test.a.org.") + + @mock_route53 def test_change_resource_record_sets_crud_valid(): conn = boto3.client("route53", region_name="us-east-1")