Browse Source

feat(api): rework SOA creation, set better values, closes #337

Peter Thomassen 5 years ago
parent
commit
3d600c7896
2 changed files with 23 additions and 4 deletions
  1. 16 1
      api/desecapi/pdns_change_tracker.py
  2. 7 3
      api/desecapi/tests/base.py

+ 16 - 1
api/desecapi/pdns_change_tracker.py

@@ -93,7 +93,22 @@ class PDNSChangeTracker:
                     'kind': 'MASTER',
                     'kind': 'MASTER',
                     'dnssec': True,
                     'dnssec': True,
                     'nsec3param': '1 0 127 %s' % salt,
                     'nsec3param': '1 0 127 %s' % salt,
-                    'nameservers': settings.DEFAULT_NS
+                    'nameservers': settings.DEFAULT_NS,
+                    'rrsets': [{
+                        'name': self.domain_name_normalized,
+                        'type': 'SOA',
+                        # SOA RRset TTL: 300 (used as TTL for negative replies including NSEC3 records)
+                        'ttl': 300,
+                        'records': [{
+                            # SOA refresh: 2 weeks (our replication doesn't rely on this, and a high value keeps our
+                            #   frontends from asking all the time)
+                            # SOA retry = refresh
+                            # SOA expire: 4 weeks (all signatures will have expired anyways)
+                            # SOA minimum: 3600 (for CDS, CDNSKEY, DNSKEY, NSEC3PARAM)
+                            'content': 'set.an.example. get.desec.io. 1 1209600 1209600 2419200 3600',
+                            'disabled': False
+                        }],
+                    }],
                 }
                 }
             )
             )
 
 

+ 7 - 3
api/desecapi/tests/base.py

@@ -170,13 +170,15 @@ class AssertRequestsContextManager:
     def _find_matching_request(pattern, requests):
     def _find_matching_request(pattern, requests):
         for request in requests:
         for request in requests:
             if pattern['method'] == request[0] and pattern['uri'].match(request[1]):
             if pattern['method'] == request[0] and pattern['uri'].match(request[1]):
+                if pattern.get('payload') and pattern['payload'] not in request[2]:
+                    continue
                 return request
                 return request
         return None
         return None
 
 
     def __exit__(self, exc_type, exc_val, exc_tb):
     def __exit__(self, exc_type, exc_val, exc_tb):
         # organize seen requests in a primitive data structure
         # organize seen requests in a primitive data structure
         seen_requests = [
         seen_requests = [
-            (r.command, 'http://%s%s' % (r.headers['Host'], r.path)) for r in httpretty.latest_requests
+            (r.command, 'http://%s%s' % (r.headers['Host'], r.path), r.parsed_body) for r in httpretty.latest_requests
         ]
         ]
         httpretty.reset()
         httpretty.reset()
         hr_core.POTENTIAL_HTTP_PORTS.add(8081)  # FIXME should depend on self.expected_requests
         hr_core.POTENTIAL_HTTP_PORTS.add(8081)  # FIXME should depend on self.expected_requests
@@ -289,13 +291,14 @@ class MockPDNSTestCase(APITestCase):
             return [x.rstrip('.') + '.' for x in arg]
             return [x.rstrip('.') + '.' for x in arg]
 
 
     @classmethod
     @classmethod
-    def request_pdns_zone_create(cls, ns):
+    def request_pdns_zone_create(cls, ns, **kwargs):
         return {
         return {
             'method': 'POST',
             'method': 'POST',
             'uri': cls.get_full_pdns_url(cls.PDNS_ZONES, ns=ns),
             'uri': cls.get_full_pdns_url(cls.PDNS_ZONES, ns=ns),
             'status': 201,
             'status': 201,
             'body': None,
             'body': None,
             'match_querystring': True,
             'match_querystring': True,
+            **kwargs
         }
         }
 
 
     def request_pdns_zone_create_assert_name(self, ns, name):
     def request_pdns_zone_create_assert_name(self, ns, name):
@@ -766,8 +769,9 @@ class DesecTestCase(MockPDNSTestCase):
 
 
     @classmethod
     @classmethod
     def requests_desec_domain_creation(cls, name=None):
     def requests_desec_domain_creation(cls, name=None):
+        soa_content = 'set.an.example. get.desec.io. 1 1209600 1209600 2419200 3600'
         return [
         return [
-            cls.request_pdns_zone_create(ns='LORD'),
+            cls.request_pdns_zone_create(ns='LORD', payload=soa_content),
             cls.request_pdns_zone_create(ns='MASTER'),
             cls.request_pdns_zone_create(ns='MASTER'),
             cls.request_pdns_update_catalog(),
             cls.request_pdns_update_catalog(),
             cls.request_pdns_zone_axfr(name=name),
             cls.request_pdns_zone_axfr(name=name),