예제 #1
0
        public void RemovesPermissionsForRemovedAccessType()
        {
            var accessType0 = AccessTypeDefinition.NewObject();
            var accessType1 = AccessTypeDefinition.NewObject();
            var accessType2 = AccessTypeDefinition.NewObject();

            var securableClassDefinition = SecurableClassDefinition.NewObject();

            securableClassDefinition.AddAccessType(accessType0);
            securableClassDefinition.AddAccessType(accessType1);
            securableClassDefinition.AddAccessType(accessType2);

            var testHelper = new AccessControlTestHelper(ClientTransaction.Current);
            var acls       = new List <AccessControlList>();

            acls.Add(testHelper.CreateStatefulAcl(securableClassDefinition));
            acls.Add(testHelper.CreateStatelessAcl(securableClassDefinition));

            foreach (var acl in acls)
            {
                acl.CreateAccessControlEntry();
            }

            securableClassDefinition.RemoveAccessType(accessType1);
            foreach (var acl in acls)
            {
                var permissions = acl.AccessControlEntries[0].GetPermissions();
                Assert.That(permissions.Count, Is.EqualTo(2));
                Assert.That(permissions[0].AccessType, Is.SameAs(accessType0));
                Assert.That(permissions[1].AccessType, Is.SameAs(accessType2));
            }
        }
예제 #2
0
        public void LeavesPermissionsUntouched()
        {
            var accessType0 = AccessTypeDefinition.NewObject();
            var accessType1 = AccessTypeDefinition.NewObject();
            var securableClassDefinition = SecurableClassDefinition.NewObject();

            securableClassDefinition.AddAccessType(accessType0);
            securableClassDefinition.AddAccessType(accessType1);

            var testHelper = new AccessControlTestHelper(ClientTransaction.Current);
            var acls       = new List <AccessControlList>();

            acls.Add(testHelper.CreateStatefulAcl(securableClassDefinition));
            acls.Add(testHelper.CreateStatelessAcl(securableClassDefinition));

            foreach (var acl in acls)
            {
                var ace = acl.CreateAccessControlEntry();
                ace.DenyAccess(accessType0);
                ace.AllowAccess(accessType1);
            }

            securableClassDefinition.MoveAccessType(0, accessType1);
            foreach (var acl in acls)
            {
                var permissions = acl.AccessControlEntries[0].GetPermissions();
                Assert.That(permissions.Count, Is.EqualTo(2));
                Assert.That(permissions[0].AccessType, Is.SameAs(accessType1));
                Assert.That(permissions[0].Allowed, Is.True);
                Assert.That(permissions[1].AccessType, Is.SameAs(accessType0));
                Assert.That(permissions[1].Allowed, Is.False);
            }
        }
예제 #3
0
        public void ValidateUniqueStateCombinations_DoubleStateCombinationAndObjectIsDeleted()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass        = testHelper.CreateOrderClassDefinition();
                List <StateCombination>  stateCombinations = testHelper.CreateOrderStateAndPaymentStateCombinations(orderClass);
                var states = stateCombinations[0].GetStates();
                StatePropertyDefinition orderStateProperty = states[0].StateProperty;
                StatePropertyDefinition paymentProperty    = states[1].StateProperty;

                using (ClientTransaction.Current.CreateSubTransaction().EnterDiscardingScope())
                {
                    testHelper.CreateStateCombination(
                        orderClass,
                        ClientTransaction.Current,
                        orderStateProperty[EnumWrapper.Get(OrderState.Received).Name],
                        paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name]);
                    Assert.That(orderClass.StateCombinations, Is.Not.Empty);
                    orderClass.Delete();

                    SecurableClassValidationResult result = new SecurableClassValidationResult();
                    orderClass.ValidateUniqueStateCombinations(result);

                    Assert.That(result.IsValid, Is.True);
                    Assert.That(orderClass.State, Is.EqualTo(StateType.Deleted));
                }
            }
        }
예제 #4
0
        public override void SetUp()
        {
            base.SetUp();

            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            _testHelper = testHelper;
            _testHelper.Transaction.EnterNonDiscardingScope();
        }
예제 #5
0
        public void GetStatePropertyTest_InvalidName()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition();

                Assert.That(orderClass.GetStateProperty("Invalid"), Is.Null);
            }
        }
예제 #6
0
        public void StateProperties_IsReadOnly()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinitionWithProperties();

                Assert.That(((ICollection <StatePropertyDefinition>)orderClass.StateProperties).IsReadOnly, Is.True);
            }
        }
