From c457d0724655601e85f89f81dbe03671a2a2038e Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Sep 19 2017 18:43:23 +0000 Subject: fix up url checks and extend unit tests for this issue --- diff --git a/koji/daemon.py b/koji/daemon.py index 533ae1a..7f0eeff 100644 --- a/koji/daemon.py +++ b/koji/daemon.py @@ -262,14 +262,25 @@ class SCM(object): netloc = userhost[1] elif len(userhost) > 2: raise koji.GenericError('Invalid username@hostname specified: %s' % netloc) + if not netloc: + raise koji.GenericError('Unable to parse SCM URL: %s . Could not find the netloc element.' % self.url) + + # check for empty path before we apply normpath + if not path: + raise koji.GenericError('Unable to parse SCM URL: %s . Could not find the path element.' % self.url) path = os.path.normpath(path) - # ensure that path and query do not end in / - if path.endswith('/'): - path = path[:-1] - if query.endswith('/'): - query = query[:-1] + # path and query should not end with / + path = path.rstrip('/') + query = query.rstrip('/') + # normpath might not strip // at start of path + if path.startswith('//'): + path = '/' + path.strip('/') + # path should start with / + if not path.startswith('/'): # pragma: no cover + # any such url should have already been caught by is_scm_url + raise koji.GenericError('Invalid SCM URL. Path should begin with /: %s) ') # check for validity: params should be empty, query may be empty, everything else should be populated if params: @@ -277,10 +288,6 @@ class SCM(object): if not scheme: #pragma: no cover # should not happen because of is_scm_url check earlier raise koji.GenericError('Unable to parse SCM URL: %s . Could not find the scheme element.' % self.url) - if not netloc: - raise koji.GenericError('Unable to parse SCM URL: %s . Could not find the netloc element.' % self.url) - if not path: - raise koji.GenericError('Unable to parse SCM URL: %s . Could not find the path element.' % self.url) if not fragment: raise koji.GenericError('Unable to parse SCM URL: %s . Could not find the fragment element.' % self.url) diff --git a/tests/test_scm.py b/tests/test_scm.py index 6912056..5742026 100644 --- a/tests/test_scm.py +++ b/tests/test_scm.py @@ -28,6 +28,9 @@ class TestSCM(unittest.TestCase): "http://localhost/foo.html", "foo-1.1-1.src.rpm", "https://server/foo-1.1-1.src.rpm", + "git:foobar", + "https:foo/bar", + "https://", ] for url in good: self.assertTrue(SCM.is_scm_url(url)) @@ -81,6 +84,13 @@ class TestSCM(unittest.TestCase): "cvs://badserver/projects/42#ref", "svn://badserver/projects/42#ref", "git://maybeserver/badpath/project#1234", + "git://maybeserver//badpath/project#1234", + "git://maybeserver////badpath/project#1234", + "git://maybeserver/./badpath/project#1234", + "git://maybeserver//.//badpath/project#1234", + "git://maybeserver/goodpath/../badpath/project#1234", + "git://maybeserver/goodpath/..//badpath/project#1234", + "git://maybeserver/..//badpath/project#1234", ] for url in good: scm = SCM(url)