예제 #1
0
 def setUp(self):
     self.permissions_mixin = ResolwePermissionsMixin()
예제 #2
0
 def setUp(self):
     super(PermissionsMixinTestCase, self).setUp()
     self.permissions_mixin = ResolwePermissionsMixin()
예제 #3
0
class PermissionsMixinTestCase(unittest.TestCase):
    def setUp(self):
        self.permissions_mixin = ResolwePermissionsMixin()

    def test_filter_owner_permission(self):
        """Check that ``owner`` permission is catched everywhere"""
        data_template = {
            'users': {
                'add': {
                    1: ['view'],
                    2: ['view', 'edit']
                },
                'remove': {
                    3: ['view', 'edit']
                }
            },
            'groups': {
                'add': {
                    1: ['view', 'edit']
                },
                'remove': {
                    2: ['view']
                }
            }
        }

        self.permissions_mixin._filter_owner_permission(data_template)  # pylint: disable=protected-access

        data = deepcopy(data_template)
        data['users']['add'][1].append('owner')
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_owner_permission(data)  # pylint: disable=protected-access

        data = deepcopy(data_template)
        data['users']['remove'][3].append('owner')
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_owner_permission(data)  # pylint: disable=protected-access

        data = deepcopy(data_template)
        data['groups']['add'][1].append('owner')
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_owner_permission(data)  # pylint: disable=protected-access

        data = deepcopy(data_template)
        data['groups']['remove'][2].append('owner')
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_owner_permission(data)  # pylint: disable=protected-access

    def test_filter_user_permissions(self):
        """Check that user cannot change his own permissions"""
        data = {
            'users': {
                'add': {
                    1: ['view'],
                },
                'remove': {
                    2: ['view', 'edit']
                }
            }
        }

        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_user_permissions(data, 1)  # pylint: disable=protected-access

        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_user_permissions(data, 2)  # pylint: disable=protected-access

        self.permissions_mixin._filter_user_permissions(data, 3)  # pylint: disable=protected-access

    def test_filter_public_permissions(self):
        """Check that public user cannot get to open permissions"""
        data = {'public': {'add': ['view']}}
        self.permissions_mixin._filter_public_permissions(data)  # pylint: disable=protected-access

        data = {'public': {'add': ['download']}}
        self.permissions_mixin._filter_public_permissions(data)  # pylint: disable=protected-access

        data = {'public': {'add': ['add']}}
        self.permissions_mixin._filter_public_permissions(data)  # pylint: disable=protected-access

        data = {'public': {'add': ['edit']}}
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_public_permissions(data)  # pylint: disable=protected-access

        data = {'public': {'add': ['share']}}
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_public_permissions(data)  # pylint: disable=protected-access

        data = {'public': {'add': ['owner']}}
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_public_permissions(data)  # pylint: disable=protected-access

        data = {'public': {'add': ['view', 'edit']}}
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_public_permissions(data)  # pylint: disable=protected-access
예제 #4
0
class PermissionsMixinTestCase(TestCase):
    def setUp(self):
        super(PermissionsMixinTestCase, self).setUp()
        self.permissions_mixin = ResolwePermissionsMixin()

    def test_filter_owner_permission(self):
        """Check that ``owner`` permission is catched everywhere"""
        data_template = {
            'users': {
                'add': {
                    1: ['view'],
                    2: ['view', 'edit']
                },
                'remove': {
                    3: ['view', 'edit']
                }
            },
            'groups': {
                'add': {
                    1: ['view', 'edit']
                },
                'remove': {
                    2: ['view']
                }
            }
        }

        self.permissions_mixin._filter_owner_permission(data_template)  # pylint: disable=protected-access

        data = deepcopy(data_template)
        data['users']['add'][1].append('owner')
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_owner_permission(data)  # pylint: disable=protected-access

        data = deepcopy(data_template)
        data['users']['remove'][3].append('owner')
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_owner_permission(data)  # pylint: disable=protected-access

        data = deepcopy(data_template)
        data['groups']['add'][1].append('owner')
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_owner_permission(data)  # pylint: disable=protected-access

        data = deepcopy(data_template)
        data['groups']['remove'][2].append('owner')
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_owner_permission(data)  # pylint: disable=protected-access

    def test_filter_user_permissions(self):
        """Check that user cannot change his own permissions"""
        data = {
            'users': {
                'add': {
                    1: ['view'],
                },
                'remove': {
                    2: ['view', 'edit']
                }
            }
        }

        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_user_permissions(data, 1)  # pylint: disable=protected-access

        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_user_permissions(data, 2)  # pylint: disable=protected-access

        self.permissions_mixin._filter_user_permissions(data, 3)  # pylint: disable=protected-access

    def test_filter_public_permissions(self):
        """Check that public user cannot get to open permissions"""
        data = {'public': {'add': ['view']}}
        self.permissions_mixin._filter_public_permissions(data)  # pylint: disable=protected-access

        data = {'public': {'add': ['download']}}
        self.permissions_mixin._filter_public_permissions(data)  # pylint: disable=protected-access

        data = {'public': {'add': ['add']}}
        self.permissions_mixin._filter_public_permissions(data)  # pylint: disable=protected-access

        data = {'public': {'add': ['edit']}}
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_public_permissions(data)  # pylint: disable=protected-access

        data = {'public': {'add': ['share']}}
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_public_permissions(data)  # pylint: disable=protected-access

        data = {'public': {'add': ['owner']}}
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_public_permissions(data)  # pylint: disable=protected-access

        data = {'public': {'add': ['view', 'edit']}}
        with self.assertRaises(exceptions.PermissionDenied):
            self.permissions_mixin._filter_public_permissions(data)  # pylint: disable=protected-access