From f3eee5881372b3d76a6f719a558abc3e85737afc Mon Sep 17 00:00:00 2001 From: Martin Maney Date: Fri, 10 Apr 2020 08:43:41 -0500 Subject: [PATCH] =?UTF-8?q?FIX=20#162=20-=20removed=20"*."=20added=20by=20?= =?UTF-8?q?client.py,=20removed=20often=20incomplete=20=E2=80=A6=20(#163)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * FIX #162 - removed "*." added by client.py, removed often incomplete fixes from most providers. * Removed broken tests - drivers are no longer passed *.domain.tld for wildcards Co-authored-by: Martin Maney --- sewer/client.py | 2 -- sewer/dns_providers/acmedns.py | 2 -- sewer/dns_providers/aliyundns.py | 2 -- sewer/dns_providers/auroradns.py | 2 -- sewer/dns_providers/cloudflare.py | 4 ---- sewer/dns_providers/cloudns.py | 6 +++--- sewer/dns_providers/dnspod.py | 9 ++++++--- sewer/dns_providers/duckdns.py | 2 -- sewer/dns_providers/hurricane.py | 2 -- sewer/dns_providers/rackspace.py | 2 -- sewer/dns_providers/tests/test_aliyundns.py | 13 ------------- sewer/dns_providers/tests/test_hedns.py | 13 ------------- 12 files changed, 9 insertions(+), 50 deletions(-) diff --git a/sewer/client.py b/sewer/client.py index 1c2a8a50..8faec464 100644 --- a/sewer/client.py +++ b/sewer/client.py @@ -457,8 +457,6 @@ def get_identifier_authorization(self, url): response_json = response.json() domain = response_json["identifier"]["value"] wildcard = response_json.get("wildcard") - if wildcard: - domain = "*." + domain for i in response_json["challenges"]: if i["type"] == self.auth_provider.auth_type: diff --git a/sewer/dns_providers/acmedns.py b/sewer/dns_providers/acmedns.py index fb55a2df..e11e9341 100644 --- a/sewer/dns_providers/acmedns.py +++ b/sewer/dns_providers/acmedns.py @@ -35,8 +35,6 @@ def __init__(self, ACME_DNS_API_USER, ACME_DNS_API_KEY, ACME_DNS_API_BASE_URL): def create_dns_record(self, domain_name, domain_dns_value): self.logger.info("create_dns_record") - # if we have been given a wildcard name, strip wildcard - domain_name = domain_name.lstrip("*.") resolver = Resolver(configure=False) resolver.nameservers = ["8.8.8.8"] diff --git a/sewer/dns_providers/aliyundns.py b/sewer/dns_providers/aliyundns.py index 202377fc..9cc1a85a 100644 --- a/sewer/dns_providers/aliyundns.py +++ b/sewer/dns_providers/aliyundns.py @@ -150,8 +150,6 @@ def extract_zone(domain_name): :param str domain_name: the value sewer client passed in, like *.menduo.example.com :return tuple: root, zone, acme_txt """ - # if we have been given a wildcard name, strip wildcard - domain_name = domain_name.lstrip("*.") if domain_name.count(".") > 1: zone, middle, last = str(domain_name).rsplit(".", 2) root = ".".join([middle, last]) diff --git a/sewer/dns_providers/auroradns.py b/sewer/dns_providers/auroradns.py index fa579697..b16ac392 100644 --- a/sewer/dns_providers/auroradns.py +++ b/sewer/dns_providers/auroradns.py @@ -33,8 +33,6 @@ def __init__(self, AURORA_API_KEY, AURORA_SECRET_KEY): def create_dns_record(self, domain_name, domain_dns_value): self.logger.info("create_dns_record") - # if we have been given a wildcard name, strip wildcard - domain_name = domain_name.lstrip("*.") extractedDomain = tldextract.extract(domain_name) domainSuffix = extractedDomain.domain + "." + extractedDomain.suffix diff --git a/sewer/dns_providers/cloudflare.py b/sewer/dns_providers/cloudflare.py index 3ccf8dd3..aba9c3ae 100644 --- a/sewer/dns_providers/cloudflare.py +++ b/sewer/dns_providers/cloudflare.py @@ -74,8 +74,6 @@ def find_dns_zone(self, domain_name): def create_dns_record(self, domain_name, domain_dns_value): self.logger.info("create_dns_record") - # if we have been given a wildcard name, strip wildcard - domain_name = domain_name.lstrip("*.") self.find_dns_zone(domain_name) url = urllib.parse.urljoin( @@ -110,8 +108,6 @@ def create_dns_record(self, domain_name, domain_dns_value): def delete_dns_record(self, domain_name, domain_dns_value): self.logger.info("delete_dns_record") - # if we have been given a wildcard name, strip wildcard - domain_name = domain_name.lstrip("*.") class MockResponse(object): def __init__(self, status_code=200, content="mock-response"): diff --git a/sewer/dns_providers/cloudns.py b/sewer/dns_providers/cloudns.py index 69fd1d3d..543cbf27 100644 --- a/sewer/dns_providers/cloudns.py +++ b/sewer/dns_providers/cloudns.py @@ -7,6 +7,9 @@ from . import common +### FIX ME ### this assumes there are only two levels above the host (no bbc.co.uk eg.) + + def _split_domain_name(domain_name): """ClouDNS requires the domain name and host to be split.""" full_domain_name = "_acme-challenge.{}".format(domain_name) @@ -15,9 +18,6 @@ def _split_domain_name(domain_name): domain_name = ".".join(domain_parts[-2:]) host = ".".join(domain_parts[:-2]) - if host == "_acme-challenge.*": - host = "_acme-challenge" - return domain_name, host diff --git a/sewer/dns_providers/dnspod.py b/sewer/dns_providers/dnspod.py index d6a45423..56362351 100644 --- a/sewer/dns_providers/dnspod.py +++ b/sewer/dns_providers/dnspod.py @@ -26,9 +26,10 @@ def __init__(self, DNSPOD_ID, DNSPOD_API_KEY, DNSPOD_API_BASE_URL="https://dnsap def create_dns_record(self, domain_name, domain_dns_value): self.logger.info("create_dns_record") - # if we have been given a wildcard name, strip wildcard - domain_name = domain_name.lstrip("*.") subd = "" + + ### FIX ME ### domain is exactly last two parts (no bbc.co.uk eg.) + if domain_name.count(".") != 1: # not top level domain pos = domain_name.rfind(".", 0, domain_name.rfind(".")) subd = domain_name[:pos] @@ -68,8 +69,10 @@ def create_dns_record(self, domain_name, domain_dns_value): def delete_dns_record(self, domain_name, domain_dns_value): self.logger.info("delete_dns_record") - domain_name = domain_name.lstrip("*.") subd = "" + + ### FIX ME ### domain is exactly last two parts (no bbc.co.uk eg.) + if domain_name.count(".") != 1: # not top level domain pos = domain_name.rfind(".", 0, domain_name.rfind(".")) subd = domain_name[:pos] diff --git a/sewer/dns_providers/duckdns.py b/sewer/dns_providers/duckdns.py index fd0ae21e..b3eb8057 100644 --- a/sewer/dns_providers/duckdns.py +++ b/sewer/dns_providers/duckdns.py @@ -21,8 +21,6 @@ def __init__(self, duckdns_token, DUCKDNS_API_BASE_URL="https://www.duckdns.org" def _common_dns_record(self, logger_info, domain_name, payload_end_arg): self.logger.info("{0}".format(logger_info)) - # if we have been given a wildcard name, strip wildcard - domain_name = domain_name.lstrip("*.") # add provider domain to the domain name if not present provider_domain = ".duckdns.org" if domain_name.rfind(provider_domain) == -1: diff --git a/sewer/dns_providers/hurricane.py b/sewer/dns_providers/hurricane.py index e00bc2dd..cc18a5d9 100644 --- a/sewer/dns_providers/hurricane.py +++ b/sewer/dns_providers/hurricane.py @@ -45,8 +45,6 @@ def extract_zone(domain_name): :param str domain_name: the value sewer client passed in, like *.menduo.example.com :return tuple: root, zone, acme_txt """ - # if we have been given a wildcard name, strip wildcard - domain_name = domain_name.lstrip("*.") if domain_name.count(".") > 1: zone, middle, last = str(domain_name).rsplit(".", 2) root = ".".join([middle, last]) diff --git a/sewer/dns_providers/rackspace.py b/sewer/dns_providers/rackspace.py index b1715849..279ab696 100644 --- a/sewer/dns_providers/rackspace.py +++ b/sewer/dns_providers/rackspace.py @@ -173,8 +173,6 @@ def poll_callback_url(self, callback_url): def create_dns_record(self, domain_name, domain_dns_value): self.logger.info("create_dns_record") - # strip wildcard if present - domain_name = domain_name.lstrip("*.") self.RACKSPACE_DNS_ZONE_ID = self.find_dns_zone_id(domain_name) record_name = "_acme-challenge." + domain_name url = urllib.parse.urljoin( diff --git a/sewer/dns_providers/tests/test_aliyundns.py b/sewer/dns_providers/tests/test_aliyundns.py index 92511ea5..0f93e6c9 100644 --- a/sewer/dns_providers/tests/test_aliyundns.py +++ b/sewer/dns_providers/tests/test_aliyundns.py @@ -33,13 +33,6 @@ def test_extract_zone_sub_domain(self): self.assertEqual(zone, _zone) self.assertEqual(acme_txt, "_acme-challenge.%s" % zone) - domain = "*.%s.%s" % (_zone, self.domain_name) - root, zone, acme_txt = self.dns_class.extract_zone(domain) - - self.assertEqual(root, self.domain_name) - self.assertEqual(zone, _zone) - self.assertEqual(acme_txt, "_acme-challenge.%s" % zone) - def test_extract_zone_root(self): domain = self.domain_name root, zone, acme_txt = self.dns_class.extract_zone(domain) @@ -47,12 +40,6 @@ def test_extract_zone_root(self): self.assertEqual(zone, "") self.assertEqual(acme_txt, "_acme-challenge") - domain = "*." + self.domain_name - root, zone, acme_txt = self.dns_class.extract_zone(domain) - self.assertEqual(root, self.domain_name) - self.assertEqual(zone, "") - self.assertEqual(acme_txt, "_acme-challenge") - def test_aliyun_is_called_by_create_dns_record(self): with mock.patch("requests.post") as mock_requests_post, mock.patch( "sewer.AliyunDns.delete_dns_record" diff --git a/sewer/dns_providers/tests/test_hedns.py b/sewer/dns_providers/tests/test_hedns.py index 9f012449..54e555f4 100644 --- a/sewer/dns_providers/tests/test_hedns.py +++ b/sewer/dns_providers/tests/test_hedns.py @@ -35,13 +35,6 @@ def test_extract_zone_sub_domain(self): self.assertEqual(zone, _zone) self.assertEqual(acme_txt, "_acme-challenge.%s" % zone) - domain = "*.%s.%s" % (_zone, self.domain_name) - root, zone, acme_txt = self.dns_class.extract_zone(domain) - - self.assertEqual(root, self.domain_name) - self.assertEqual(zone, _zone) - self.assertEqual(acme_txt, "_acme-challenge.%s" % zone) - def test_extract_zone_root(self): domain = self.domain_name root, zone, acme_txt = self.dns_class.extract_zone(domain) @@ -49,12 +42,6 @@ def test_extract_zone_root(self): self.assertEqual(zone, "") self.assertEqual(acme_txt, "_acme-challenge") - domain = "*." + self.domain_name - root, zone, acme_txt = self.dns_class.extract_zone(domain) - self.assertEqual(root, self.domain_name) - self.assertEqual(zone, "") - self.assertEqual(acme_txt, "_acme-challenge") - def test_hedns_is_called_by_create_dns_record(self): with mock.patch("requests.post") as mock_requests_post, mock.patch( "sewer.HurricaneDns.delete_dns_record"