Browse Source

fix(api): fix 500 error on dyn update when domain.minimum_ttl > 60

Peter Thomassen 5 years ago
parent
commit
9c03cb5db2
3 changed files with 13 additions and 1 deletions
  1. 7 0
      api/desecapi/tests/test_dyndns12update.py
  2. 2 0
      api/desecapi/views.py
  3. 4 1
      docs/dyndns/update-api.rst

+ 7 - 0
api/desecapi/tests/test_dyndns12update.py

@@ -188,6 +188,13 @@ class SingleDomainDynDNS12UpdateTest(DynDNS12UpdateTest):
 class MultipleDomainDynDNS12UpdateTest(DynDNS12UpdateTest):
     NUM_OWNED_DOMAINS = 4
 
+    def test_honor_minimum_ttl(self):
+        self.my_domain.minimum_ttl = 61
+        self.my_domain.save()
+        response = self.assertDynDNS12NoUpdate(self.my_domain.name)
+        self.assertStatus(response, status.HTTP_403_FORBIDDEN)
+        self.assertEqual(response.data['detail'], 'Domain not eligible for dynamic updates, please contact support.')
+
     def test_identification_by_token(self):
         """
         Test if the conflict of having multiple domains, but not specifying which to update is correctly recognized.

+ 2 - 0
api/desecapi/views.py

@@ -332,6 +332,8 @@ class DynDNS12Update(APIView):
         try:
             serializer.is_valid(raise_exception=True)
         except ValidationError as e:
+            if any('ttl' in error for error in e.detail):
+                raise PermissionDenied({'detail': 'Domain not eligible for dynamic updates, please contact support.'})
             raise e
 
         with PDNSChangeTracker():

+ 4 - 1
docs/dyndns/update-api.rst

@@ -57,7 +57,10 @@ determine the hostname, we try the following steps until there is a match:
   associated with your user account (if not ambiguous).
 
 If we cannot determine a hostname to update, the API will return a ``404 Not
-Found`` status code.
+Found`` status code. If the selected hostname is not eligible for dynamic
+updates, we will return ``403 Forbidden``. This usually happens if you try
+updating a hostname that is not under the ``dedyn.io`` domain. If you are
+affected by this and would like to use another domain, please contact support.
 
 .. _determine-ip-addresses: