DNSName key retrieval for list-hosted-zones-by-dns-name (#3774)
* DNSName key retrieval for list-hosted-zones-by-dns-name per https://docs.aws.amazon.com/Route53/latest/APIReference/API_ListHostedZonesByName.html#API_ListHostedZonesByName_RequestSyntax * Route53 - uncomment return to be shared by zone list response - add test to return list hosted zone by dns name without '.' in FQDN Co-authored-by: Tony Greising-Murschel <tony@platform.sh>
This commit is contained in:
parent
9bfd95476b
commit
1b288b6936
@ -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 = """<ListHostedZonesResponse xmlns="https://route53.
|
||||
</ListHostedZonesResponse>"""
|
||||
|
||||
LIST_HOSTED_ZONES_BY_NAME_RESPONSE = """<ListHostedZonesByNameResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
|
||||
{% if dnsname %}
|
||||
<DNSName>{{ dnsname }}</DNSName>
|
||||
{% endif %}
|
||||
<HostedZones>
|
||||
{% for zone in zones %}
|
||||
<HostedZone>
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user