Merge #515 Add config option for allowing custom scmurls

This commit is contained in:
Jan Kaluža
2017-05-02 12:57:48 +00:00
5 changed files with 3595 additions and 1 deletions

View File

@@ -47,6 +47,8 @@ class BaseConfiguration(object):
# and be in the build state at a time. Set this to 0 for no restrictions
NUM_CONSECUTIVE_BUILDS = 5
ALLOW_CUSTOM_SCMURLS = False
RPMS_DEFAULT_REPOSITORY = 'git://pkgs.fedoraproject.org/rpms/'
RPMS_ALLOW_REPOSITORY = False
RPMS_DEFAULT_CACHE = 'http://pkgs.fedoraproject.org/repo/pkgs/'

View File

@@ -181,6 +181,10 @@ class Config(object):
'type': list,
'default': ['module'],
'desc': 'List of allowed koji tag prefixes.'},
'allow_custom_scmurls': {
'type': bool,
'default': False,
'desc': 'Allow custom scmurls.'},
'rpms_default_repository': {
'type': str,
'default': 'git://pkgs.fedoraproject.org/rpms/',

View File

@@ -195,7 +195,8 @@ class SCMHandler(BaseHandler):
raise ValidationError('Missing scmurl')
url = self.data["scmurl"]
if not any(url.startswith(prefix) for prefix in conf.scmurls):
allowed_prefix = any(url.startswith(prefix) for prefix in conf.scmurls)
if not conf.allow_custom_scmurls and not allowed_prefix:
log.error("The submitted scmurl %r is not allowed" % url)
raise Forbidden("The submitted scmurl %s is not allowed" % url)

View File

@@ -756,3 +756,25 @@ class TestViews(unittest.TestCase):
data['message'])
self.assertEquals(data['status'], 422)
self.assertEquals(data['error'], 'Unprocessable Entity')
@patch('module_build_service.auth.get_user', return_value=user)
@patch('module_build_service.scm.SCM')
@patch("module_build_service.config.Config.allow_custom_scmurls", new_callable=PropertyMock)
def test_submit_custom_scmurl(self, allow_custom_scmurls, mocked_scm, mocked_get_user):
MockedSCM(mocked_scm, 'testmodule', 'testmodule.yaml',
'620ec77321b2ea7b0d67d82992dda3e1d67055b4')
def submit(scmurl):
return self.client.post('/module-build-service/1/module-builds/', data=json.dumps(
{'branch': 'master', 'scmurl': scmurl}))
allow_custom_scmurls.return_value = False
res1 = submit('git://some.custom.url.org/modules/testmodule.git?#68931c9')
data = json.loads(res1.data)
self.assertEquals(data['status'], 403)
self.assertTrue(data['message'].startswith('The submitted scmurl'))
self.assertTrue(data['message'].endswith('is not allowed'))
allow_custom_scmurls.return_value = True
res2 = submit('git://some.custom.url.org/modules/testmodule.git?#68931c9')
self.assertEquals(res2.status_code, 201)

File diff suppressed because it is too large Load Diff