Checking git url format
Change-Id: I994c40ae710a23b208745be042ef367d6050f1df Closes-Bug: #1552401
This commit is contained in:
parent
6ee1345a9e
commit
bdc0fae745
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import re
|
||||
import uuid
|
||||
|
||||
from oslo_config import cfg
|
||||
@ -73,6 +74,17 @@ class LanguagePackHandler(handler.Handler):
|
||||
else:
|
||||
return False
|
||||
|
||||
def check_lp_url(self, data):
|
||||
|
||||
# try to use a correct git uri
|
||||
pt = re.compile(r'github\.com[:/](.+?)/(.+?)($|/.*$|\.git$|\.git/.*$)')
|
||||
match = pt.search(data['source_uri'])
|
||||
if not match:
|
||||
msg = ("Bad git url. Provide git url in the following format: \n"
|
||||
"Public repo: https://github.com/<USER>/<REPO>.git\n"
|
||||
"Private repo: git@github.com:<USER>/<REPO>.git\n")
|
||||
raise exc.BadRequest(reason=msg)
|
||||
|
||||
def get(self, id):
|
||||
"""Return a languagepack."""
|
||||
return objects.registry.Image.get_lp_by_name_or_uuid(
|
||||
@ -84,6 +96,9 @@ class LanguagePackHandler(handler.Handler):
|
||||
|
||||
def create(self, data, lp_metadata):
|
||||
"""Create a new languagepack."""
|
||||
|
||||
self.check_lp_url(data)
|
||||
|
||||
try:
|
||||
# Check if an LP with the same name exists.
|
||||
objects.registry.Image.get_lp_by_name_or_uuid(
|
||||
|
@ -47,7 +47,7 @@ class TestLanguagePackHandler(base.BaseTestCase):
|
||||
'LanguagePackHandler._start_build')
|
||||
def test_languagepack_create(self, mock_lp_build, mock_img):
|
||||
data = {'name': 'new app',
|
||||
'source_uri': 'git://example.com/foo'}
|
||||
'source_uri': 'git://github.com/foo/foo.git'}
|
||||
fi = fakes.FakeImage()
|
||||
mock_img.get_lp_by_name_or_uuid.side_effect = exc.ResourceNotFound()
|
||||
mock_img.return_value = fi
|
||||
@ -57,6 +57,16 @@ class TestLanguagePackHandler(base.BaseTestCase):
|
||||
fi.update.assert_called_once_with(data)
|
||||
fi.create.assert_called_once_with(self.ctx)
|
||||
|
||||
def test_lp_create_bad_git_url(self, mock_img):
|
||||
data = {'name': 'new app',
|
||||
'source_uri': 'git://123'}
|
||||
handler = language_pack_handler.LanguagePackHandler(self.ctx)
|
||||
try:
|
||||
handler.create(data, lp_metadata=None)
|
||||
self.assertTrue(False)
|
||||
except exc.BadRequest:
|
||||
self.assertTrue(True)
|
||||
|
||||
@mock.patch('solum.common.solum_swiftclient.SwiftClient.delete_object')
|
||||
@mock.patch('solum.api.handlers.userlog_handler.UserlogHandler')
|
||||
@mock.patch('solum.objects.registry.PlanList')
|
||||
|
Loading…
Reference in New Issue
Block a user