Skip to content

Commit f12fea2

Browse files
committed
Normalize Resend tracking DNS within the sending domain
1 parent f400092 commit f12fea2

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

‎src/pocketdeploy/services.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,12 @@ def _email_dns(self, domain):
263263
raise DeployError('Resend returned an unsupported DNS record.')
264264
name = name.rstrip('.')
265265
suffix = self.c['smtp-domain']
266-
if name in ('send', 'resend._domainkey'):
266+
if name in ('send', 'resend._domainkey', 'rsend'):
267267
name += '.' + suffix
268268
elif getattr(self, 'zone_name', None) and suffix.endswith('.' + self.zone_name):
269-
relative = suffix[:-(len(self.zone_name) + 1)]
270-
if name in ('send.' + relative, 'resend._domainkey.' + relative):
271-
name += '.' + self.zone_name
269+
candidate = name + '.' + self.zone_name
270+
if candidate == suffix or candidate.endswith('.' + suffix):
271+
name = candidate
272272
if name != suffix and not name.endswith('.' + suffix):
273273
raise DeployError('Resend requested DNS outside the configured sending domain.')
274274
record = {'type': kind, 'name': name, 'content': value}

‎tests/test_services.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,12 @@ def test_pending_domain_preflight_blocks_before_compute(service, monkeypatch):
255255
with pytest.raises(DeployError) as error:
256256
service.preflight()
257257
assert error.value.code == 'provider_recovery_required'
258+
259+
260+
def test_resend_zone_relative_cname_stays_within_sending_domain(service):
261+
service.c['smtp-domain'] = 'notifications.example.com'
262+
service.zone_name = 'example.com'
263+
records = service._email_dns({'records': [{'name': 'rsend.notifications', 'type': 'CNAME', 'value': 'tracking.resend.com'}]})
264+
assert records[0]['name'] == 'rsend.notifications.example.com'
265+
with pytest.raises(DeployError, match='outside'):
266+
service._email_dns({'records': [{'name': 'rsend.other', 'type': 'CNAME', 'value': 'tracking.resend.com'}]})

0 commit comments

Comments
 (0)