Esempio n. 1
0
    def test_delete_role_permission_allow(self):

        role_id1, role_id2 = 1, 2
        role_name1, role_name2 = 'role_name1', 'role_name2'

        res_name1, res_name2 = 'res_name1', 'res_name2'

        perm_id1, perm_id2 = 11, 22
        perm_name1, perm_name2 = 'perm_name1', 'perm_name2'

        rbac = RBAC()

        rbac.create_role(role_id1, role_name1, None)
        rbac.create_role(role_id2, role_name2, None)

        rbac.create_resource(res_name1)
        rbac.create_resource(res_name2)

        rbac.create_permission(perm_id1, perm_name1)
        rbac.create_permission(perm_id2, perm_name2)

        rbac.create_role_permission_allow(role_id1, perm_id1, res_name1)
        rbac.create_role_permission_allow(role_id1, perm_id2, res_name1)

        rbac.create_role_permission_allow(role_id2, perm_id1, res_name2)
        rbac.create_role_permission_allow(role_id2, perm_id2, res_name2)

        self.assertIn((role_id1, perm_id1, res_name1), rbac.registry._allowed)
        self.assertIn((role_id1, perm_id2, res_name1), rbac.registry._allowed)

        self.assertIn((role_id2, perm_id1, res_name2), rbac.registry._allowed)
        self.assertIn((role_id2, perm_id2, res_name2), rbac.registry._allowed)

        rbac.delete_role_permission_allow(role_id1, perm_id1, res_name1)
        rbac.delete_role_permission_allow(role_id2, perm_id1, res_name2)

        self.assertNotIn((role_id1, perm_id1, res_name1),
                         rbac.registry._allowed)
        self.assertIn((role_id1, perm_id2, res_name1), rbac.registry._allowed)

        self.assertNotIn((role_id2, perm_id1, res_name2),
                         rbac.registry._allowed)
        self.assertIn((role_id2, perm_id2, res_name2), rbac.registry._allowed)
Esempio n. 2
0
    def test_delete_role_permission_allow(self):

        role_id1, role_id2 = 1, 2
        role_name1, role_name2 = 'role_name1', 'role_name2'

        res_name1, res_name2 = 'res_name1', 'res_name2'

        perm_id1, perm_id2 = 11, 22
        perm_name1, perm_name2 = 'perm_name1', 'perm_name2'

        rbac = RBAC()

        rbac.create_role(role_id1, role_name1, None)
        rbac.create_role(role_id2, role_name2, None)

        rbac.create_resource(res_name1)
        rbac.create_resource(res_name2)

        rbac.create_permission(perm_id1, perm_name1)
        rbac.create_permission(perm_id2, perm_name2)

        rbac.create_role_permission_allow(role_id1, perm_id1, res_name1)
        rbac.create_role_permission_allow(role_id1, perm_id2, res_name1)

        rbac.create_role_permission_allow(role_id2, perm_id1, res_name2)
        rbac.create_role_permission_allow(role_id2, perm_id2, res_name2)

        self.assertIn((role_id1, perm_id1, res_name1), rbac.registry._allowed)
        self.assertIn((role_id1, perm_id2, res_name1), rbac.registry._allowed)

        self.assertIn((role_id2, perm_id1, res_name2), rbac.registry._allowed)
        self.assertIn((role_id2, perm_id2, res_name2), rbac.registry._allowed)

        rbac.delete_role_permission_allow(role_id1, perm_id1, res_name1)
        rbac.delete_role_permission_allow(role_id2, perm_id1, res_name2)

        self.assertNotIn((role_id1, perm_id1, res_name1), rbac.registry._allowed)
        self.assertIn((role_id1, perm_id2, res_name1), rbac.registry._allowed)

        self.assertNotIn((role_id2, perm_id1, res_name2), rbac.registry._allowed)
        self.assertIn((role_id2, perm_id2, res_name2), rbac.registry._allowed)