From b570948484032530320a73182f9a0d1425363be3 Mon Sep 17 00:00:00 2001 From: mprahl Date: Mar 12 2019 18:58:28 +0000 Subject: Don't allow building modules with the same name as a base module (e.g. platform) A user managed to build a module called "platform", which stopped dependency resolution from working. This should stop that from happening again. --- diff --git a/module_build_service/utils/submit.py b/module_build_service/utils/submit.py index 5eb4308..b49ffa8 100644 --- a/module_build_service/utils/submit.py +++ b/module_build_service/utils/submit.py @@ -568,6 +568,10 @@ def submit_module_build(username, url, mmd, optional_params=None): """ import koji # Placed here to avoid py2/py3 conflicts... + if mmd.get_name() in conf.base_module_names: + raise ValidationError( + 'You cannot build a module named "{}" since it is a base module'.format(mmd.get_name())) + raise_if_stream_ambigous = False default_streams = {} if optional_params: diff --git a/tests/test_views/test_views.py b/tests/test_views/test_views.py index 928a29b..535c4bf 100644 --- a/tests/test_views/test_views.py +++ b/tests/test_views/test_views.py @@ -1309,6 +1309,26 @@ class TestViews: } assert rv.status_code == 400 + @patch('module_build_service.auth.get_user', return_value=user) + @patch('module_build_service.scm.SCM') + def test_submit_build_with_base_module_name(self, mocked_scm, mocked_get_user): + FakeSCM(mocked_scm, 'platform', 'testmodule.yaml', + '620ec77321b2ea7b0d67d82992dda3e1d67055b4') + + data = { + 'branch': 'master', + 'scmurl': 'https://src.stg.fedoraproject.org/modules/' + 'platform.git?#68931c90de214d9d13feefbd35246a81b6cb8d49', + } + rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps(data)) + result = json.loads(rv.data) + assert result == { + 'error': 'Bad Request', + 'status': 400, + 'message': 'You cannot build a module named "platform" since it is a base module' + } + assert rv.status_code == 400 + @pytest.mark.parametrize('dep_type', ('buildrequire', 'require')) @patch('module_build_service.auth.get_user', return_value=user) @patch('module_build_service.scm.SCM')