예제 #7
0
        public void AccessTypes_Empty()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition();

                Assert.That(orderClass.AccessTypes, Is.Empty);
            }
        }
예제 #8
0
        public void StateProperties_OrderStateAndPaymentState()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinitionWithProperties();

                Assert.That(orderClass.StateProperties.Count, Is.EqualTo(AccessControlTestHelper.OrderClassPropertyCount));
            }
        }
예제 #9
0
        public override void SetUp()
        {
            base.SetUp();

            _aceClass = BindableObjectProviderTestHelper.GetBindableObjectClass(typeof(AccessControlEntry));

            _testHelper = new AccessControlTestHelper();
            _testHelper.Transaction.EnterNonDiscardingScope();

            _ace = AccessControlEntry.NewObject();
        }
예제 #10
0
        public void AccessTypes_IsReadOnly()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition();
                testHelper.AttachJournalizeAccessType(orderClass);

                Assert.That(((ICollection <AccessTypeDefinition>)orderClass.AccessTypes).IsReadOnly, Is.True);
            }
        }
예제 #11
0
        public void AccessTypes_OneAccessType()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition();
                testHelper.AttachJournalizeAccessType(orderClass);

                Assert.That(orderClass.AccessTypes.Count, Is.EqualTo(1));
            }
        }
예제 #12
0
        public void GetStateCombinations_TwoCombinations()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass        = testHelper.CreateOrderClassDefinition();
                StateCombination         stateCombination  = testHelper.CreateStateCombination(orderClass);
                List <StateCombination>  stateCombinations = testHelper.CreateOrderStateAndPaymentStateCombinations(orderClass);

                Assert.That(orderClass.StateCombinations, Is.EqualTo(ArrayUtility.Combine(stateCombination, stateCombinations.ToArray())));
            }
        }
예제 #13
0
        public void Commit_EmptyStateCombinationInClassWithStateProperties()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition();
                testHelper.CreateOrderStateAndPaymentStateCombinations(orderClass);
                testHelper.CreateStateCombination(orderClass);

                testHelper.Transaction.Commit();
            }
        }
예제 #14
0
        public void SetUp()
        {
            try
            {
                // Use default localization for tests
                AclToolsExpansion.Culture = new CultureInfo("");

                AccessControlTestHelper testHelper = new AccessControlTestHelper();
                using (testHelper.Transaction.EnterDiscardingScope())
                {
                    _dbFixtures = new DatabaseFixtures();
                    _dbFixtures.CreateAndCommitOrganizationalStructureWithTwoTenants(ClientTransaction.Current);

                    _cultureDe = Culture.NewObject("de-DE");
                    _cultureEn = Culture.NewObject("en-US");

                    SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition();
                    OrderClassHandle = orderClass.GetHandle();

                    testHelper.AttachAccessType(orderClass, Guid.NewGuid(), "FirstAccessType", 0);
                    testHelper.AttachAccessType(orderClass, Guid.NewGuid(), "FirstAccessType2", 2);
                    testHelper.AttachAccessType(orderClass, Guid.NewGuid(), "FirstAccessType3", 3);
                    aclList = testHelper.CreateAclsForOrderAndPaymentAndDeliveryStates(orderClass);
                    var ace = aclList[0].CreateAccessControlEntry();
                    ace.GetPermissions()[0].Allowed = true; // FirstAccessType

                    testHelper.CreateInvoiceClassDefinition();

                    LocalizeClassEnDe(orderClass, "Order", "Bestellung");

                    LocalizeStatePropertyEnDe(orderClass, "Payment", "Payment", "Bezahlstatus");
                    LocalizeStateEnDe(orderClass, "Payment", (int)PaymentState.None, "None", "Offen");
                    LocalizeStateEnDe(orderClass, "Payment", (int)PaymentState.Paid, "Paid", "Bezahlt");

                    LocalizeStatePropertyEnDe(orderClass, "State", "Order State", "Bestellstatus");
                    LocalizeStateEnDe(orderClass, "State", (int)OrderState.Delivered, "Delivered", "Ausgelifert");
                    LocalizeStateEnDe(orderClass, "State", (int)OrderState.Received, "Received", "Erhalten");

                    LocalizeStatePropertyEnDe(orderClass, "Delivery", "Delivery Provider", "Auslieferer");
                    LocalizeStateEnDe(orderClass, "Delivery", (int)Delivery.Dhl, "DHL", "DHL");
                    LocalizeStateEnDe(orderClass, "Delivery", (int)Delivery.Post, "Mail", "Post");

                    ClientTransaction.Current.Commit();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #15
0
        public void StateProperties_IsNotCached()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinitionWithProperties();

                var firstCollection  = orderClass.StateProperties;
                var secondCollection = orderClass.StateProperties;

                Assert.That(secondCollection, Is.Not.SameAs(firstCollection));
            }
        }
예제 #16
0
        public void ValidateUniqueStateCombinations_NoStateCombinations()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition();

                SecurableClassValidationResult result = new SecurableClassValidationResult();
                orderClass.ValidateUniqueStateCombinations(result);

                Assert.That(result.IsValid, Is.True);
            }
        }
