diff --git a/murano/api/v1/templates.py b/murano/api/v1/templates.py index 49df87f0..5e718811 100644 --- a/murano/api/v1/templates.py +++ b/murano/api/v1/templates.py @@ -49,7 +49,7 @@ class Controller(object): if not is_public: filters['is_public'] = False - filters = {'tenant_id': tenant_id} + filters['tenant_id'] = tenant_id elif is_public: filters['is_public'] = True @@ -57,7 +57,7 @@ class Controller(object): get_env_templates_by(filters) else: - filters = (EnvironmentTemplate.is_public is True, + filters = (EnvironmentTemplate.is_public, EnvironmentTemplate.tenant_id == tenant_id) list_templates = env_temps.EnvTemplateServices.\ get_env_templates_or_by(filters) diff --git a/murano/tests/unit/api/v1/test_env_templates.py b/murano/tests/unit/api/v1/test_env_templates.py index 9e5c187e..7a1615f3 100644 --- a/murano/tests/unit/api/v1/test_env_templates.py +++ b/murano/tests/unit/api/v1/test_env_templates.py @@ -173,8 +173,8 @@ class TestEnvTemplateApi(tb.ControllerTest, tb.MuranoApiTestCase): self.assertFalse(0, len(json.loads(result.body))) def test_list_private_env_templates(self): - """Create an template, test list public with no - public templates. + """Create a public template and a private template, + test list private templates. """ self._set_policy_rules( {'create_env_template': '@', @@ -187,6 +187,12 @@ class TestEnvTemplateApi(tb.ControllerTest, tb.MuranoApiTestCase): result = req.get_response(self.api) self.assertFalse(json.loads(result.body)['is_public']) + self.expect_policy_check('create_env_template') + body = {'name': 'mytemp1', 'is_public': True} + req = self._post('/templates', json.dumps(body)) + result = req.get_response(self.api) + self.assertTrue(json.loads(result.body)['is_public']) + self.expect_policy_check('list_env_templates') req = self._get('/templates', {'is_public': False}) result = req.get_response(self.api) @@ -219,6 +225,34 @@ class TestEnvTemplateApi(tb.ControllerTest, tb.MuranoApiTestCase): self.assertEqual(2, len(json.loads(result.body)['templates'])) + def test_list_env_templates_with_different_tenant(self): + """Create two template in two different tenants, + test list public template from another tenant. + """ + self._set_policy_rules( + {'create_env_template': '@', + 'list_env_templates': '@'} + ) + + self.expect_policy_check('create_env_template') + body = {'name': 'mytemp', 'is_public': False} + req = self._post('/templates', json.dumps(body), tenant='first_tenant') + result = req.get_response(self.api) + self.assertFalse(json.loads(result.body)['is_public']) + + self.expect_policy_check('create_env_template') + body = {'name': 'mytemp1', 'is_public': True} + req = self._post('/templates', json.dumps(body), + tenant='second_tenant') + result = req.get_response(self.api) + self.assertTrue(json.loads(result.body)['is_public']) + + self.expect_policy_check('list_env_templates') + req = self._get('/templates', tenant='first_tenant') + result = req.get_response(self.api) + + self.assertEqual(2, len(json.loads(result.body)['templates'])) + def test_illegal_template_name_create(self): """Check that an illegal temp name results in an HTTPClientError.""" self._set_policy_rules( diff --git a/murano_tempest_tests/tests/api/application_catalog/test_env_templates.py b/murano_tempest_tests/tests/api/application_catalog/test_env_templates.py index 4af0c0fb..55d8a0a5 100644 --- a/murano_tempest_tests/tests/api/application_catalog/test_env_templates.py +++ b/murano_tempest_tests/tests/api/application_catalog/test_env_templates.py @@ -14,7 +14,6 @@ # under the License. from tempest.test import attr -from tempest_lib import decorators from murano_tempest_tests.tests.api.application_catalog import base from murano_tempest_tests import utils @@ -126,7 +125,6 @@ class TestEnvironmentTemplates(base.BaseApplicationCatalogTest): template = self.alt_client.get_env_template(cloned_template['id']) self.assertEqual(name, template['name']) - @decorators.skip_because(bug="1540709") @attr(type='smoke') def test_get_public_private_both_env_templates(self): name = utils.generate_name('get_public_private_both')