Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNS Made Easy does not supports quotes in TXT records #48

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 12 additions & 0 deletions octodns_dnsmadeeasy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions tests/config/unit.tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions tests/fixtures/dnsmadeeasy-records.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 24 additions & 9 deletions tests/test_octodns_provider_dnsmadeeasy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
)
Loading