PR#2081: new policy for dist-repo
Merges #2081 https://pagure.io/koji/pull-request/2081 Fixes: #1660 https://pagure.io/koji/issue/1660 Add dist-repo to hub policy
This commit is contained in:
commit
164e4bfb6e
2 changed files with 8 additions and 4 deletions
|
|
@ -11829,7 +11829,8 @@ class RootExports(object):
|
|||
|
||||
def distRepo(self, tag, keys, **task_opts):
|
||||
"""Create a dist-repo task. returns task id"""
|
||||
context.session.assertPerm('dist-repo')
|
||||
if not context.session.hasPerm('dist-repo') and not context.session.hasPerm('admin'):
|
||||
assert_policy('dist_repo', {'tag': tag})
|
||||
repo_id, event_id = dist_repo_init(tag, keys, task_opts)
|
||||
task_opts['event'] = event_id
|
||||
# cancel potentially running distRepos
|
||||
|
|
|
|||
|
|
@ -85,14 +85,16 @@ class TestDistRepoInit(unittest.TestCase):
|
|||
|
||||
class TestDistRepo(unittest.TestCase):
|
||||
|
||||
@mock.patch('kojihub.assert_policy')
|
||||
@mock.patch('kojihub.dist_repo_init')
|
||||
@mock.patch('kojihub.make_task')
|
||||
def test_DistRepo(self, make_task, dist_repo_init):
|
||||
def test_DistRepo(self, make_task, dist_repo_init, assert_policy):
|
||||
session = kojihub.context.session = mock.MagicMock()
|
||||
session.user_id = 123
|
||||
# It seems MagicMock will not automatically handle attributes that
|
||||
# start with "assert"
|
||||
session.assertPerm = mock.MagicMock()
|
||||
session.hasPerm = mock.MagicMock()
|
||||
session.hasPerm.return_value = False
|
||||
dist_repo_init.return_value = ('repo_id', 'event_id')
|
||||
make_task.return_value = 'task_id'
|
||||
exports = kojihub.RootExports()
|
||||
|
|
@ -101,7 +103,8 @@ class TestDistRepo(unittest.TestCase):
|
|||
|
||||
ret = exports.distRepo('tag', 'keys')
|
||||
|
||||
session.assertPerm.assert_called_once_with('dist-repo')
|
||||
session.hasPerm.has_calls(mock.call('dist_repo'), mock.call('admin'))
|
||||
assert_policy.assert_called_once_with('dist_repo', {'tag': 'tag'})
|
||||
dist_repo_init.assert_called_once()
|
||||
make_task.assert_called_once()
|
||||
self.assertEquals(ret, make_task.return_value)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue