Ejemplo n.º 1
0
        public void ShouldGetAlphabeticallySortedSelectListForResourceClaims()
        {
            var testApplication = new Application
            {
                ApplicationName = "TestApplicationName"
            };

            Save(testApplication);

            var testResourceClaims  = SetupParentResourceClaimsWithChildren(testApplication).ToList();
            var parentResourceNames = testResourceClaims.Where(x => x.ParentResourceClaim == null)
                                      .OrderBy(x => x.ResourceName).Select(x => x.ResourceName).ToList();
            var childResourceNames = testResourceClaims.Where(x => x.ParentResourceClaim != null)
                                     .OrderBy(x => x.ResourceName).Select(x => x.ResourceName).ToList();

            Transaction <SqlServerSecurityContext>(securityContext =>
            {
                var query = new GetResourceClaimsQuery(securityContext);

                var results = query.GetSelectListForResourceClaims();

                // Removing "Please select a value" SelectListItem from the results
                results.RemoveAt(0);

                results.Count.ShouldBe(testResourceClaims.Count);
                results.Where(x => x.Group.Name == "Groups").Select(x => x.Text).ToList().ShouldBe(parentResourceNames);
                results.Where(x => x.Group.Name == "Resources").Select(x => x.Text).ToList().ShouldBe(childResourceNames);
            });
        }
Ejemplo n.º 2
0
        public void ShouldGetResourceClaims()
        {
            var testApplication = new Application
            {
                ApplicationName = "TestApplicationName"
            };

            Save(testApplication);

            var testResourceClaims = SetupResourceClaims(testApplication);

            Transaction <SqlServerSecurityContext>(securityContext =>
            {
                var query = new GetResourceClaimsQuery(securityContext);

                var results = query.Execute().ToArray();

                results.Length.ShouldBe(testResourceClaims.Count);
                results.Select(x => x.Name).ShouldBe(testResourceClaims.Select(x => x.ResourceName), true);
                results.Select(x => x.Id).ShouldBe(testResourceClaims.Select(x => x.ResourceClaimId), true);
                results.All(x => x.Create == false).ShouldBe(true);
                results.All(x => x.Delete == false).ShouldBe(true);
                results.All(x => x.Update == false).ShouldBe(true);
                results.All(x => x.Read == false).ShouldBe(true);
                results.All(x => x.ParentId.Equals(0)).ShouldBe(true);
                results.All(x => x.Children.IsNullOrEmpty()).ShouldBe(true);
            });
        }
Ejemplo n.º 3
0
        public void ShouldGetResourceClaims()
        {
            var testApplication = new Application
            {
                ApplicationName = "TestApplicationName"
            };

            Save(testApplication);

            var testResourceClaims = SetupResourceClaims(testApplication);

            Management.ClaimSetEditor.ResourceClaim[] results = null;
            Scoped <ISecurityContext>(securityContext =>
            {
                var query = new GetResourceClaimsQuery(securityContext);

                results = query.Execute().ToArray();
            });

            Scoped <ISecurityContext>(securityContext =>
            {
                results.Length.ShouldBe(testResourceClaims.Count);
                results.Select(x => x.Name).ShouldBe(testResourceClaims.Select(x => x.ResourceName), true);
                results.Select(x => x.Id).ShouldBe(testResourceClaims.Select(x => x.ResourceClaimId), true);
                results.All(x => x.Create == false).ShouldBe(true);
                results.All(x => x.Delete == false).ShouldBe(true);
                results.All(x => x.Update == false).ShouldBe(true);
                results.All(x => x.Read == false).ShouldBe(true);
                results.All(x => x.ParentId.Equals(0)).ShouldBe(true);
                results.All(x => x.Children.Count == 0).ShouldBe(true);
            });
        }
