diff options
author | dkehn <dekehn@gmail.com> | 2022-07-07 10:58:04 +0000 |
---|---|---|
committer | Don Kehn <dekehn@gmail.com> | 2022-07-12 16:15:59 +0000 |
commit | 410c1e8d60a6b3844050dd4d3ecc46f640356bfb (patch) | |
tree | c77debfb2a24a1b006d3384623ba0f5e5d2d731a | |
parent | 2159c7a5aa4669cdb31ec8c5780c3b445f32d7cb (diff) | |
download | designate-410c1e8d60a6b3844050dd4d3ecc46f640356bfb.tar.gz |
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
-rwxr-xr-x | designate/objects/recordset.py | 2 | ||||
-rw-r--r-- | designate/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 c4de31b9..ee8e72f1 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 9b96157c..19c24011 100644 --- a/designate/tests/test_api/test_v2/test_recordsets.py +++ b/designate/tests/test_api/test_v2/test_recordsets.py @@ -55,6 +55,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( @@ -171,14 +211,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 @@ -684,14 +716,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} |