##// END OF EJS Templates
validators: fix url_validator tests and make it flag controllable.
marcink -
r3072:fe39713b default
parent child Browse files
Show More
@@ -19,7 +19,7 b''
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import os
21 import os
22
22 import mock
23 import pytest
23 import pytest
24
24
25 from rhodecode.tests import TESTS_TMP_PATH
25 from rhodecode.tests import TESTS_TMP_PATH
@@ -29,6 +29,7 b' from rhodecode.api.tests.utils import ('
29
29
30 @pytest.mark.usefixtures("testuser_api", "app")
30 @pytest.mark.usefixtures("testuser_api", "app")
31 class TestPull(object):
31 class TestPull(object):
32
32 @pytest.mark.backends("git", "hg")
33 @pytest.mark.backends("git", "hg")
33 def test_api_pull(self, backend):
34 def test_api_pull(self, backend):
34 r = backend.create_repo()
35 r = backend.create_repo()
@@ -37,12 +38,13 b' class TestPull(object):'
37 r.clone_uri = clone_uri
38 r.clone_uri = clone_uri
38
39
39 id_, params = build_data(self.apikey, 'pull', repoid=repo_name,)
40 id_, params = build_data(self.apikey, 'pull', repoid=repo_name,)
40 response = api_call(self.app, params)
41 with mock.patch('rhodecode.model.scm.url_validator'):
41 msg = 'Pulled from url `%s` on repo `%s`' % (
42 response = api_call(self.app, params)
42 clone_uri, repo_name)
43 msg = 'Pulled from url `%s` on repo `%s`' % (
43 expected = {'msg': msg,
44 clone_uri, repo_name)
44 'repository': repo_name}
45 expected = {'msg': msg,
45 assert_ok(id_, expected, given=response.body)
46 'repository': repo_name}
47 assert_ok(id_, expected, given=response.body)
46
48
47 def test_api_pull_error(self, backend):
49 def test_api_pull_error(self, backend):
48 id_, params = build_data(
50 id_, params = build_data(
@@ -56,9 +56,15 b' class TestApiUpdateRepo(object):'
56 ({'clone_uri': ''},
56 ({'clone_uri': ''},
57 {'clone_uri': ''}),
57 {'clone_uri': ''}),
58
58
59 ({'clone_uri': 'http://example.com/repo_pull'},
60 {'clone_uri': 'http://example.com/repo_pull'}),
61
59 ({'push_uri': ''},
62 ({'push_uri': ''},
60 {'push_uri': ''}),
63 {'push_uri': ''}),
61
64
65 ({'push_uri': 'http://example.com/repo_push'},
66 {'push_uri': 'http://example.com/repo_push'}),
67
62 ({'landing_rev': 'rev:tip'},
68 ({'landing_rev': 'rev:tip'},
63 {'landing_rev': ['rev', 'tip']}),
69 {'landing_rev': ['rev', 'tip']}),
64
70
@@ -377,7 +377,7 b' class ScmModel(BaseModel):'
377 self.sa.add(repo)
377 self.sa.add(repo)
378 return repo
378 return repo
379
379
380 def pull_changes(self, repo, username, remote_uri=None):
380 def pull_changes(self, repo, username, remote_uri=None, validate_uri=True):
381 dbrepo = self._get_repo(repo)
381 dbrepo = self._get_repo(repo)
382 remote_uri = remote_uri or dbrepo.clone_uri
382 remote_uri = remote_uri or dbrepo.clone_uri
383 if not remote_uri:
383 if not remote_uri:
@@ -390,8 +390,9 b' class ScmModel(BaseModel):'
390 # NOTE(marcink): add extra validation so we skip invalid urls
390 # NOTE(marcink): add extra validation so we skip invalid urls
391 # this is due this tasks can be executed via scheduler without
391 # this is due this tasks can be executed via scheduler without
392 # proper validation of remote_uri
392 # proper validation of remote_uri
393 config = make_db_config(clear_session=False)
393 if validate_uri:
394 url_validator(remote_uri, dbrepo.repo_type, config)
394 config = make_db_config(clear_session=False)
395 url_validator(remote_uri, dbrepo.repo_type, config)
395 except InvalidCloneUrl:
396 except InvalidCloneUrl:
396 raise
397 raise
397
398
@@ -405,7 +406,7 b' class ScmModel(BaseModel):'
405 log.error(traceback.format_exc())
406 log.error(traceback.format_exc())
406 raise
407 raise
407
408
408 def push_changes(self, repo, username, remote_uri=None):
409 def push_changes(self, repo, username, remote_uri=None, validate_uri=True):
409 dbrepo = self._get_repo(repo)
410 dbrepo = self._get_repo(repo)
410 remote_uri = remote_uri or dbrepo.push_uri
411 remote_uri = remote_uri or dbrepo.push_uri
411 if not remote_uri:
412 if not remote_uri:
@@ -418,8 +419,9 b' class ScmModel(BaseModel):'
418 # NOTE(marcink): add extra validation so we skip invalid urls
419 # NOTE(marcink): add extra validation so we skip invalid urls
419 # this is due this tasks can be executed via scheduler without
420 # this is due this tasks can be executed via scheduler without
420 # proper validation of remote_uri
421 # proper validation of remote_uri
421 config = make_db_config(clear_session=False)
422 if validate_uri:
422 url_validator(remote_uri, dbrepo.repo_type, config)
423 config = make_db_config(clear_session=False)
424 url_validator(remote_uri, dbrepo.repo_type, config)
423 except InvalidCloneUrl:
425 except InvalidCloneUrl:
424 raise
426 raise
425
427
General Comments 0
You need to be logged in to leave comments. Login now