Skip to content

Commit

Permalink
fix(api): require subname for PUT on RRsetDetail (as documented)
Browse files Browse the repository at this point in the history
Previously, the serializer would fall back to the default empty subname.
On non-apex records, this resulted in an attempt to change the subname
value, which previously was rejected (with a different error). For apex
names, the operation would continue (because the default subname would
mean no change).
  • Loading branch information
peterthomassen committed Jan 27, 2025
1 parent ffd46bd commit 362a348
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion api/desecapi/serializers/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def __init__(self, default):

def __call__(self, serializer_field):
is_many = getattr(serializer_field.root, "many", False)
if is_many:
partial = getattr(serializer_field.root, "partial", False)
if is_many or (serializer_field.root.instance and not partial):
serializer_field.fail("required")
if callable(self.default):
if getattr(self.default, "requires_context", False):
Expand Down
16 changes: 16 additions & 0 deletions api/desecapi/tests/test_rrsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,22 @@ def test_update_my_rr_sets(self):
)
self.assertStatus(response, status.HTTP_400_BAD_REQUEST)

def test_update_my_rr_sets_missing_subname(self):
for subname in ["", "test"]:
with self.assertNoRequestsBut():
data = {
"records": ["127.0.0.1"],
"ttl": 3630,
"type": "A",
}
self.assertBadRequest(
self.client.put_rr_set(
self.my_rr_set_domain.name, subname, "A", data
),
"This field is required.",
("subname", 0),
)

def test_update_my_rr_sets_wrong_subname(self):
for s1, s2 in [("", "test"), ("test", "")]:
with self.assertNoRequestsBut():
Expand Down

0 comments on commit 362a348

Please sign in to comment.