浏览代码

fix(api): catch overly long names in record validation

Peter Thomassen 1 年之前
父节点
当前提交
dddf707c2c
共有 2 个文件被更改,包括 3 次插入1 次删除
  1. 2 0
      api/desecapi/models/records.py
  2. 1 1
      api/desecapi/tests/test_rrsets.py

+ 2 - 0
api/desecapi/models/records.py

@@ -303,6 +303,8 @@ class RR(ExportModelOperationsMixin("RR"), models.Model):
                 raise ValueError(
                     f'Record content for type {type_} malformed: {",".join(e.args)}'
                 )
+        except dns.name.NameTooLong:
+            raise ValueError("Hostname must be no longer than 255 characters")
         except dns.name.NeedAbsoluteNameOrOrigin:
             raise ValueError(
                 'Hostname must be fully qualified (i.e., end in a dot: "example.com.")'

+ 1 - 1
api/desecapi/tests/test_rrsets.py

@@ -987,7 +987,7 @@ class AuthenticatedRRSetTestCase(AuthenticatedRRSetBaseTestCase):
                 "6454 8 1 aabbccddeeff",
                 "0 0 0 0",
             ],
-            "CNAME": ["example.com", "10 example.com.", "@."],
+            "CNAME": ["example.com", "10 example.com.", "@.", "abcd123." * 32],
             "CSYNC": ["0 -1 A", "444 65536 A", "0 3 AAA"],
             "DHCID": ["x", "xx", "xxx"],
             "DLV": [