From 9ef57c0f822eeb3b62c0d320abb1f47a2c45f539 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Thu, 12 Mar 2020 16:08:46 +0100 Subject: [PATCH 1/3] new policy for dist-repo Fixes: https://pagure.io/koji/issue/1660 --- hub/kojihub.py | 8 +++++++- tests/test_hub/test_dist_repo.py | 9 ++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/hub/kojihub.py b/hub/kojihub.py index 0f289e89..68c06f53 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -11829,7 +11829,13 @@ 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'): + policy_data = { + 'tag': tag, + 'keys': keys, + } + assert_policy('dist_repo', policy_data) + repo_id, event_id = dist_repo_init(tag, keys, task_opts) task_opts['event'] = event_id # cancel potentially running distRepos diff --git a/tests/test_hub/test_dist_repo.py b/tests/test_hub/test_dist_repo.py index f685908b..536a899f 100644 --- a/tests/test_hub/test_dist_repo.py +++ b/tests/test_hub/test_dist_repo.py @@ -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', 'keys': 'keys'}) dist_repo_init.assert_called_once() make_task.assert_called_once() self.assertEquals(ret, make_task.return_value) From 09da0aa1e40dc4f494072b8207d6210cb04655d0 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Mon, 16 Mar 2020 09:30:36 +0100 Subject: [PATCH 2/3] fix typo --- tests/test_hub/test_dist_repo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_hub/test_dist_repo.py b/tests/test_hub/test_dist_repo.py index 536a899f..2cf10608 100644 --- a/tests/test_hub/test_dist_repo.py +++ b/tests/test_hub/test_dist_repo.py @@ -104,7 +104,7 @@ class TestDistRepo(unittest.TestCase): ret = exports.distRepo('tag', 'keys') session.hasPerm.has_calls(mock.call('dist_repo'), mock.call('admin')) - assert_policy.assert_called_once_with('dist-repo', {'tag': 'tag', 'keys': 'keys'}) + assert_policy.assert_called_once_with('dist_repo', {'tag': 'tag', 'keys': 'keys'}) dist_repo_init.assert_called_once() make_task.assert_called_once() self.assertEquals(ret, make_task.return_value) From 7970e78092f2f5d7fe9d7331a58dff86d2aeb554 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Mon, 6 Apr 2020 09:21:12 +0200 Subject: [PATCH 3/3] drop "keys" field --- hub/kojihub.py | 7 +------ tests/test_hub/test_dist_repo.py | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/hub/kojihub.py b/hub/kojihub.py index 68c06f53..5932415d 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -11830,12 +11830,7 @@ class RootExports(object): def distRepo(self, tag, keys, **task_opts): """Create a dist-repo task. returns task id""" if not context.session.hasPerm('dist-repo') and not context.session.hasPerm('admin'): - policy_data = { - 'tag': tag, - 'keys': keys, - } - assert_policy('dist_repo', policy_data) - + 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 diff --git a/tests/test_hub/test_dist_repo.py b/tests/test_hub/test_dist_repo.py index 2cf10608..92e34bfa 100644 --- a/tests/test_hub/test_dist_repo.py +++ b/tests/test_hub/test_dist_repo.py @@ -104,7 +104,7 @@ class TestDistRepo(unittest.TestCase): ret = exports.distRepo('tag', 'keys') session.hasPerm.has_calls(mock.call('dist_repo'), mock.call('admin')) - assert_policy.assert_called_once_with('dist_repo', {'tag': 'tag', 'keys': 'keys'}) + 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)