예제 #1
0
        public async Task TestModifyGroupingPolicyAsync()
        {
            var e = new Enforcer(_testModelFixture.GetNewRbacTestModel());

            e.BuildRoleLinks();

            TestGetRoles(e, "alice", AsList("data2_admin"));
            TestGetRoles(e, "bob", AsList());
            TestGetRoles(e, "eve", AsList());
            TestGetRoles(e, "non_exist", AsList());

            await e.RemoveGroupingPolicyAsync("alice", "data2_admin");

            await e.AddGroupingPolicyAsync("bob", "data1_admin");

            await e.AddGroupingPolicyAsync("eve", "data3_admin");

            var groupingRules = AsList(
                AsList("ham", "data4_admin"),
                AsList("jack", "data5_admin")
                );

            _ = await e.AddGroupingPoliciesAsync(groupingRules);

            TestGetRoles(e, "ham", AsList("data4_admin"));
            TestGetRoles(e, "jack", AsList("data5_admin"));
            _ = await e.RemoveGroupingPoliciesAsync(groupingRules);

            TestGetRoles(e, "alice", AsList());
            var namedGroupingPolicy = AsList("alice", "data2_admin");

            TestGetRoles(e, "alice", AsList());
            await e.AddNamedGroupingPolicyAsync("g", namedGroupingPolicy);

            TestGetRoles(e, "alice", AsList("data2_admin"));
            await e.RemoveNamedGroupingPolicyAsync("g", namedGroupingPolicy);

            TestGetRoles(e, "alice", AsList());
            TestGetRoles(e, "bob", AsList("data1_admin"));
            TestGetRoles(e, "eve", AsList("data3_admin"));
            TestGetRoles(e, "non_exist", AsList());

            TestGetUsers(e, "data1_admin", AsList("bob"));
            TestGetUsers(e, "data2_admin", AsList());
            TestGetUsers(e, "data3_admin", AsList("eve"));

            await e.RemoveFilteredGroupingPolicyAsync(0, "bob");

            TestGetRoles(e, "alice", AsList());
            TestGetRoles(e, "bob", AsList());
            TestGetRoles(e, "eve", AsList("data3_admin"));
            TestGetRoles(e, "non_exist", AsList());

            TestGetUsers(e, "data1_admin", AsList());
            TestGetUsers(e, "data2_admin", AsList());
            TestGetUsers(e, "data3_admin", AsList("eve"));
        }