mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-05 03:38:12 +08:00
This commit is contained in:
@@ -36,6 +36,7 @@ import rida.auth
|
||||
import rida.scm
|
||||
import shutil
|
||||
import tempfile
|
||||
import re
|
||||
from rida import app, conf, db, log
|
||||
from rida import models
|
||||
from rida.utils import pagination_metadata, filter_module_builds
|
||||
@@ -92,8 +93,15 @@ class ModuleBuildAPI(MethodView):
|
||||
|
||||
url = r["scmurl"]
|
||||
if not any(url.startswith(prefix) for prefix in conf.scmurls):
|
||||
log.error('The submitted scmurl is not allowed')
|
||||
raise Unauthorized("The submitted scmurl is not allowed")
|
||||
log.error("The submitted scmurl %r is not allowed" % url)
|
||||
raise Unauthorized("The submitted scmurl %s is not allowed" % url)
|
||||
|
||||
scmurl_re = re.compile(
|
||||
r"(?P<giturl>(?:(?P<scheme>git)://(?P<host>[^/]+))?"
|
||||
r"(?P<repopath>/[^\?]+))\?(?P<modpath>[^#]*)#(?P<revision>.+)")
|
||||
if not scmurl_re.match(url):
|
||||
log.error("The submitted scmurl %r is not valid" % url)
|
||||
raise Unauthorized("The submitted scmurl %s is not valid" % url)
|
||||
|
||||
yaml = ""
|
||||
td = None
|
||||
|
||||
@@ -212,8 +212,23 @@ class TestViews(unittest.TestCase):
|
||||
rv = self.client.post('/rida/1/module-builds/', data=json.dumps(
|
||||
{'scmurl': 'git://badurl.com'}))
|
||||
data = json.loads(rv.data)
|
||||
self.assertEquals(
|
||||
data['message'], 'The submitted scmurl is not allowed')
|
||||
self.assertEquals(data['message'], 'The submitted scmurl '
|
||||
'git://badurl.com is not allowed')
|
||||
self.assertEquals(data['status'], 401)
|
||||
self.assertEquals(data['error'], 'Unauthorized')
|
||||
|
||||
@patch('rida.auth.get_username', return_value='Homer J. Simpson')
|
||||
@patch('rida.auth.assert_is_packager')
|
||||
def test_submit_build_scm_url_without_hash(self,
|
||||
mocked_assert_is_packager,
|
||||
mocked_get_username):
|
||||
rv = self.client.post('/rida/1/module-builds/', data=json.dumps(
|
||||
{'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/'
|
||||
'testmodule.git'}))
|
||||
data = json.loads(rv.data)
|
||||
self.assertEquals(data['message'], 'The submitted scmurl '
|
||||
'git://pkgs.stg.fedoraproject.org/modules/testmodule.git '
|
||||
'is not valid')
|
||||
self.assertEquals(data['status'], 401)
|
||||
self.assertEquals(data['error'], 'Unauthorized')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user