diff --git a/designate/objects/domain.py b/designate/objects/domain.py index e8bc4a34e..02154c75a 100644 --- a/designate/objects/domain.py +++ b/designate/objects/domain.py @@ -59,7 +59,7 @@ class Domain(base.DictObjectMixin, base.SoftDeleteObjectMixin, 'ttl': { 'schema': { 'type': ['integer', 'null'], - 'minimum': 0, + 'minimum': 1, 'maximum': 2147483647 }, }, diff --git a/designate/objects/recordset.py b/designate/objects/recordset.py index b38afda67..340b00668 100644 --- a/designate/objects/recordset.py +++ b/designate/objects/recordset.py @@ -112,7 +112,7 @@ class RecordSet(base.DictObjectMixin, base.PersistentObjectMixin, 'schema': { 'type': ['integer', 'null'], 'description': 'Default time to live', - 'minimum': 0, + 'minimum': 1, 'maximum': 2147483647 }, }, diff --git a/designate/resources/schemas/v1/domain.json b/designate/resources/schemas/v1/domain.json index a9a6178ed..51633b2cb 100644 --- a/designate/resources/schemas/v1/domain.json +++ b/designate/resources/schemas/v1/domain.json @@ -32,7 +32,7 @@ "ttl": { "type": "integer", "description": "Time to live", - "minimum": 0, + "minimum": 1, "maximum": 2147483647 }, "serial": { diff --git a/designate/resources/schemas/v1/record.json b/designate/resources/schemas/v1/record.json index 440df45cb..fbf822019 100644 --- a/designate/resources/schemas/v1/record.json +++ b/designate/resources/schemas/v1/record.json @@ -48,7 +48,7 @@ "ttl": { "type": ["integer", "null"], "description": "Time to live", - "minimum": 0, + "minimum": 1, "maximum": 2147483647 }, "description": { diff --git a/designate/tests/test_api/test_v1/test_domains.py b/designate/tests/test_api/test_v1/test_domains.py index 087172788..c1612c71f 100644 --- a/designate/tests/test_api/test_v1/test_domains.py +++ b/designate/tests/test_api/test_v1/test_domains.py @@ -87,6 +87,12 @@ class ApiV1DomainsTest(ApiV1Test): fixture['ttl'] = -1 self.post('domains', data=fixture, status_code=400) + def test_create_domain_zero_ttl(self): + # Create a domain + fixture = self.get_domain_fixture(0) + fixture['ttl'] = 0 + self.post('domains', data=fixture, status_code=400) + def test_create_domain_invalid_ttl(self): # Create a domain fixture = self.get_domain_fixture(0) @@ -278,6 +284,14 @@ class ApiV1DomainsTest(ApiV1Test): self.put('domains/%s' % domain['id'], data=data, status_code=400) + def test_update_domain_zero_ttl(self): + # Create a domain + domain = self.create_domain() + + data = {'ttl': 0} + + self.put('domains/%s' % domain['id'], data=data, status_code=400) + @patch.object(central_service.Service, 'update_domain', side_effect=messaging.MessagingTimeout()) def test_update_domain_timeout(self, _): diff --git a/designate/tests/test_api/test_v1/test_records.py b/designate/tests/test_api/test_v1/test_records.py index d14699471..e743a49db 100644 --- a/designate/tests/test_api/test_v1/test_records.py +++ b/designate/tests/test_api/test_v1/test_records.py @@ -96,7 +96,7 @@ class ApiV1RecordsTest(ApiV1Test): # Get the record 2 to ensure recordset did not get deleted rec_2_get_response = self.get('domains/%s/records/%s' % - (self.domain['id'], record_2.json['id'])) + (self.domain['id'], record_2.json['id'])) self.assertIn('id', rec_2_get_response.json) self.assertIn('name', rec_2_get_response.json) @@ -210,6 +210,20 @@ class ApiV1RecordsTest(ApiV1Test): self.post('domains/%s/records' % self.domain['id'], data=fixture, status_code=400) + def test_create_record_zero_ttl(self): + fixture = self.get_record_fixture(self.recordset['type']) + fixture.update({ + 'name': self.recordset['name'], + 'type': self.recordset['type'], + }) + + # Set the TTL to a value zero + fixture['ttl'] = 0 + + # Create a record, Ensuring it Fails with a 400 + self.post('domains/%s/records' % self.domain['id'], data=fixture, + status_code=400) + def test_create_record_invalid_ttl(self): fixture = self.get_record_fixture(self.recordset['type']) fixture.update({ @@ -466,6 +480,15 @@ class ApiV1RecordsTest(ApiV1Test): self.put('domains/%s/records/%s' % (self.domain['id'], record['id']), data=data, status_code=400) + def test_update_record_zero_ttl(self): + # Create a record + record = self.create_record(self.domain, self.recordset) + + data = {'ttl': 0} + + self.put('domains/%s/records/%s' % (self.domain['id'], record['id']), + data=data, status_code=400) + def test_update_record_invalid_ttl(self): # Create a record record = self.create_record(self.domain, self.recordset)