Exemple #1
0
        public void GetAccess_ContextDoesNotMatchAcl_ReturnsEmptyAccessTypes()
        {
            SecurityToken token = SecurityToken.Create(
                PrincipalTestHelper.Create(_tenant, null, new Role[0]),
                null,
                null,
                null,
                Enumerable.Empty <IDomainObjectHandle <AbstractRoleDefinition> >());

            Expect.Call(_mockAclFinder.Find(_context)).Return(null);
            Expect.Call(_mockTokenBuilder.CreateToken(_principalStub, _context)).Return(token);
            _mocks.ReplayAll();

            AccessType[] actualAccessTypes = _service.GetAccess(_context, _principalStub);

            Assert.That(actualAccessTypes, Is.Empty);
        }
Exemple #2
0
        public void GetAccess_UsesSecurityFreeSection()
        {
            ClientTransaction subTransaction;

            using (_clientTransaction.EnterNonDiscardingScope())
            {
                var abstractRoles = new List <IDomainObjectHandle <AbstractRoleDefinition> >();
                //abstractRoles.Add (_ace.SpecificAbstractRole.GetHandle());

                //_ace.GroupCondition = GroupCondition.AnyGroupWithSpecificGroupType;
                //_ace.SpecificGroupType = GroupType.NewObject();
                OrganizationalStructureFactory organizationalStructureFactory = new OrganizationalStructureFactory();
                var role = Role.NewObject();
                role.Group        = organizationalStructureFactory.CreateGroup();
                role.Group.Tenant = _tenant;
                role.Position     = organizationalStructureFactory.CreatePosition();

                var token = SecurityToken.Create(PrincipalTestHelper.Create(_tenant, null, new[] { role }), null, null, null, abstractRoles);

                subTransaction = _clientTransaction.CreateSubTransaction();
                using (subTransaction.EnterNonDiscardingScope())
                {
                    var aclHandle = CreateAccessControlListHandle();
                    Expect.Call(_mockAclFinder.Find(_context))
                    .WhenCalled(invocation => Assert.That(SecurityFreeSection.IsActive, Is.True))
                    .Return(aclHandle);
                    Expect.Call(_mockTokenBuilder.CreateToken(_principalStub, _context))
                    .WhenCalled(invocation => Assert.That(SecurityFreeSection.IsActive, Is.True))
                    .Return(token);
                }
            }

            var serviceLocator = DefaultServiceLocator.Create();

            serviceLocator.RegisterSingle(() => MockRepository.GenerateStub <ISecurityProvider>());
            using (new ServiceLocatorScope(serviceLocator))
            {
                _clientTransaction.Extensions.Add(new SecurityClientTransactionExtension());

                _mocks.ReplayAll();

                _service.GetAccess(_context, _principalStub);

                _mocks.VerifyAll();
            }
        }
Exemple #3
0
        public void GetAccess_ReturnsAccessTypes()
        {
            AccessType[] expectedAccessTypes = new AccessType[1];

            SecurityToken token = SecurityToken.Create(
                PrincipalTestHelper.Create(_tenant, null, new Role[0]),
                null,
                null,
                null,
                Enumerable.Empty <IDomainObjectHandle <AbstractRoleDefinition> >());

            var aclHandle = CreateAccessControlListHandle();

            Expect.Call(_mockAclFinder.Find(_context)).Return(aclHandle);
            Expect.Call(_mockTokenBuilder.CreateToken(_principalStub, _context)).Return(token);
            Expect.Call(_mockAccessResolver.GetAccessTypes(aclHandle, token)).Return(expectedAccessTypes);
            _mocks.ReplayAll();

            AccessType[] actualAccessTypes = _service.GetAccess(_context, _principalStub);

            Assert.That(actualAccessTypes, Is.SameAs(expectedAccessTypes));
        }