diff --git a/CHANGELOG.md b/CHANGELOG.md index b68f431..abcd626 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v0.0.? - 20??-??-?? - ??? + +* DNS Made Easy does not support quotes in TXT values, add strict_supports check + around it w/False work-around. + ## v0.0.5 - 2023-08-02 - TXT Record Fixes * Fix problems when manipulating TXT records with values longer than 255 characters diff --git a/octodns_dnsmadeeasy/__init__.py b/octodns_dnsmadeeasy/__init__.py index 7aa6936..f5a3b16 100644 --- a/octodns_dnsmadeeasy/__init__.py +++ b/octodns_dnsmadeeasy/__init__.py @@ -354,6 +354,18 @@ def supports(self, record): return super().supports(record) + def _process_desired_zone(self, desired): + for record in desired.records: + if record._type == 'TXT' and any('"' in v for v in record.values): + msg = 'Quotes not supported in TXT values' + fallback = 'removing them' + self.supports_warn_or_except(msg, fallback) + record = record.copy() + record.values = [v.replace('"', '') for v in record.values] + desired.add_record(record, replace=True) + + return desired + def _params_for_multiple(self, record): for value in record.values: yield { diff --git a/tests/config/unit.tests.yaml b/tests/config/unit.tests.yaml index b6f3d18..23463b9 100644 --- a/tests/config/unit.tests.yaml +++ b/tests/config/unit.tests.yaml @@ -149,10 +149,6 @@ ptr: ttl: 300 type: PTR values: [foo.bar.com.] -quotes: - ttl: 600 - type: TXT - value: This is a TXT record with \"quotes\" in it to ensure they are handled correctly spf: ttl: 600 type: SPF diff --git a/tests/fixtures/dnsmadeeasy-records.json b/tests/fixtures/dnsmadeeasy-records.json index cc7cc74..491d5b9 100644 --- a/tests/fixtures/dnsmadeeasy-records.json +++ b/tests/fixtures/dnsmadeeasy-records.json @@ -339,20 +339,6 @@ "redirectType": "Standard - 302", "description": "unsupported record", "type": "HTTPRED" - }, { - "failover": false, - "monitor": false, - "sourceId": 123123, - "dynamicDns": false, - "failed": false, - "gtdLocation": "DEFAULT", - "hardLink": false, - "ttl": 600, - "source": 1, - "name": "quotes", - "value": "\"This is a TXT record with \\\"quotes\\\" in it to ensure they are handled correctly\"", - "id": 11189900, - "type": "TXT" }, { "failover": false, "monitor": false, diff --git a/tests/test_octodns_provider_dnsmadeeasy.py b/tests/test_octodns_provider_dnsmadeeasy.py index 009c248..a36bff1 100644 --- a/tests/test_octodns_provider_dnsmadeeasy.py +++ b/tests/test_octodns_provider_dnsmadeeasy.py @@ -11,6 +11,7 @@ from requests_mock import ANY from requests_mock import mock as requests_mock +from octodns.provider import SupportsException from octodns.provider.yaml import YamlProvider from octodns.record import Record from octodns.zone import Zone @@ -103,14 +104,14 @@ def test_populate(self): zone = Zone('unit.tests.', []) provider.populate(zone) - self.assertEqual(16, len(zone.records)) + self.assertEqual(15, len(zone.records)) changes = self.expected.changes(zone, provider) self.assertEqual(0, len(changes)) # 2nd populate makes no network calls/all from cache again = Zone('unit.tests.', []) provider.populate(again) - self.assertEqual(16, len(again.records)) + self.assertEqual(15, len(again.records)) # bust the cache del provider._zone_records[zone.name] @@ -283,13 +284,6 @@ def test_apply(self): 'type': 'PTR', 'gtdLocation': 'DEFAULT', }, - { - 'value': '"This is a TXT record with \\"quotes\\" in it to ensure they are handled correctly"', - 'name': 'quotes', - 'ttl': 600, - 'type': 'TXT', - 'gtdLocation': 'DEFAULT', - }, { 'value': '"v=spf1 ip4:192.168.0.1/16-all"', 'name': 'spf', @@ -630,3 +624,24 @@ def test_batching_requests(self): any_order=True, ) self.assertEqual(9, provider._client._request.call_count) + + def test_quotes_in_TXT(self): + provider = DnsMadeEasyProvider('test', 'api', 'secret') + desired = Zone('unit.tests.', []) + value = 'This has "quote" chars in it' + txt = Record.new( + desired, 'txt', {'ttl': 42, 'type': 'TXT', 'value': value} + ) + desired.add_record(txt) + + with self.assertRaises(SupportsException) as ctx: + provider._process_desired_zone(desired) + self.assertEqual( + 'test: Quotes not supported in TXT values', str(ctx.exception) + ) + + provider.strict_supports = False + got = provider._process_desired_zone(desired.copy()) + self.assertEqual( + [value.replace('"', '')], next(iter(got.records)).values + )