public void CheckRulesAsOne_AllRules_Should_Satisfied() { //result = rule1 && rule2 //result = allowedUsers || allowedRoles var logic = new RoleBasedCheckLogic(); var theRule = RoleBasedPermissionRule.Create("MockPermission", "bob, john", ""); var theRule2 = RoleBasedPermissionRule.Create("MockPermission", "", "Admin, super"); var theRules = new List <RoleBasedPermissionRule>() { theRule, theRule2 }; var bobContext = MockHelper.CreatePermissionCheckContext("A, B, MockPermission", "bob"); logic.CheckRulesAsOne(theRules, bobContext).LogJson().Category.ShouldEqual(PermissionCheckResultCategory.Forbidden); var johnContext = MockHelper.CreatePermissionCheckContext("A, B, MockPermission", "john", "Admin"); logic.CheckRulesAsOne(theRules, johnContext).LogJson().Category.ShouldEqual(PermissionCheckResultCategory.Allowed); var marryContext = MockHelper.CreatePermissionCheckContext("A, B, MockPermission", "marry", "Admin", "Super"); logic.CheckRulesAsOne(theRules, marryContext).LogJson().Category.ShouldEqual(PermissionCheckResultCategory.Forbidden); var jackContext = MockHelper.CreatePermissionCheckContext("A, B, MockPermission", "jack", "FooRole"); logic.CheckRulesAsOne(theRules, jackContext).LogJson().Category.ShouldEqual(PermissionCheckResultCategory.Forbidden); var tomContext = MockHelper.CreatePermissionCheckContext("A, B, MockPermission", "tom", "Leader"); logic.CheckRulesAsOne(theRules, tomContext).LogJson().Category.ShouldEqual(PermissionCheckResultCategory.Forbidden); }
public void CheckUserRule_Should_Ok() { var logic = new RoleBasedCheckLogic(); var theRule = RoleBasedPermissionRule.Create("MockPermission", "bob, john", ""); var bobContext = MockHelper.CreatePermissionCheckContext("A, B, MockPermission", "bob"); logic.Check(theRule, bobContext).LogJson().Category.ShouldEqual(PermissionCheckResultCategory.Allowed); var johnContext = MockHelper.CreatePermissionCheckContext("A, B, MockPermission", "john"); logic.Check(theRule, johnContext).LogJson().Category.ShouldEqual(PermissionCheckResultCategory.Allowed); var jackContext = MockHelper.CreatePermissionCheckContext("A, B, MockPermission", "jack"); logic.Check(theRule, jackContext).LogJson().Category.ShouldEqual(PermissionCheckResultCategory.Forbidden); }
public void CheckUserRoleRule_Should_Ok() { //result = allowedUsers || allowedRoles var logic = new RoleBasedCheckLogic(); var theRule = RoleBasedPermissionRule.Create("MockPermission", "bob, john", "Admin, super"); var bobContext = MockHelper.CreatePermissionCheckContext("A, B, MockPermission", "bob"); logic.Check(theRule, bobContext).LogJson().Category.ShouldEqual(PermissionCheckResultCategory.Allowed); var johnContext = MockHelper.CreatePermissionCheckContext("A, B, MockPermission", "john", "FooRole"); logic.Check(theRule, johnContext).LogJson().Category.ShouldEqual(PermissionCheckResultCategory.Allowed); var marryContext = MockHelper.CreatePermissionCheckContext("A, B, MockPermission", "marry", "Admin", "Super"); logic.Check(theRule, marryContext).LogJson().Category.ShouldEqual(PermissionCheckResultCategory.Allowed); var jackContext = MockHelper.CreatePermissionCheckContext("A, B, MockPermission", "jack", "FooRole"); logic.Check(theRule, jackContext).LogJson().Category.ShouldEqual(PermissionCheckResultCategory.Forbidden); }