From 2d42de9e8a401ad360da75ce6c7a816bdcebe4b0 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Fri, 26 Jul 2013 16:42:11 +0200 Subject: [PATCH] message_id is not allowed to be submitted via api The message_id of sample is not a modifiable value. So, forbidden it in API. Change-Id: Ieeb5330d36732fd9ea829b879226c5e5bb8fd083 --- ceilometer/api/controllers/v2.py | 4 ++++ tests/api/v2/test_post_samples_scenarios.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ceilometer/api/controllers/v2.py b/ceilometer/api/controllers/v2.py index e32635882..f2044b064 100644 --- a/ceilometer/api/controllers/v2.py +++ b/ceilometer/api/controllers/v2.py @@ -507,6 +507,10 @@ class MeterController(rest.RestController): raise wsme.exc.InvalidInput('counter_name', s.counter_name, 'should be %s' % self._id) + if s.message_id: + raise wsme.exc.InvalidInput('message_id', s.message_id, + 'The message_id must not be set') + s.user_id = (s.user_id or def_user_id) s.project_id = (s.project_id or def_project_id) s.source = '%s:%s' % (s.project_id, (s.source or def_source)) diff --git a/tests/api/v2/test_post_samples_scenarios.py b/tests/api/v2/test_post_samples_scenarios.py index 468afec03..164929839 100644 --- a/tests/api/v2/test_post_samples_scenarios.py +++ b/tests/api/v2/test_post_samples_scenarios.py @@ -72,6 +72,26 @@ class TestPostSamples(FunctionalTest, self.assertEqual(s1, data.json) self.assertEqual(s1[0], self.published[0][1]['args']['data'][0]) + def test_messsage_id_provided(self): + """Do not accept sample with message_id.""" + s1 = [{'counter_name': 'my_counter_name', + 'counter_type': 'gauge', + 'counter_unit': 'instance', + 'counter_volume': 1, + 'message_id': 'evil', + 'source': 'closedstack', + 'resource_id': 'bd9431c1-8d69-4ad3-803a-8d4a6b89fd36', + 'project_id': '35b17138-b364-4e6a-a131-8f3099c5be68', + 'user_id': 'efd87807-12d2-4b38-9c70-5f5c2ac427ff', + 'resource_metadata': {'name1': 'value1', + 'name2': 'value2'}}] + + data = self.post_json('/meters/my_counter_name/', s1, + expect_errors=True) + + self.assertEqual(data.status_int, 400) + self.assertEqual(len(self.published), 0) + def test_wrong_project_id(self): """Do not accept cross posting samples to different projects.""" s1 = [{'counter_name': 'my_counter_name',