public void ShouldImportClaimSetResourceClaimWithChildrenAndAuthrozationStrategyOverrides() { var testApplication = new Application { ApplicationName = $"Test Application {DateTime.Now:O}" }; Save(testApplication); var appAuthorizationStrategies = SetupApplicationAuthorizationStrategies(testApplication, 3).ToList(); SetupResourceClaims(testApplication, 1, 1); var testJSON = @"{ ""title"": ""testfile"", ""template"": { ""claimSets"": [ { ""name"": ""Test Claimset"", ""resourceClaims"": [ { ""Name"": ""TestParentResourceClaim1"", ""Read"": true, ""Create"": true, ""Update"": false, ""Delete"": false, ""AuthStrategyOverridesForCRUD"": [ { ""AuthStrategyId"": {0}, ""AuthStrategyName"": ""{1}"", ""DisplayName"": ""{1}"", ""IsInheritedFromParent"": false }, { ""AuthStrategyId"": {2}, ""AuthStrategyName"": ""{3}"", ""DisplayName"": ""{3}"", ""IsInheritedFromParent"": false }, null, null ], ""Children"": [ { ""Name"": ""TestChildResourceClaim1"", ""Read"": true, ""Create"": true, ""Update"": true, ""Delete"": false, ""AuthStrategyOverridesForCRUD"": [ { ""AuthStrategyId"": {0}, ""AuthStrategyName"": ""{1}"", ""DisplayName"": ""{1}"", ""IsInheritedFromParent"": true }, { ""AuthStrategyId"": {2}, ""AuthStrategyName"": ""{3}"", ""DisplayName"": ""{3}"", ""IsInheritedFromParent"": true }, { ""AuthStrategyId"": {4}, ""AuthStrategyName"": ""{5}"", ""DisplayName"": ""{5}"", ""IsInheritedFromParent"": false }, null ] } ] } ] } ] } }"; var authStrategy1Id = appAuthorizationStrategies[0].AuthorizationStrategyId; var authStrategy1Name = appAuthorizationStrategies[0].AuthorizationStrategyName.ToString(); var authStrategy2Id = appAuthorizationStrategies[1].AuthorizationStrategyId; var authStrategy2Name = appAuthorizationStrategies[1].AuthorizationStrategyName.ToString(); var authStrategy3Id = appAuthorizationStrategies[2].AuthorizationStrategyId; var authStrategy3Name = appAuthorizationStrategies[2].AuthorizationStrategyName.ToString(); var formattedJson = testJSON.Replace("{0}", authStrategy1Id.ToString()) .Replace("{1}", authStrategy1Name) .Replace("{2}", authStrategy2Id.ToString()) .Replace("{3}", authStrategy2Name) .Replace("{4}", authStrategy3Id.ToString()) .Replace("{5}", authStrategy3Name); var importModel = GetImportModel(formattedJson); var importSharingModel = SharingModel.DeserializeToSharingModel(importModel.ImportFile.OpenReadStream()); Scoped <ClaimSetFileImportCommand>(command => command.Execute(importSharingModel)); var testClaimSet = Transaction(securityContext => securityContext.ClaimSets.SingleOrDefault(x => x.ClaimSetName == "Test Claimset")); testClaimSet.ShouldNotBeNull(); var resourcesForClaimSet = Scoped <IGetResourcesByClaimSetIdQuery, List <ResourceClaim> >( query => query.AllResources(testClaimSet.ClaimSetId).ToList()); resourcesForClaimSet.Count.ShouldBeGreaterThan(0); var testResources = resourcesForClaimSet.Where(x => x.ParentId == 0).ToArray(); testResources.Count().ShouldBe(1); var testResource1 = testResources[0]; MatchActions(testResource1, "TestParentResourceClaim1", new bool[] { true, true, false, false }); testResource1.Children.Count.ShouldBe(1); var childResource = testResource1.Children[0]; childResource.ShouldNotBeNull(); testResource1.AuthStrategyOverridesForCRUD.ShouldNotBeNull(); testResource1.AuthStrategyOverridesForCRUD.Length.ShouldBe(4); var parentAuthStrategyOverrideForCreate = testResource1.AuthStrategyOverridesForCRUD.Create(); parentAuthStrategyOverrideForCreate.ShouldNotBeNull(); parentAuthStrategyOverrideForCreate.AuthStrategyId.ShouldBe(authStrategy1Id); parentAuthStrategyOverrideForCreate.AuthStrategyName.ShouldBe(authStrategy1Name); var parentAuthStrategyOverrideForRead = testResource1.AuthStrategyOverridesForCRUD.Read(); parentAuthStrategyOverrideForRead.ShouldNotBeNull(); parentAuthStrategyOverrideForRead.AuthStrategyId.ShouldBe(authStrategy2Id); parentAuthStrategyOverrideForRead.AuthStrategyName.ShouldBe(authStrategy2Name); var childAuthStrategyOverrideForCreate = childResource.AuthStrategyOverridesForCRUD.Create(); childAuthStrategyOverrideForCreate.ShouldNotBeNull(); childAuthStrategyOverrideForCreate.AuthStrategyId.ShouldBe(authStrategy1Id); childAuthStrategyOverrideForCreate.AuthStrategyName.ShouldBe(authStrategy1Name); childAuthStrategyOverrideForCreate.IsInheritedFromParent.ShouldBeTrue(); var childAuthStrategyOverrideForRead = childResource.AuthStrategyOverridesForCRUD.Read(); childAuthStrategyOverrideForRead.ShouldNotBeNull(); childAuthStrategyOverrideForRead.AuthStrategyId.ShouldBe(authStrategy2Id); childAuthStrategyOverrideForRead.AuthStrategyName.ShouldBe(authStrategy2Name); childAuthStrategyOverrideForRead.IsInheritedFromParent.ShouldBeTrue(); var childAuthStrategyOverrideForUpdate = childResource.AuthStrategyOverridesForCRUD.Update(); childAuthStrategyOverrideForUpdate.ShouldNotBeNull(); childAuthStrategyOverrideForUpdate.AuthStrategyId.ShouldBe(authStrategy3Id); childAuthStrategyOverrideForUpdate.AuthStrategyName.ShouldBe(authStrategy3Name); childAuthStrategyOverrideForUpdate.IsInheritedFromParent.ShouldBeFalse(); }
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 importSharingModel = SharingModel.DeserializeToSharingModel(importModel.ImportFile.OpenReadStream()); Scoped <ClaimSetFileImportCommand>(command => command.Execute(importSharingModel)); var testClaimSet = Transaction(securityContext => securityContext.ClaimSets.SingleOrDefault(x => x.ClaimSetName == "Test Claimset")); testClaimSet.ShouldNotBeNull(); var resourcesForClaimSet = Scoped <IGetResourcesByClaimSetIdQuery, List <Management.ClaimSetEditor.ResourceClaim> >( query => query.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 }); }
public SharingModel AsSharingModel() { return(_sharingModel ??= SharingModel.DeserializeToSharingModel(ImportFile.OpenReadStream())); }