From a31e41ecaca791286ab7b93b0035b6b1dd89a5e8 Mon Sep 17 00:00:00 2001 From: Vinod Mangalpally Date: Wed, 10 Sep 2014 18:27:53 -0500 Subject: [PATCH] Getting deleted recordsets returns a 404 Getting recordsets of a deleted domain from the v2 api now returns a domain_not_found exception similar to v1 Change-Id: I3532ddd139f534b5ac77c1fdfdd7c4cc326e1f5c Closes-Bug: 1367954 --- designate/api/v2/controllers/recordsets.py | 4 ++++ .../tests/test_api/test_v2/test_recordsets.py | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/designate/api/v2/controllers/recordsets.py b/designate/api/v2/controllers/recordsets.py index 3d72dd683..ceb719e3f 100644 --- a/designate/api/v2/controllers/recordsets.py +++ b/designate/api/v2/controllers/recordsets.py @@ -53,6 +53,10 @@ class RecordSetsController(rest.RestController): request = pecan.request context = request.environ['context'] + # NOTE: We need to ensure the domain actually exists, otherwise we may + # return deleted recordsets instead of a domain not found + self.central_api.get_domain(context, zone_id) + # Extract the pagination params marker, limit, sort_key, sort_dir = self._get_paging_params(params) diff --git a/designate/tests/test_api/test_v2/test_recordsets.py b/designate/tests/test_api/test_v2/test_recordsets.py index e87cf80ac..5ad855cff 100644 --- a/designate/tests/test_api/test_v2/test_recordsets.py +++ b/designate/tests/test_api/test_v2/test_recordsets.py @@ -225,13 +225,29 @@ class ApiV2RecordSetsTest(ApiV2TestCase): def test_get_recordsets_invalid_id(self): self._assert_invalid_uuid(self.client.get, '/zones/%s/recordsets') - @patch.object(central_service.Service, 'find_recordsets', + @patch.object(central_service.Service, 'get_domain', side_effect=messaging.MessagingTimeout()) def test_get_recordsets_timeout(self, _): url = '/zones/ba751950-6193-11e3-949a-0800200c9a66/recordsets' self._assert_exception('timeout', 504, self.client.get, url) + def test_get_deleted_recordsets(self): + zone = self.create_domain(fixture=1) + self.create_recordset(zone) + url = '/zones/%s/recordsets' % zone['id'] + + response = self.client.get(url) + + # Check the headers are what we expect + self.assertEqual(200, response.status_int) + + # now delete the domain and get the recordsets + self.client.delete('/zones/%s' % zone['id'], status=204) + + # Check that we get a domain_not_found error + self._assert_exception('domain_not_found', 404, self.client.get, url) + def test_get_recordset(self): # Create a recordset recordset = self.create_recordset(self.domain)