From 2dc40a15894d2c2010b7176ff6f1dff0c8621503 Mon Sep 17 00:00:00 2001 From: dkehn Date: Thu, 7 Jul 2022 10:58:04 +0000 Subject: Minmum TTL value is zero According to IETF https://tools.ietf.org/html/rfc2181#section-8 the definition of the ttl value is unsigned and can have a minimum value of 0. This path changes the minimum value of 1 to allow for 0 in recordset creats and updates. Unit test have also been modified accordingly. Closes-Bug: #1926429 Change-Id: I9b08e25a007bea598442da377dc227538f6e35f7 --- designate/objects/recordset.py | 2 +- .../tests/test_api/test_v2/test_recordsets.py | 56 +++++++++++++++------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/designate/objects/recordset.py b/designate/objects/recordset.py index 1fe0c687..e2f1ffbc 100755 --- a/designate/objects/recordset.py +++ b/designate/objects/recordset.py @@ -89,7 +89,7 @@ class RecordSet(base.DesignateObject, base.DictObjectMixin, 'name': fields.HostField(maxLength=255, nullable=True), 'type': fields.StringFields(nullable=True, read_only=True), 'ttl': fields.IntegerFields(nullable=True, - minimum=1, maximum=2147483647), + minimum=0, maximum=2147483647), 'description': fields.StringFields(nullable=True, maxLength=160), 'records': fields.PolymorphicObjectField('RecordList', nullable=True), } diff --git a/designate/tests/test_api/test_v2/test_recordsets.py b/designate/tests/test_api/test_v2/test_recordsets.py index d69bc044..a2fdd7c3 100644 --- a/designate/tests/test_api/test_v2/test_recordsets.py +++ b/designate/tests/test_api/test_v2/test_recordsets.py @@ -56,6 +56,46 @@ class ApiV2RecordSetsTest(ApiV2TestCase): self.assertEqual('NONE', response.json['action']) self.assertEqual('ACTIVE', response.json['status']) + def test_create_recordset_with_zero_ttl(self): + fixture = self.get_recordset_fixture(self.zone['name'], fixture=0) + fixture['ttl'] = 0 + response = self.client.post_json( + '/zones/%s/recordsets' % self.zone['id'], fixture) + + # Check the headers are what we expect + self.assertEqual(201, response.status_int) + self.assertEqual('application/json', response.content_type) + + def test_update_recordset_zero_ttl(self): + # Create a recordset + recordset = self.create_recordset(self.zone, records=[]) + + # Prepare an update body + body = {'ttl': 0} + + url = '/zones/%s/recordsets/%s' % (recordset['zone_id'], + recordset['id']) + response = self.client.put_json(url, body, status=200) + + # Check the headers are what we expect + self.assertEqual(200, response.status_int) + self.assertEqual('application/json', response.content_type) + + # The action and status are NONE and ACTIVE as there are no records + self.assertEqual('NONE', response.json['action']) + self.assertEqual('ACTIVE', response.json['status']) + self.assertEqual(0, response.json['ttl']) + + # Check the zone's status is as expected + response = self.client.get('/zones/%s/recordsets/%s' % + (recordset['zone_id'], recordset['id']), + headers=[('Accept', 'application/json')]) + # Check the headers are what we expect + self.assertEqual(200, response.status_int) + self.assertEqual('application/json', response.content_type) + + self.assertEqual(0, response.json['ttl']) + def test_create_recordset_with_records(self): # Prepare a RecordSet fixture fixture = self.get_recordset_fixture( @@ -172,14 +212,6 @@ class ApiV2RecordSetsTest(ApiV2TestCase): self._assert_exception( 'invalid_object', 400, self.client.post_json, url, body) - def test_create_recordset_with_zero_ttl(self): - fixture = self.get_recordset_fixture(self.zone['name'], fixture=0) - fixture['ttl'] = 0 - body = fixture - url = '/zones/%s/recordsets' % self.zone['id'] - self._assert_exception( - 'invalid_object', 400, self.client.post_json, url, body) - def test_create_recordset_with_ttl_greater_than_max(self): fixture = self.get_recordset_fixture(self.zone['name'], fixture=0) fixture['ttl'] = 2147483648 @@ -708,14 +740,6 @@ class ApiV2RecordSetsTest(ApiV2TestCase): self._assert_exception('invalid_object', 400, self.client.put_json, url, body) - def test_update_recordset_zero_ttl(self): - recordset = self.create_recordset(self.zone) - body = {'ttl': 0} - url = '/zones/%s/recordsets/%s' % (recordset['zone_id'], - recordset['id']) - self._assert_exception('invalid_object', 400, - self.client.put_json, url, body) - def test_update_recordset_negative_ttl(self): recordset = self.create_recordset(self.zone) body = {'ttl': -1} -- cgit v1.2.1