예제 #17
0
        public void Validate_Valid()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition();
                testHelper.CreateOrderStateAndPaymentStateCombinations(orderClass);

                SecurableClassValidationResult result = orderClass.Validate();

                Assert.That(result.IsValid, Is.True);
            }
        }
예제 #18
0
        public void AccessTypes_IsNotCached()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition();
                testHelper.AttachJournalizeAccessType(orderClass);

                var firstCollection  = orderClass.AccessTypes;
                var secondCollection = orderClass.AccessTypes;

                Assert.That(secondCollection, Is.Not.SameAs(firstCollection));
            }
        }
예제 #19
0
        public void Commit_TwoStateCombinations()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass      = testHelper.CreateOrderClassDefinition();
                StatePropertyDefinition  paymentProperty = testHelper.CreatePaymentStateProperty(orderClass);
                testHelper.CreateStateCombination(orderClass, paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name]);
                testHelper.CreateStateCombination(orderClass, paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name]);
                testHelper.CreateStateCombination(orderClass, paymentProperty[EnumWrapper.Get(PaymentState.None).Name]);

                testHelper.Transaction.Commit();
            }
        }
예제 #20
0
        public void GetStatePropertyTest_ValidName()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass        = testHelper.CreateOrderClassDefinition();
                List <StateCombination>  stateCombinations = testHelper.CreateOrderStateAndPaymentStateCombinations(orderClass);
                var states = stateCombinations[0].GetStates();
                StatePropertyDefinition orderStateProperty = states[0].StateProperty;
                StatePropertyDefinition paymentProperty    = states[1].StateProperty;

                Assert.That(orderClass.GetStateProperty(orderStateProperty.Name), Is.EqualTo(orderStateProperty));
                Assert.That(orderClass.GetStateProperty(paymentProperty.Name), Is.EqualTo(paymentProperty));
            }
        }
예제 #21
0
        public void IsValid_DuplicateStateCombination()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass       = testHelper.CreateOrderClassDefinition();
                StateCombination         stateCombination = testHelper.CreateStateCombination(orderClass);

                SecurableClassValidationResult result = new SecurableClassValidationResult();

                result.AddDuplicateStateCombination(stateCombination);

                Assert.That(result.IsValid, Is.False);
            }
        }
예제 #22
0
        public void DuplicateStateCombinations_OneInvalidStateCombination()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass       = testHelper.CreateOrderClassDefinition();
                StateCombination         stateCombination = testHelper.CreateStateCombination(orderClass);

                SecurableClassValidationResult result = new SecurableClassValidationResult();

                result.AddDuplicateStateCombination(stateCombination);

                Assert.That(result.DuplicateStateCombinations.Count, Is.EqualTo(1));
                Assert.That(result.DuplicateStateCombinations, Has.Member(stateCombination));
            }
        }
예제 #23
0
        public void ValidateStateCombinationsAgainstStateProperties_EmptyStateCombinationInClassWithStateProperties()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition();
                testHelper.CreateOrderStateAndPaymentStateCombinations(orderClass);
                StateCombination statelessCombination = testHelper.CreateStateCombination(orderClass);

                SecurableClassValidationResult result = new SecurableClassValidationResult();
                orderClass.ValidateStateCombinationsAgainstStateProperties(result);

                Assert.That(result.IsValid, Is.False);
                Assert.That(result.InvalidStateCombinations, Is.EquivalentTo(new[] { statelessCombination }));
            }
        }
예제 #24
0
        public void ValidateUniqueStateCombinations_TwoEmptyStateCombinations()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass            = testHelper.CreateOrderClassDefinition();
                StateCombination         statelessCombination1 = testHelper.CreateStateCombination(orderClass);
                StateCombination         statelessCombination2 = testHelper.CreateStateCombination(orderClass);

                SecurableClassValidationResult result = new SecurableClassValidationResult();
                orderClass.ValidateUniqueStateCombinations(result);

                Assert.That(result.IsValid, Is.False);
                Assert.That(result.DuplicateStateCombinations, Has.Member(statelessCombination1));
                Assert.That(result.DuplicateStateCombinations, Has.Member(statelessCombination2));
            }
        }
