public GuardianPermissionsTests()
 {
     _permissions = new GuardianPermissions();
     _permissions.General.AddRange(Seed.GeneralPermissions);
     _permissions.RowLevel.AddRange(Seed.RowPermissions);
     _permissions.ColumnLevel.AddRange(Seed.ColumnRestrictions);
 }
Exemple #2
0
        public void Check_WithColumnRestrictions_ShouldReturnRestricted()
        {
            var model = new Model1()
            {
                Id        = 1,
                Property1 = "Property1",
                Property2 = "Property2"
            };

            var permissions = new GuardianPermissions();

            permissions.RowLevel.Add(new TestRowPermission()
            {
                AccessType     = AccessTypes.Get,
                EntityTypeName = model.GetType().Name,
                RowIdentifier  = "1"
            });

            permissions.ColumnLevel.Add(new TestColumnRestriction()
            {
                AccessType     = AccessTypes.Get,
                EntityTypeName = model.GetType().Name,
                PropertyName   = "Property1"
            });

            _kernel.Permissions = permissions;

            var policyContext = GetPolicyContext(model);

            var result = _policy.Check(policyContext, _kernel);

            Assert.Equal(true, result);

            Assert.Equal(true, model.ProtectedProperties.Contains("Property1"));
        }
        public void Check_WithRowLevelPermission_ShouldReturnTrue()
        {
            var model = new Model1()
            {
                Id        = 1,
                Property1 = "Property1",
                Property2 = "Property2"
            };

            var permissions = new GuardianPermissions();

            permissions.RowLevel.Add(new TestRowPermission()
            {
                AccessType     = AccessTypes.Add,
                EntityTypeName = model.GetType().Name,
                RowIdentifier  = "1"
            });

            _kernel.Permissions = permissions;

            var policyContext = GetPolicyContext(model, AccessTypes.Add);

            var result = _policy.Check(policyContext, _kernel);

            Assert.Equal(true, result);
        }
Exemple #4
0
        public void Check_WithNoPermissions_ShouldReturnFalse()
        {
            var permissions = new GuardianPermissions();

            _kernel.Permissions = permissions;

            var model = new Model1()
            {
                Id        = 1,
                Property1 = "Property1",
                Property2 = "Property2"
            };

            var policyContext = GetPolicyContext(model);

            var result = _policy.Check(policyContext, _kernel);

            Assert.Equal(false, result);
        }
        public void Check_WithGeneralPermission_ShouldReturnTrue()
        {
            var model = new Model1()
            {
                Id        = 1,
                Property1 = "Property1",
                Property2 = "Property2"
            };

            var permissions = new GuardianPermissions();

            permissions.General.Add(new TestPermission()
            {
                AccessType     = AccessTypes.Update,
                EntityTypeName = model.GetType().Name
            });
            _kernel.Permissions = permissions;

            var policyContext = GetPolicyContext(model, AccessTypes.Update);

            var result = _policy.Check(policyContext, _kernel);

            Assert.Equal(true, result);
        }