Exemple #1
0
        public void ShouldGetDefaultAuthorizationStrategiesForParentResourcesByClaimSetId()
        {
            var testApplication = new Application
            {
                ApplicationName = "TestApplicationName"
            };

            Save(testApplication);

            var testClaimSet = new ClaimSet
            {
                ClaimSetName = "TestClaimSet",
                Application  = testApplication
            };

            Save(testClaimSet);

            var appAuthorizationStrategies = SetupApplicationAuthorizationStrategies(testApplication).ToList();
            var testResourceClaims         = SetupParentResourceClaims(new List <ClaimSet> {
                testClaimSet
            }, testApplication);
            var testAuthStrategies = SetupResourcesWithDefaultAuthorizationStrategies(appAuthorizationStrategies, testResourceClaims.ToList());

            Scoped <IGetResourcesByClaimSetIdQuery>(query =>
            {
                var results = query.AllResources(testClaimSet.ClaimSetId).ToArray();
                results.Select(x => x.DefaultAuthStrategiesForCRUD[0].AuthStrategyName).ShouldBe(testAuthStrategies.Select(x => x.AuthorizationStrategy.AuthorizationStrategyName), true);
            });
        }
Exemple #2
0
        public void ShouldGetDefaultAuthorizationStrategiesForParentResourcesWithChildrenByClaimSetId()
        {
            var testApplication = new Application
            {
                ApplicationName = "TestApplicationName"
            };

            Save(testApplication);

            var testClaimSet = new ClaimSet
            {
                ClaimSetName = "TestClaimSet",
                Application  = testApplication
            };

            Save(testClaimSet);

            var appAuthorizationStrategies = SetupApplicationAuthorizationStrategies(testApplication).ToList();

            var testResourceClaims = SetupParentResourceClaimsWithChildren(new List <ClaimSet> {
                testClaimSet
            }, testApplication);
            var testAuthStrategies = SetupResourcesWithDefaultAuthorizationStrategies(appAuthorizationStrategies, testResourceClaims.ToList());

            Transaction <SqlServerSecurityContext>(securityContext =>
            {
                var query   = new GetResourcesByClaimSetIdQuery(securityContext, GetMapper());
                var results = query.AllResources(testClaimSet.ClaimSetId).ToArray();

                var testParentResourceClaimsForId =
                    testResourceClaims
                    .Where(x => x.ClaimSet.ClaimSetId == testClaimSet.ClaimSetId &&
                           x.ResourceClaim.ParentResourceClaim == null).Select(x => x.ResourceClaim).ToArray();

                var testAuthStrategiesForParents =
                    testAuthStrategies.Where(x => x.ResourceClaim.ParentResourceClaim == null);

                results.Select(x => x.DefaultAuthStrategiesForCRUD[0].AuthStrategyName).ShouldBe(testAuthStrategiesForParents.Select(x => x.AuthorizationStrategy.AuthorizationStrategyName), true);

                foreach (var testParentResourceClaim in testParentResourceClaimsForId)
                {
                    var parentResult = results.First(x => x.Id == testParentResourceClaim.ResourceClaimId);
                    var testAuthStrategiesForChildren =
                        testAuthStrategies.Where(x =>
                                                 x.ResourceClaim.ParentResourceClaimId == testParentResourceClaim.ResourceClaimId);
                    parentResult.Children.Select(x => x.DefaultAuthStrategiesForCRUD[0].AuthStrategyName).ShouldBe(testAuthStrategiesForChildren.Select(x => x.AuthorizationStrategy.AuthorizationStrategyName), true);
                }
            });
        }
Exemple #3
0
        public void ShouldGetDefaultAuthorizationStrategiesForSingleResourcesByClaimSetIdAndResourceId()
        {
            var testApplication = new Application
            {
                ApplicationName = "TestApplicationName"
            };

            Save(testApplication);

            var testClaimSet = new ClaimSet
            {
                ClaimSetName = "TestClaimSet",
                Application  = testApplication
            };

            Save(testClaimSet);

            var appAuthorizationStrategies = SetupApplicationAuthorizationStrategies(testApplication).ToList();
            var testResourceClaims         = SetupParentResourceClaims(new List <ClaimSet> {
                testClaimSet
            }, testApplication);
            var testAuthStrategies = SetupResourcesWithDefaultAuthorizationStrategies(appAuthorizationStrategies, testResourceClaims.ToList());

            Transaction <SqlServerSecurityContext>(securityContext =>
            {
                var query             = new GetResourcesByClaimSetIdQuery(securityContext, GetMapper());
                var testResourceClaim =
                    testResourceClaims.Single(x => x.ClaimSet.ClaimSetId == testClaimSet.ClaimSetId && x.ResourceClaim.ResourceName == "TestResourceClaim3.00").ResourceClaim;
                var testAuthStrategy = testAuthStrategies.Single(x =>
                                                                 x.ResourceClaim.ResourceClaimId == testResourceClaim.ResourceClaimId && x.Action.ActionName == ActionName.Create.Value).AuthorizationStrategy;

                var result = query.SingleResource(testClaimSet.ClaimSetId, testResourceClaim.ResourceClaimId);

                result.Name.ShouldBe(testResourceClaim.ResourceName);
                result.Id.ShouldBe(testResourceClaim.ResourceClaimId);
                result.Create.ShouldBe(true);
                result.Read.ShouldBe(false);
                result.Update.ShouldBe(false);
                result.Delete.ShouldBe(false);
                result.DefaultAuthStrategiesForCRUD[0].AuthStrategyName.ShouldBe(testAuthStrategy.DisplayName);
            });
        }