Exemplo n.º 1
0
    def test_check_task_get_acl_no_pool_cfg(self):
        # mock
        self.mock(acl, 'can_view_task', lambda _: False)
        self.mock(pools_config, 'get_pool_config', lambda _: None)

        # call
        task = _gen_task_request_mock(pool='pool1')
        with self.assertRaises(endpoints.InternalServerErrorException):
            realms.check_task_get_acl(task)
        self._has_permission_mock.assert_not_called()
Exemplo n.º 2
0
    def test_check_task_get_acl_allowed_by_task_permission(self):
        # mock
        self.mock(acl, 'can_view_task', lambda _: False)
        get_pool_config = lambda _: _gen_pool_config(realm=None)
        self.mock(pools_config, 'get_pool_config', get_pool_config)
        self._has_permission_mock.return_value = True

        # call
        task = _gen_task_request_mock(realm='test:realm')
        realms.check_task_get_acl(task)
        self._has_permission_mock.assert_called_once_with(
            _PERM_TASKS_GET, ['test:realm'])
Exemplo n.º 3
0
    def test_check_task_get_acl_no_pool_realm(self):
        # mock
        self.mock(acl, 'can_view_task', lambda _: False)
        get_pool_config = lambda p: _gen_pool_config(realm=None)
        self.mock(pools_config, 'get_pool_config', get_pool_config)
        self._mock_bot(['pool:pool1'])

        # call
        task = _gen_task_request_mock(pool='pool1', bot_id='bot1', realm=None)
        with self.assertRaises(auth.AuthorizationError):
            realms.check_task_get_acl(task)
        self._has_permission_mock.assert_not_called()
Exemplo n.º 4
0
    def test_check_task_get_acl_allowed_by_bot_pool_permission(self):
        # mock
        self.mock(acl, 'can_view_task', lambda _: False)
        get_pool_config = lambda p: _gen_pool_config(realm='test:' + p)
        self.mock(pools_config, 'get_pool_config', get_pool_config)
        self._mock_bot(['pool:pool1', 'pool:pool2'])
        self._has_permission_mock.return_value = True

        # call
        task = _gen_task_request_mock(bot_id='bot1')
        realms.check_task_get_acl(task)
        self._has_permission_mock.assert_called_once_with(
            _PERM_POOLS_LIST_TASKS, ['test:pool1', 'test:pool2'])
Exemplo n.º 5
0
    def test_check_task_get_acl_not_allowed(self):
        # mock
        self.mock(acl, 'can_view_task', lambda _: False)
        get_pool_config = lambda p: _gen_pool_config(realm='test:' + p)
        self.mock(pools_config, 'get_pool_config', get_pool_config)
        self._mock_bot(['pool:pool1', 'pool:pool2'])
        self._has_permission_mock.return_value = False

        # call
        with self.assertRaises(auth.AuthorizationError):
            task = _gen_task_request_mock(pool='pool1',
                                          bot_id='bot1',
                                          realm='test:realm')
            realms.check_task_get_acl(task)
        self._has_permission_mock.assert_any_call(_PERM_POOLS_LIST_TASKS,
                                                  ['test:pool1'])
        self._has_permission_mock.assert_any_call(_PERM_POOLS_LIST_TASKS,
                                                  ['test:pool1', 'test:pool2'])
        self._has_permission_mock.assert_any_call(_PERM_TASKS_GET,
                                                  ['test:realm'])
Exemplo n.º 6
0
    def test_check_task_get_acl_with_global_permission(self):
        self.mock(acl, 'can_view_task', lambda _: True)

        realms.check_task_get_acl(None)
        self._has_permission_mock.assert_not_called()