Ejemplo n.º 4
0
 public ClaimSetFileImportCommand(AddClaimSetCommand addClaimSetCommand,
                                  EditResourceOnClaimSetCommand editResourceOnClaimSetCommand,
                                  GetResourceClaimsQuery getResourceClaimsQuery,
                                  OverrideDefaultAuthorizationStrategyCommand overrideDefaultAuthorizationStrategyCommand)
 {
     _addClaimSetCommand            = addClaimSetCommand;
     _editResourceOnClaimSetCommand = editResourceOnClaimSetCommand;
     _getResourceClaimsQuery        = getResourceClaimsQuery;
     _overrideDefaultAuthorizationStrategyCommand = overrideDefaultAuthorizationStrategyCommand;
 }
 public ClaimSetsController(IGetClaimSetByIdQuery getClaimSetByIdQuery
                            , IGetApplicationsByClaimSetIdQuery getApplicationsByClaimSetIdQuery
                            , IGetResourcesByClaimSetIdQuery getResourcesByClaimSetIdQuery
                            , IGetClaimSetsByApplicationNameQuery getClaimSetsByApplicationNameQuery
                            , IGetAuthStrategiesByApplicationNameQuery getAuthStrategiesByApplicationNameQuery
                            , ITabDisplayService tabDisplayService
                            , CopyClaimSetCommand copyClaimSetCommand
                            , AddClaimSetCommand addClaimSetCommand
                            , EditClaimSetCommand editClaimSetCommand
                            , GetResourceClaimsQuery getResourceClaimsQuery
                            , GetChildResourceClaimsForParentQuery getChildResourceClaimsForParentQuery
                            , DeleteClaimSetCommand deleteClaimSetCommand
                            , EditResourceOnClaimSetCommand editResourceOnClaimSetCommand
                            , DeleteResourceOnClaimSetCommand deleteResourceOnClaimSetCommand
                            , ClaimSetFileExportCommand claimSetFileExportCommand
                            , ClaimSetFileImportCommand claimSetFileImportCommand
                            , OverrideDefaultAuthorizationStrategyCommand overrideDefaultAuthorizationStrategyCommand
                            , ResetToDefaultAuthStrategyCommand resetToDefaultAuthStrategyCommand)
 {
     _getClaimSetByIdQuery                    = getClaimSetByIdQuery;
     _getApplicationsByClaimSetIdQuery        = getApplicationsByClaimSetIdQuery;
     _getResourcesByClaimSetIdQuery           = getResourcesByClaimSetIdQuery;
     _getClaimSetsByApplicationNameQuery      = getClaimSetsByApplicationNameQuery;
     _getAuthStrategiesByApplicationNameQuery = getAuthStrategiesByApplicationNameQuery;
     _tabDisplayService      = tabDisplayService;
     _copyClaimSetCommand    = copyClaimSetCommand;
     _addClaimSetCommand     = addClaimSetCommand;
     _editClaimSetCommand    = editClaimSetCommand;
     _getClaimSetByIdQuery   = getClaimSetByIdQuery;
     _getResourceClaimsQuery = getResourceClaimsQuery;
     _getChildResourceClaimsForParentQuery = getChildResourceClaimsForParentQuery;
     _deleteClaimSetCommand                       = deleteClaimSetCommand;
     _editResourceOnClaimSetCommand               = editResourceOnClaimSetCommand;
     _deleteResourceOnClaimSetCommand             = deleteResourceOnClaimSetCommand;
     _claimSetFileExportCommand                   = claimSetFileExportCommand;
     _claimSetFileImportCommand                   = claimSetFileImportCommand;
     _overrideDefaultAuthorizationStrategyCommand = overrideDefaultAuthorizationStrategyCommand;
     _resetToDefaultAuthStrategyCommand           = resetToDefaultAuthStrategyCommand;
 }
Ejemplo n.º 6
0
 public ClaimSetFileImportCommand(AddClaimSetCommand addClaimSetCommand, EditResourceOnClaimSetCommand editResourceOnClaimSetCommand, GetResourceClaimsQuery getResourceClaimsQuery)
 {
     _addClaimSetCommand            = addClaimSetCommand;
     _editResourceOnClaimSetCommand = editResourceOnClaimSetCommand;
     _getResourceClaimsQuery        = getResourceClaimsQuery;
 }
        public void ShouldImportClaimSet()
        {
            var testApplication = new Application
            {
                ApplicationName = $"Test Application {DateTime.Now:O}"
            };

            Save(testApplication);

            SetupResourceClaims(testApplication);

            var testJSON = @"{
                ""title"": ""testfile"",
                ""template"": {
                    ""claimSets"": [
                      {
                        ""name"": ""Test Claimset"",
                        ""resourceClaims"": [
                          {
                            ""Name"": ""TestParentResourceClaim1"",
                            ""Read"": true,
                            ""Create"": false,
                            ""Update"": false,
                            ""Delete"": false,
                            ""Children"": []
                          },
                          {
                            ""Name"": ""TestParentResourceClaim2"",
                            ""Read"": true,
                            ""Create"": false,
                            ""Update"": false,
                            ""Delete"": false,	
                            ""Children"": []
                          },
                          {
                            ""Name"": ""TestParentResourceClaim3"",
                            ""Read"": true,
                            ""Create"": true,
                            ""Update"": true,
                            ""Delete"": true,
                            ""Children"": []
                          }
                        ]
                      }
                    ]
                }
            }";

            var importModel = GetImportModel(testJSON);

            var getResourceByClaimSetIdQuery  = new GetResourcesByClaimSetIdQuery(TestContext, GetMapper());
            var addClaimSetCommand            = new AddClaimSetCommand(TestContext);
            var getResourceClaimsQuery        = new GetResourceClaimsQuery(TestContext);
            var editResourceOnClaimSetCommand = new EditResourceOnClaimSetCommand(TestContext);

            var command = new ClaimSetFileImportCommand(addClaimSetCommand, editResourceOnClaimSetCommand, getResourceClaimsQuery);

            command.Execute(importModel);

            var testClaimSet = TestContext.ClaimSets.SingleOrDefault(x => x.ClaimSetName == "Test Claimset");

            testClaimSet.ShouldNotBeNull();
            var resourcesForClaimSet = getResourceByClaimSetIdQuery.AllResources(testClaimSet.ClaimSetId).ToList();

            resourcesForClaimSet.Count.ShouldBeGreaterThan(0);
            var testResources = resourcesForClaimSet.Where(x => x.ParentId == 0).ToArray();

            testResources.Count().ShouldBe(3);

            var testResource1 = testResources[0];

            MatchActions(testResource1, "TestParentResourceClaim1", new bool[] { false, true, false, false });

            var testResource2 = testResources[1];

            MatchActions(testResource2, "TestParentResourceClaim2", new bool[] { false, true, false, false });

            var testResource3 = testResources[2];

            MatchActions(testResource3, "TestParentResourceClaim3", new bool[] { true, true, true, true });
        }