Skip to content

Commit f93584c

Browse files
feat(dyndns): continue domain search when &hostname= is given
1 parent 88844df commit f93584c

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

api/desecapi/tests/test_dyndns12update.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,16 @@ def test_ignore_minimum_ttl(self):
298298
self.assertStatus(response, status.HTTP_200_OK)
299299
self.assertEqual(domain.rrset_set.get(subname="", type="A").ttl, 60)
300300

301+
def test_empty_hostname(self):
302+
# Test that dynDNS updates work when &hostname= is given with username in basic auth
303+
self.client.set_credentials_basic_auth(
304+
self.my_domain.name.lower(), self.token.plain
305+
)
306+
response = self.assertDynDNS12Update(self.my_domain.name, hostname="")
307+
self.assertStatus(response, status.HTTP_200_OK)
308+
self.assertEqual(response.data, "good")
309+
self.assertIP(ipv4="127.0.0.1")
310+
301311
def test_identification_by_token(self):
302312
"""
303313
Test if the conflict of having multiple domains, but not specifying which to update is correctly recognized.

api/desecapi/views/dyndns.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ def _find_ip(self, param_keys, separator):
6868

6969
@cached_property
7070
def qname(self):
71-
# hostname parameter
72-
try:
73-
if self.request.query_params["hostname"] != "YES":
74-
return self.request.query_params["hostname"].lower()
75-
except KeyError:
76-
pass
77-
78-
# host_id parameter
79-
try:
80-
return self.request.query_params["host_id"].lower()
81-
except KeyError:
82-
pass
71+
# hostname / host_id
72+
for param, reserved in {
73+
"hostname": ["", "YES"],
74+
"host_id": [],
75+
}.items():
76+
try:
77+
domain_name = self.request.query_params[param]
78+
except KeyError:
79+
pass
80+
else:
81+
if domain_name not in reserved:
82+
return domain_name.lower()
8383

8484
# http basic auth username
8585
try:

0 commit comments

Comments
 (0)