diff --git a/lemur/plugins/lemur_acme/route53.py b/lemur/plugins/lemur_acme/route53.py index 87b1c51ace..f54f2a73d6 100644 --- a/lemur/plugins/lemur_acme/route53.py +++ b/lemur/plugins/lemur_acme/route53.py @@ -26,9 +26,11 @@ def _find_zone_id(domain, client=None): for page in paginator.paginate(): for zone in page["HostedZones"]: - if domain.endswith(zone["Name"]) or (domain + ".").endswith(zone["Name"]): + # strip the trailing "." to match against the domain (but return the full, original value) + zone_name = zone["Name"].rstrip(".") + if domain == zone_name or domain.endswith("." + zone_name): if not zone["Config"]["PrivateZone"]: - diff_length = len(domain) - len(zone["Name"]) + diff_length = len(domain) - len(zone_name) if diff_length < min_diff_length: min_diff_length = diff_length chosen_zone = (zone["Name"], zone["Id"]) diff --git a/lemur/plugins/lemur_acme/tests/test_route53.py b/lemur/plugins/lemur_acme/tests/test_route53.py index 3d08e6306a..2f7c4bbbcb 100644 --- a/lemur/plugins/lemur_acme/tests/test_route53.py +++ b/lemur/plugins/lemur_acme/tests/test_route53.py @@ -24,6 +24,9 @@ def test_zone_selection(app): # noqa # Replace this with reference to your function assert _find_zone_id("test.dev.acme.identity.uq.edu.au", client) == "Z2" assert _find_zone_id("another.dev.acme.identity.uq.edu.au", client) == "Z2" + assert _find_zone_id("dev.acme.identity.uq.edu.au", client) == "Z2" + assert _find_zone_id("anotherdev.acme.identity.uq.edu.au", client) == "Z1" + assert _find_zone_id("acme.identity.uq.edu.au", client) == "Z1" assert _find_zone_id("test2.acme.identity.uq.edu.au", client) == "Z1" # Test that it raises a ValueError for a domain where no matching zone is found