Esempio n. 1
0
    def test_object_creation_from_json(self):
        test_dict = {
            'roles': ['superuser', ['user_1', ['superuser', ], ], 'user_2', ],
            'privileges': ['browse.blog.post', 'view.blog.post', 'add.blog.post', 'edit.blog.post', 'delete.blog.post', ],
            'resources': ['blog.post.1', 'blog.post.2', ],
            'acl': {
                'any': {'superuser': {'any': True}},
                'blog.post.2': {'user_2': {'view.blog.post': True}},
            }
        }
        test_json = json.dumps(test_dict)
        acl = simpleacl.Acl.create_instance(test_json)
        self.assertTrue(isinstance(acl, simpleacl.Acl))
        self.assertTrue(acl.is_allowed('user_2', 'view.blog.post', 'blog.post.2'))
        self.assertFalse(acl.is_allowed('user_2', 'edit.blog.post', 'blog.post.2'))
        self.assertFalse(acl.is_allowed('user_2', 'view.blog.post', 'blog.post.1'))

        self.assertTrue(acl.is_allowed('user_1', 'view.blog.post', 'blog.post.2'))
        self.assertTrue(acl.is_allowed('user_1', 'edit.blog.post', 'blog.post.2'))
        self.assertTrue(acl.is_allowed('user_1', 'view.blog.post', 'blog.post.1'))
Esempio n. 2
0
 def test_object_creation_from_json(self):
     test_dict = {'roles': ['role1', 'role2'], 'privileges': ['r1', 'r2',
         'r3']}
     test_json = json.dumps(test_dict)
     acl = simpleacl.Acl.create_instance(test_json)
     self.assertTrue(isinstance(acl, simpleacl.Acl))
Esempio n. 3
0
    def test_object_creation_from_json2(self):
        test_dict = {
            'roles': [
                'moderator',
                'author',
                'authenticated',
                ['user_1', {'any': ['authenticated'],
                            'blog': ['moderator']}],
                ['user_2', {'any': ['authenticated'],
                            'blog.post.2': ['author']}],
                ['user_3', {'any': ['authenticated'],
                            'blog.post.2': ['moderator']}],
            ],
            'privileges': [
                'browse.blog.post',
                'view.blog.post',
                'add.blog.post',
                'edit.blog.post',
                'delete.blog.post',
            ],
            'resources': ['blog.post.1', 'blog.post.2', 'blog.post.3', 'board.message.3'],
            'acl': {
                'any': {
                    'authenticated': {'browse.blog.post': True},
                },
                'blog.post': {
                    'moderator': {'browse': True,
                                  'view': True,
                                  'edit': True},
                    'author': {'browse.blog.post': True,
                               'view.blog.post': True,
                               'edit.blog.post': True},
                }
            }
        }
        test_json = json.dumps(test_dict)
        acl = simpleacl.Acl.create_instance(test_json)
        self.assertTrue(isinstance(acl, simpleacl.Acl))
        self.assertTrue(acl.is_allowed('user_2', 'browse.blog.post', 'blog.post.2'))
        self.assertTrue(acl.is_allowed('user_2', 'view.blog.post', 'blog.post.2'))
        self.assertTrue(acl.is_allowed('user_2', 'edit.blog.post', 'blog.post.2'))
        self.assertFalse(acl.is_allowed('user_2', 'delete.blog.post', 'blog.post.2'))
        self.assertFalse(acl.is_allowed('user_2', 'edit.blog.post', 'blog.post'))
        self.assertFalse(acl.is_allowed('user_2', 'edit.blog', 'blog.post'))

        self.assertTrue(acl.is_allowed('user_2', 'browse.blog.post', 'blog.post.1'))
        self.assertFalse(acl.is_allowed('user_2', 'edit.blog.post', 'blog.post.1'))

        self.assertTrue(acl.is_allowed('user_1', 'view.blog.post', 'blog.post.2'))
        self.assertTrue(acl.is_allowed('user_1', 'edit.blog.post', 'blog.post.2'))
        self.assertTrue(acl.is_allowed('user_1', 'edit.blog.post', 'blog.post.1'))
        self.assertTrue(acl.is_allowed('user_1', 'edit.blog.post', 'blog.post'))
        self.assertTrue(acl.is_allowed('user_1', 'edit.blog', 'blog.post.2'))
        self.assertTrue(acl.is_allowed('user_1', 'edit.blog', 'blog.post'))
        self.assertTrue(acl.is_allowed('user_1', 'view.blog.post', 'blog.post.1'))
        self.assertFalse(acl.is_allowed('user_1', 'view', 'blog'))
        self.assertFalse(acl.is_allowed('user_1', 'view', 'board.message.3'))

        self.assertTrue(acl.is_allowed('user_3', 'edit.blog.post', 'blog.post.2'))
        self.assertFalse(acl.is_allowed('user_3', 'edit.blog.post', 'blog.post.3'))
        self.assertFalse(acl.is_allowed('user_3', 'edit.blog.post', 'blog.post'))
        self.assertFalse(acl.is_allowed('user_3', 'edit.blog.post', 'blog'))