예제 #25
0
        public void DeleteGroupType_WithAccessControlEntry()
        {
            DatabaseFixtures        dbFixtures = new DatabaseFixtures();
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                dbFixtures.CreateEmptyDomain();
                GroupType          groupType = testHelper.CreateGroupType("GroupType");
                AccessControlEntry ace       = testHelper.CreateAceWithBranchOfOwningGroup(groupType);
                ClientTransaction.Current.Commit();

                groupType.Delete();

                ClientTransaction.Current.Commit();

                Assert.That(ace.State, Is.EqualTo(StateType.Invalid));
            }
        }
예제 #26
0
        public void Validate_DoubleStateCombination()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass        = testHelper.CreateOrderClassDefinition();
                List <StateCombination>  stateCombinations = testHelper.CreateOrderStateAndPaymentStateCombinations(orderClass);
                var states = stateCombinations[0].GetStates();
                StatePropertyDefinition orderStateProperty = states[0].StateProperty;
                StatePropertyDefinition paymentProperty    = states[1].StateProperty;
                testHelper.CreateStateCombination(
                    orderClass, orderStateProperty[EnumWrapper.Get(OrderState.Received).Name], paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name]);

                SecurableClassValidationResult result = orderClass.Validate();

                Assert.That(result.IsValid, Is.False);
            }
        }
예제 #27
0
        public void DeleteGroup_WithAccessControlEntry()
        {
            DatabaseFixtures        dbFixtures = new DatabaseFixtures();
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                dbFixtures.CreateEmptyDomain();
                var group = testHelper.CreateGroup("group", null, testHelper.CreateTenant("tenant"));
                var ace   = testHelper.CreateAceWithSpecificGroup(group);
                ClientTransaction.Current.Commit();

                group.Delete();

                ClientTransaction.Current.Commit();

                Assert.That(ace.State, Is.EqualTo(StateType.Invalid));
            }
        }
예제 #28
0
        public void CascadeToAccessControlEntry()
        {
            DatabaseFixtures        dbFixtures = new DatabaseFixtures();
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                dbFixtures.CreateEmptyDomain();
                var tenant      = testHelper.CreateTenant("TestTenant");
                var owningGroup = testHelper.CreateGroup("group", null, tenant);
                var user        = testHelper.CreateUser("user", null, "user", null, owningGroup, tenant);
                var ace         = testHelper.CreateAceWithSpecificUser(user);
                ClientTransaction.Current.Commit();

                user.Delete();

                ClientTransaction.Current.Commit();

                Assert.That(ace.State, Is.EqualTo(StateType.Invalid));
            }
        }
예제 #29
0
        public void ValidateUniqueStateCombinations_TwoStateCombinations()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass       = testHelper.CreateOrderClassDefinition();
                StatePropertyDefinition  paymentProperty  = testHelper.CreatePaymentStateProperty(orderClass);
                StateCombination         paidCombination1 = testHelper.CreateStateCombination(orderClass, paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name]);
                StateCombination         paidCombination2 = testHelper.CreateStateCombination(orderClass, paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name]);
                testHelper.CreateStateCombination(orderClass, paymentProperty[EnumWrapper.Get(PaymentState.None).Name]);

                SecurableClassValidationResult result = new SecurableClassValidationResult();
                orderClass.ValidateUniqueStateCombinations(result);

                Assert.That(result.IsValid, Is.False);
                Assert.That(result.DuplicateStateCombinations.Count, Is.EqualTo(2));
                Assert.That(result.DuplicateStateCombinations, Has.Member(paidCombination1));
                Assert.That(result.DuplicateStateCombinations, Has.Member(paidCombination2));
            }
        }
예제 #30
0
        public void DeletePosition_WithAccessControlEntry()
        {
            DatabaseFixtures        dbFixtures = new DatabaseFixtures();
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                Tenant             tenant   = dbFixtures.CreateAndCommitOrganizationalStructureWithTwoTenants(ClientTransaction.Current);
                User               user     = User.FindByTenant(tenant.GetHandle()).First();
                Role               role     = user.Roles[0];
                Position           position = role.Position;
                AccessControlEntry ace      = testHelper.CreateAceWithPosition(position);
                ClientTransaction.Current.Commit();

                position.Delete();

                ClientTransaction.Current.Commit();

                Assert.That(ace.State, Is.EqualTo(StateType.Invalid));
            }
        }