예제 #1
0
        public void RolesTest03()
        {
            var systemManager = VLSystemManager.GetAnInstance(admin);

            try
            {
                VLAccessToken _atoken = new VLAccessToken(admin);

                //Δημιουργούμε ένα νέο ρόλο:
                var role01 = systemManager.CreateRole("ρόλος1", permissions: VLPermissions.Developer | VLPermissions.ManageSecurity);
                Assert.IsNotNull(role01);
                _atoken.Permissions = role01.Permissions;

                var _manager = new TestManager(_atoken);
                Assert.IsFalse(_manager.HasPermissions(VLPermissions.ManageSystem));
                Assert.IsFalse(_manager.ValidatePermissions(VLPermissions.ManageSystem));
                _EXECUTEAndCATCHType(delegate { _manager.CheckPermissions(VLPermissions.ManageSystem); }, typeof(VLAccessDeniedException));


                Assert.IsFalse(_manager.HasPermissions(VLPermissions.ManageSystem | VLPermissions.Developer));
                Assert.IsFalse(_manager.ValidatePermissions(VLPermissions.ManageSystem | VLPermissions.Developer));
                _EXECUTEAndCATCHType(delegate { _manager.CheckPermissions(VLPermissions.ManageSystem | VLPermissions.Developer); }, typeof(VLAccessDeniedException));

                Assert.IsFalse(_manager.HasPermissions(VLPermissions.ManageSystem | VLPermissions.Developer | VLPermissions.ManageSecurity));
                Assert.IsFalse(_manager.ValidatePermissions(VLPermissions.ManageSystem | VLPermissions.Developer | VLPermissions.ManageSecurity));
                _EXECUTEAndCATCHType(delegate { _manager.CheckPermissions(VLPermissions.ManageSystem | VLPermissions.Developer | VLPermissions.ManageSecurity); }, typeof(VLAccessDeniedException));


                Assert.IsTrue(_manager.HasPermissions(VLPermissions.Developer | VLPermissions.ManageSecurity));
                Assert.IsTrue(_manager.ValidatePermissions(VLPermissions.Developer | VLPermissions.ManageSecurity));
                _EXECUTE_SUCCESS(delegate { _manager.ValidatePermissions(VLPermissions.Developer | VLPermissions.ManageSecurity); });


                Assert.IsTrue(_manager.ValidatePermissions(VLPermissions.ManageSystemParameters, VLPermissions.Developer | VLPermissions.ManageSecurity));
                _EXECUTE_SUCCESS(delegate { _manager.ValidatePermissions(VLPermissions.ManageSystemParameters, VLPermissions.Developer | VLPermissions.ManageSecurity); });

                Assert.IsTrue(_manager.ValidatePermissions(VLPermissions.ManageThemes, VLPermissions.ManageSystemParameters | VLPermissions.ManageSecurity, VLPermissions.Developer | VLPermissions.ManageSecurity));
                _EXECUTE_SUCCESS(delegate { _manager.ValidatePermissions(VLPermissions.ManageThemes, VLPermissions.ManageSystemParameters | VLPermissions.ManageSecurity, VLPermissions.Developer | VLPermissions.ManageSecurity); });
            }
            finally
            {
                var roles = systemManager.GetRoles();
                foreach (var item in roles)
                {
                    if (item.IsBuiltIn == false)
                    {
                        systemManager.DeleteRole(item.RoleId);
                    }
                }
            }
        }