public void Test_CheckAccess_EmptyEntityTypes() { var result = new IntersectingEntityAccessControlChecker(new IEntityAccessControlChecker[0]).CheckAccess(new Collection <EntityRef>(), new Collection <EntityRef>(), new EntityRef(1)); Assert.AreEqual(0, result.Count, "The result should be empty"); }
public void TestCheckAccess_ByPassSecurity() { var entitiesToCheck = new List <EntityRef> { new EntityRef(100), new EntityRef(200) }; var permissionsToCheck = new List <EntityRef> { new EntityRef(5) }; var userToCheck = new EntityRef(1); var mockRepo = new MockRepository(MockBehavior.Strict); var checker1 = mockRepo.Create <IEntityAccessControlChecker>(); var checker2 = mockRepo.Create <IEntityAccessControlChecker>(); var intersectingChecker = new IntersectingEntityAccessControlChecker(new List <IEntityAccessControlChecker> { checker1.Object, checker2.Object }); IDictionary <long, bool> result; using (new SecurityBypassContext()) { result = intersectingChecker.CheckAccess(entitiesToCheck, permissionsToCheck, userToCheck); } Assert.AreEqual(2, result.Count, "The count is invalid"); Assert.AreEqual(true, result[100], "Access to entity 1 is invalid"); Assert.AreEqual(true, result[200], "Access to entity 2 is invalid"); mockRepo.VerifyAll(); }
public void TestCheckAccess( bool?checker1Entity1, bool?checker1Entity2, bool?checker2Entity1, bool?checker2Entity2, bool resultEntity1, bool resultEntity2) { var entitiesToCheck = new List <EntityRef> { new EntityRef(100), new EntityRef(200) }; var permissionsToCheck = new List <EntityRef> { new EntityRef(5) }; var userToCheck = new EntityRef(1); var result1 = new Dictionary <long, bool>(); if (checker1Entity1 != null) { result1[100] = checker1Entity1.Value; } if (checker1Entity2 != null) { result1[200] = checker1Entity2.Value; } var result2 = new Dictionary <long, bool>(); if (checker2Entity1 != null) { result2[100] = checker2Entity1.Value; } if (checker2Entity2 != null) { result2[200] = checker2Entity2.Value; } var mockRepo = new MockRepository(MockBehavior.Strict); var checker1 = mockRepo.Create <IEntityAccessControlChecker>(); checker1.Setup(f => f.CheckAccess( It.Is <IList <EntityRef> >(e => e.SequenceEqual(entitiesToCheck, EntityRefComparer.Instance)), It.Is <IList <EntityRef> >(p => p.SequenceEqual(permissionsToCheck, EntityRefComparer.Instance)), It.Is <EntityRef>(e => Equals(userToCheck, e)))).Returns(result1); var checker2 = mockRepo.Create <IEntityAccessControlChecker>(); checker2.Setup(f => f.CheckAccess( It.Is <IList <EntityRef> >(e => e.SequenceEqual(entitiesToCheck, EntityRefComparer.Instance)), It.Is <IList <EntityRef> >(p => p.SequenceEqual(permissionsToCheck, EntityRefComparer.Instance)), It.Is <EntityRef>(e => Equals(userToCheck, e)))).Returns(result2); var intersectingChecker = new IntersectingEntityAccessControlChecker(new List <IEntityAccessControlChecker> { checker1.Object, checker2.Object }); var result = intersectingChecker.CheckAccess(entitiesToCheck, permissionsToCheck, userToCheck); Assert.AreEqual(2, result.Count, "The count is invalid"); Assert.AreEqual(resultEntity1, result[100], "Access to entity 1 is invalid"); Assert.AreEqual(resultEntity2, result[200], "Access to entity 2 is invalid"); mockRepo.VerifyAll(); }
public void TestCheckTypeAccessList( bool?checker1Entity1, bool?checker1Entity2, bool?checker2Entity1, bool?checker2Entity2, bool resultEntity1, bool resultEntity2) { var et1 = new EntityType(); var et2 = new EntityType(); var entitiesToCheck = new List <EntityType> { et1, et2 }; var userToCheck = new EntityRef(1); var permission = new EntityRef(2); var result1 = new Dictionary <long, bool>(); if (checker1Entity1 != null) { result1[et1.Id] = checker1Entity1.Value; } if (checker1Entity2 != null) { result1[et2.Id] = checker1Entity2.Value; } var result2 = new Dictionary <long, bool>(); if (checker2Entity1 != null) { result2[et1.Id] = checker2Entity1.Value; } if (checker2Entity2 != null) { result2[et2.Id] = checker2Entity2.Value; } var mockRepo = new MockRepository(MockBehavior.Strict); var checker1 = mockRepo.Create <IEntityAccessControlChecker>(); checker1.Setup(f => f.CheckTypeAccess( It.Is <IList <EntityType> >(e => ReferenceEquals(e, entitiesToCheck)), It.Is <EntityRef>(e => Equals(permission, e)), It.Is <EntityRef>(e => Equals(userToCheck, e)))).Returns(result1); var checker2 = mockRepo.Create <IEntityAccessControlChecker>(); checker2.Setup(f => f.CheckTypeAccess( It.Is <IList <EntityType> >(e => ReferenceEquals(e, entitiesToCheck)), It.Is <EntityRef>(e => Equals(permission, e)), It.Is <EntityRef>(e => Equals(userToCheck, e)))).Returns(result2); var intersectingChecker = new IntersectingEntityAccessControlChecker(new List <IEntityAccessControlChecker> { checker1.Object, checker2.Object }); var result = intersectingChecker.CheckTypeAccess(entitiesToCheck, permission, userToCheck); Assert.AreEqual(2, result.Count, "The count is invalid"); Assert.AreEqual(resultEntity1, result[et1.Id], "Access to entity 1 is invalid"); Assert.AreEqual(resultEntity2, result[et2.Id], "Access to entity 2 is invalid"); mockRepo.VerifyAll(); }