def test_check_bots_list_acl_realm_no_pool_dimension(self): # mock self.mock(acl, 'can_view_bot', lambda: False) # call with self.assertRaises(auth.AuthorizationError): realms.check_bots_list_acl(None) self._has_permission_mock.assert_not_called()
def test_check_bots_list_acl_realm_unknown_pool(self): # mock self.mock(acl, 'can_view_bot', lambda: False) self.mock(pools_config, 'get_pool_config', lambda _: None) # call with self.assertRaises(endpoints.BadRequestException): realms.check_bots_list_acl(['unknown']) self._has_permission_mock.assert_not_called()
def test_check_bots_list_acl_realm_no_pool_realms(self): # mock self.mock(acl, 'can_view_bot', lambda: False) get_pool_config = lambda p: _gen_pool_config(realm=None) self.mock(pools_config, 'get_pool_config', get_pool_config) # call with self.assertRaises(auth.AuthorizationError): realms.check_bots_list_acl(['pool1', 'pool2']) self._has_permission_mock.assert_not_called()
def test_check_bots_list_acl_realm_allowed(self): # mock self.mock(acl, 'can_view_bot', lambda: False) get_pool_config = lambda p: _gen_pool_config(realm='test:' + p) self.mock(pools_config, 'get_pool_config', get_pool_config) # call realms.check_bots_list_acl(['pool1', 'pool2']) for pool_realm in ['test:pool1', 'test:pool2']: self._has_permission_mock.assert_any_call( _PERM_POOLS_LIST_BOTS, [pool_realm], identity=auth.get_current_identity())
def test_check_bots_list_acl_realm_missing_any_permission(self): # mock self.mock(acl, 'can_view_bot', lambda: False) get_pool_config = lambda p: _gen_pool_config(realm='test:' + p) self.mock(pools_config, 'get_pool_config', get_pool_config) self._has_permission_mock.side_effect = [True, False] # call with self.assertRaises(auth.AuthorizationError): realms.check_bots_list_acl(['pool1', 'pool2']) for pool_realm in ['test:pool1', 'test:pool2']: self._has_permission_mock.assert_any_call( _PERM_POOLS_LIST_BOTS, [pool_realm], identity=auth.get_current_identity())
def test_check_bots_list_acl_realm_not_allowed(self): # mock self.mock(acl, 'can_view_bot', lambda: False) get_pool_config = lambda p: _gen_pool_config(realm='test:' + p) self.mock(pools_config, 'get_pool_config', get_pool_config) self._has_permission_mock.return_value = False # call with self.assertRaises(auth.AuthorizationError): realms.check_bots_list_acl(['pool1', 'pool2']) # it checks only the first realm and fails. self._has_permission_mock.assert_any_call( _PERM_POOLS_LIST_BOTS, ['test:pool1'], identity=auth.get_current_identity())
def test_check_bots_list_acl_with_global_permission(self): self.mock(acl, 'can_view_bot', lambda: True) realms.check_bots_list_acl(None) self._has_permission_mock.assert_not_called()