##// END OF EJS Templates
api: validate commit_id when using commit_comment API
marcink -
r1429:4cef5a61 stable
parent child Browse files
Show More
@@ -33,9 +33,29 b' class TestCommentCommit(object):'
33 self.apikey, 'comment_commit', repoid=repo.repo_name,
33 self.apikey, 'comment_commit', repoid=repo.repo_name,
34 commit_id='tip', message='message', status_change=None)
34 commit_id='tip', message='message', status_change=None)
35 response = api_call(self.app, params)
35 response = api_call(self.app, params)
36 expected = 'failed to set comment on repository `%s`' % repo.repo_name
36 expected = 'There are no commits yet'
37 assert_error(id_, expected, given=response.body)
37 assert_error(id_, expected, given=response.body)
38
38
39 @pytest.mark.parametrize("commit_id, expected_err", [
40 ('abcabca', {'hg': 'Commit {commit} does not exist for {repo}',
41 'git': 'Commit {commit} does not exist for {repo}',
42 'svn': 'Commit id {commit} not understood.'}),
43 ('idontexist', {'hg': 'Commit {commit} does not exist for {repo}',
44 'git': 'Commit {commit} does not exist for {repo}',
45 'svn': 'Commit id {commit} not understood.'}),
46 ])
47 def test_api_comment_commit_wrong_hash(self, backend, commit_id, expected_err):
48 repo_name = backend.repo.repo_name
49 id_, params = build_data(
50 self.apikey, 'comment_commit', repoid=repo_name,
51 commit_id=commit_id, message='message', status_change=None)
52 response = api_call(self.app, params)
53
54 expected_err = expected_err[backend.alias]
55 expected_err = expected_err.format(
56 repo=backend.repo.scm_instance(), commit=commit_id)
57 assert_error(id_, expected_err, given=response.body)
58
39 @pytest.mark.parametrize("status_change, message, commit_id", [
59 @pytest.mark.parametrize("status_change, message, commit_id", [
40 (None, 'Hallo', 'tip'),
60 (None, 'Hallo', 'tip'),
41 (ChangesetStatus.STATUS_APPROVED, 'Approved', 'tip'),
61 (ChangesetStatus.STATUS_APPROVED, 'Approved', 'tip'),
@@ -44,6 +64,9 b' class TestCommentCommit(object):'
44 def test_api_comment_commit(
64 def test_api_comment_commit(
45 self, backend, status_change, message, commit_id,
65 self, backend, status_change, message, commit_id,
46 no_notifications):
66 no_notifications):
67
68 commit_id = backend.repo.scm_instance().get_changeset(commit_id).raw_id
69
47 id_, params = build_data(
70 id_, params = build_data(
48 self.apikey, 'comment_commit', repoid=backend.repo_name,
71 self.apikey, 'comment_commit', repoid=backend.repo_name,
49 commit_id=commit_id, message=message, status=status_change)
72 commit_id=commit_id, message=message, status=status_change)
@@ -30,9 +30,9 b' from rhodecode.api.utils import ('
30 get_perm_or_error, parse_args, get_origin, build_commit_data,
30 get_perm_or_error, parse_args, get_origin, build_commit_data,
31 validate_set_owner_permissions)
31 validate_set_owner_permissions)
32 from rhodecode.lib.auth import HasPermissionAnyApi, HasUserGroupPermissionAnyApi
32 from rhodecode.lib.auth import HasPermissionAnyApi, HasUserGroupPermissionAnyApi
33 from rhodecode.lib.exceptions import StatusChangeOnClosedPullRequestError
34 from rhodecode.lib.utils2 import str2bool, time_to_datetime
33 from rhodecode.lib.utils2 import str2bool, time_to_datetime
35 from rhodecode.lib.ext_json import json
34 from rhodecode.lib.ext_json import json
35 from rhodecode.lib.exceptions import StatusChangeOnClosedPullRequestError
36 from rhodecode.model.changeset_status import ChangesetStatusModel
36 from rhodecode.model.changeset_status import ChangesetStatusModel
37 from rhodecode.model.comment import CommentsModel
37 from rhodecode.model.comment import CommentsModel
38 from rhodecode.model.db import (
38 from rhodecode.model.db import (
@@ -1426,6 +1426,12 b' def comment_commit('
1426 _perms = ('repository.read', 'repository.write', 'repository.admin')
1426 _perms = ('repository.read', 'repository.write', 'repository.admin')
1427 validate_repo_permissions(apiuser, repoid, repo, _perms)
1427 validate_repo_permissions(apiuser, repoid, repo, _perms)
1428
1428
1429 try:
1430 commit_id = repo.scm_instance().get_commit(commit_id=commit_id).raw_id
1431 except Exception as e:
1432 log.exception('Failed to fetch commit')
1433 raise JSONRPCError(e.message)
1434
1429 if isinstance(userid, Optional):
1435 if isinstance(userid, Optional):
1430 userid = apiuser.user_id
1436 userid = apiuser.user_id
1431
1437
General Comments 0
You need to be logged in to leave comments. Login now