Exemple #1
0
        public void CantPerformActionNotGranted()
        {
            var options = GetSecurityAccessProviderOptions();
            var sec     = new SecurityAccessProvider(options);
            var id      = GetIdentity();

            var result = sec.CanPerformOperation("ControllerA", "Details", id);

            result.Should().Be(false);
        }
Exemple #2
0
        public void GlobalDeniedControllersShouldTakePrecenceOverExplicitGrants()
        {
            var options = GetSecurityAccessProviderOptions();
            var sec     = new SecurityAccessProvider(options);
            var id      = GetIdentity();

            var result = sec.CanPerformOperation("ControllerB", "Details", id);

            options.Value.SecurityRoles[0].AllowActions.IndexOf("ControllerB.Details").Should().BeGreaterOrEqualTo(0);
            options.Value.GlobalAllowActions.IndexOf("ControllerB.Details").Should().BeGreaterOrEqualTo(0);
            options.Value.GlobalDenyActions.IndexOf("ControllerB").Should().BeGreaterOrEqualTo(0);
            result.Should().Be(false);
        }
Exemple #3
0
        public void CantPerformActionDeniedInInGlobalListEvenIfGrantedToRole()
        {
            var options = GetSecurityAccessProviderOptions();
            var sec     = new SecurityAccessProvider(options);
            var id      = GetIdentity();

            var result = sec.CanPerformOperation("ControllerA", "Delete", id);

            options.Value.SecurityRoles[0].AllowActions.IndexOf("ControllerA.Delete").Should().BeGreaterOrEqualTo(0);
            options.Value.GlobalAllowActions.IndexOf("ControllerA.Delete").Should().Be(-1);
            options.Value.GlobalDenyActions.IndexOf("ControllerA.Delete").Should().BeGreaterOrEqualTo(0);
            options.Value.GlobalDenyActions.IndexOf("ControllerA").Should().Be(-1);
            result.Should().Be(false);
        }
Exemple #4
0
        public void CantPerformUnconfiguredROles()
        {
            var options = GetSecurityAccessProviderOptions();
            var sec     = new SecurityAccessProvider(options);
            var id      = GetIdentity();

            var result = sec.CanPerformOperation("ControllerA", "DoAThing", id);

            options.Value.SecurityRoles[0].AllowActions.IndexOf("ControllerA.DoAThing").Should().Be(-1);
            options.Value.GlobalAllowActions.IndexOf("ControllerA.DoAThing").Should().Be(-1);
            options.Value.GlobalDenyActions.IndexOf("ControllerA.DoAThing").Should().Be(-1);
            options.Value.GlobalDenyActions.IndexOf("ControllerA").Should().Be(-1);
            result.Should().Be(false);
        }
Exemple #5
0
        public void CanPerformActionAllowedInGlobalList()
        {
            var options = GetSecurityAccessProviderOptions();
            var sec     = new SecurityAccessProvider(options);
            var id      = GetIdentity();

            var result = sec.CanPerformOperation("ControllerA", "List", id);

            options.Value.SecurityRoles[0].AllowActions.IndexOf("ControllerA.List").Should().Be(-1);
            options.Value.GlobalAllowActions.IndexOf("ControllerA.List").Should().BeGreaterOrEqualTo(0);
            options.Value.GlobalDenyActions.IndexOf("ControllerA.List").Should().Be(-1);
            options.Value.GlobalDenyActions.IndexOf("ControllerA").Should().Be(-1);
            result.Should().Be(true);
        }
Exemple #6
0
        protected JArray GetSecurityFilteredActions(string actions)
        {
            var    actionsList = actions.Split(",");
            JArray results     = new JArray();

            foreach (var item in actionsList)
            {
                if (_securityAccessProvider.CanPerformOperation(Name, item, User.Identity as ClaimsIdentity))
                {
                    results.Add(item);
                }
            }
            return(results);
        }
Exemple #7
0
        public void GrantActionBasedOnWildcardControllerAliasedAction()
        {
            var options = GetSecurityAccessProviderOptions();
            var sec     = new SecurityAccessProvider(options);
            var id      = GetIdentity("WildcardAppliedRoleId");

            sec.CanPerformOperation("UndefinedController", "ReaderAppliedAction1", id).Should().Be(true);
            sec.CanPerformOperation("UndefinedController", "ReaderAppliedAction2", id).Should().Be(true);
            sec.CanPerformOperation("UndefinedController", "WriterAppliedAction1", id).Should().Be(true);
            sec.CanPerformOperation("UndefinedController", "WriterAppliedAction2", id).Should().Be(true);
            sec.CanPerformOperation("UndefinedController", "Create", id).Should().Be(true);
            sec.CanPerformOperation("UndefinedController", "UnknownAction", id).Should().Be(false);
        }
Exemple #8
0
        public void GrantActionBasedOnInnerWildCardActionName()
        {
            var options = GetSecurityAccessProviderOptions();
            var sec     = new SecurityAccessProvider(options);
            var id      = GetIdentity();

            //test the wildcard inclusion
            sec.CanPerformOperation("ControllerA", "WildCardItem", id).Should().Be(true);
            sec.CanPerformOperation("ControllerA", "WildCardItem*", id).Should().Be(true);
            sec.CanPerformOperation("ControllerA", "WildCardItemRANDOMTEXT", id).Should().Be(true);

            //varify that it's not caught up in a full-action wildcard assignmenent
            sec.CanPerformOperation("ControllerA", "BoopWildCardItemRANDOMTEXT", id).Should().Be(false);
            sec.CanPerformOperation("ControllerB", "WildCardItem*", id).Should().Be(false);
            sec.CanPerformOperation("ControllerB", "WildCardItemRANDOMTEXT", id).Should().Be(false);
        }
Exemple #9
0
        public void GrantActionBasedOnAliasedActions()
        {
            var options = GetSecurityAccessProviderOptions();
            var sec     = new SecurityAccessProvider(options);
            var id      = GetIdentity("AliasAppliedRoleId");

            sec.CanPerformOperation("GlobalAppliedController", "ReaderAppliedAction1", id).Should().Be(true);
            sec.CanPerformOperation("GlobalAppliedController", "ReaderAppliedAction2", id).Should().Be(true);
            sec.CanPerformOperation("GlobalAppliedController", "WriterAppliedAction1", id).Should().Be(true);
            sec.CanPerformOperation("GlobalAppliedController", "WriterAppliedAction2", id).Should().Be(true);
            sec.CanPerformOperation("UserAppliedController", "ReaderAppliedAction1", id).Should().Be(true);
            sec.CanPerformOperation("UserAppliedController", "ReaderAppliedAction2", id).Should().Be(true);
            sec.CanPerformOperation("UserAppliedController", "WriterAppliedAction1", id).Should().Be(true);
            sec.CanPerformOperation("UserAppliedController", "WriterAppliedAction2", id).Should().Be(true);
            sec.CanPerformOperation("UserAppliedController", "UnknownAction", id).Should().Be(false);
            sec.CanPerformOperation("OtherController", "ReaderAppliedAction1", id).Should().Be(false);
            sec.CanPerformOperation("OtherController", "ReaderAppliedAction2", id).Should().Be(false);
        }