Пример #1
0
        public void GetAccessTypeFromEnum()
        {
            AccessType accessType = AccessType.Get(EnumWrapper.Get(TestAccessTypes.First));

            Assert.That(accessType.Value, Is.EqualTo(EnumWrapper.Get(TestAccessTypes.First)));
        }
Пример #2
0
 public void Equals_False_WithNull()
 {
     Assert.That(AccessType.Get(EnumWrapper.Get(TestAccessTypes.Second)).Equals(null), Is.False);
 }
Пример #3
0
 public void GetHashCode_IsSameForEqualValues()
 {
     Assert.That(AccessType.Get(TestAccessTypes.Second).GetHashCode(), Is.EqualTo(AccessType.Get(EnumWrapper.Get(TestAccessTypes.Second)).GetHashCode()));
 }
Пример #4
0
        public void Test_WithSecurityStrategyIsNull()
        {
            _testHelper.ReplayAll();

            _securityClient.CheckAccess(new SecurableObject(null), (IReadOnlyList <AccessType>) new[] { AccessType.Get(TestAccessTypes.First) });

            _testHelper.VerifyAll();
        }
Пример #5
0
        public void HasAccess_WithReEntrancyOnSameGuard_ThrowsInvalidOperationException()
        {
            var objectSecurityStrategyStub = MockRepository.GenerateStub <IObjectSecurityStrategy>();
            var guard = new InstanceBasedReEntrancyGuardedObjectSecurityStrategyDecorator(objectSecurityStrategyStub);
            var accessTypesOnFirstCall = new[] { AccessType.Get(GeneralAccessTypes.Find) };

            bool isExceptionThrownBySecondHasAccess = false;

            objectSecurityStrategyStub
            .Stub(_ => _.HasAccess(_securityProviderStub, _principalStub, accessTypesOnFirstCall))
            .Return(false)
            .WhenCalled(
                mi =>
            {
                var exception = Assert.Throws <InvalidOperationException> (
                    () => guard.HasAccess(_securityProviderStub, _principalStub, new[] { AccessType.Get(GeneralAccessTypes.Read) }));
                isExceptionThrownBySecondHasAccess = true;
                throw exception;
            });

            Assert.That(
                () => guard.HasAccess(_securityProviderStub, _principalStub, accessTypesOnFirstCall),
                Throws.InvalidOperationException
                .With.Message.StartsWith(
                    "Multiple reentrancies on InstanceBasedReEntrancyGuardedObjectSecurityStrategyDecorator.HasAccess(...) are not allowed as they can indicate a possible infinite recursion."));

            Assert.That(isExceptionThrownBySecondHasAccess, Is.True);
        }
Пример #6
0
 public void Equatable_Equals_False()
 {
     Assert.That(AccessType.Get(EnumWrapper.Get(TestAccessTypes.Second)).Equals(AccessType.Get(TestAccessTypes.Fourth)), Is.False);
 }
Пример #7
0
        public void Test_AccessGranted()
        {
            _testHelper.ExpectFunctionalSecurityStrategyHasAccess(TestAccessTypes.First, true);
            _testHelper.ReplayAll();

            _securityClient.CheckStatelessAccess(typeof(SecurableObject), (IReadOnlyList <AccessType>) new[] { AccessType.Get(TestAccessTypes.First) });

            _testHelper.VerifyAll();
        }
Пример #8
0
        public void Test_WithParamsArray_AndSecurityPrincipal()
        {
            _testHelper.ReplayAll();

            var  securityPrincipal = _securityClient.PrincipalProvider.GetPrincipal();
            bool hasAccess         = _securityClient.HasAccess(_testHelper.SecurableObject, securityPrincipal, AccessType.Get(TestAccessTypes.First));

            _testHelper.VerifyAll();
            Assert.That(hasAccess, Is.EqualTo(true));
        }
Пример #9
0
        public void Test_WithParamsArray_AndSecurityPrincipal()
        {
            _testHelper.ReplayAll();

            var securityPrincipal = _securityClient.PrincipalProvider.GetPrincipal();

            _securityClient.CheckAccess(_testHelper.SecurableObject, securityPrincipal, AccessType.Get(TestAccessTypes.First));

            _testHelper.VerifyAll();
        }
        public void IsReadonly_PropertyWithDefaultPermission_False()
        {
            var securityContextStub        = MockRepository.GenerateStub <ISecurityContext> ();
            var securityContextFactoryStub = MockRepository.GenerateStub <ISecurityContextFactory> ();

            securityContextFactoryStub.Stub(mock => mock.CreateSecurityContext()).Return(securityContextStub);
            _securityProviderStub.Stub(mock => mock.GetAccess(securityContextStub, _securityPrincipalStub)).Return(new[] { AccessType.Get(GeneralAccessTypes.Edit) });

            IBusinessObject bindableSecurableObject;

            using (SecurityFreeSection.Activate())
            {
                bindableSecurableObject = CreateBindableSecurableObject(securityContextFactoryStub);
            }
            var businessObjectClass = bindableSecurableObject.BusinessObjectClass;
            var property            = businessObjectClass.GetPropertyDefinition("PropertyWithDefaultPermission");

            Assert.That(property.IsReadOnly(bindableSecurableObject), Is.False);
        }
Пример #11
0
 private AccessType ConvertToAccessType(AccessTypeDefinition accessTypeDefinition)
 {
     return(AccessType.Get(EnumWrapper.Get(accessTypeDefinition.Name)));
 }
        public void IsAccessible_CustomPermissionMixedProperty_True()
        {
            var securityContextStub        = MockRepository.GenerateStub <ISecurityContext> ();
            var securityContextFactoryStub = MockRepository.GenerateStub <ISecurityContextFactory> ();

            securityContextFactoryStub.Stub(mock => mock.CreateSecurityContext()).Return(securityContextStub);
            _securityProviderStub.Stub(mock => mock.GetAccess(securityContextStub, _securityPrincipalStub)).Return(new[] { AccessType.Get(TestAccessTypes.First) });

            IBusinessObject bindableSecurableObject;

            using (SecurityFreeSection.Activate())
            {
                bindableSecurableObject = CreateBindableSecurableObject(securityContextFactoryStub);
            }
            var businessObjectClass = bindableSecurableObject.BusinessObjectClass;
            var property            = businessObjectClass.GetPropertyDefinition("CustomPermissionMixedProperty");

            Assert.That(property.IsAccessible(bindableSecurableObject), Is.True);
        }
        public void NoTest_DerivedReadOnlyProperty_IsNotAccessible()
        {
            var securityContextStub        = MockRepository.GenerateStub <ISecurityContext> ();
            var securityContextFactoryStub = MockRepository.GenerateStub <ISecurityContextFactory> ();

            securityContextFactoryStub.Stub(mock => mock.CreateSecurityContext()).Return(securityContextStub);
            _securityProviderStub.Stub(mock => mock.GetAccess(securityContextStub, _securityPrincipalStub)).Return(new[] { AccessType.Get(TestAccessTypes.First) });

            IBusinessObject bindableSecurableObject;

            using (SecurityFreeSection.Activate())
            {
                bindableSecurableObject = CreateDerivedBindableSecurableObject(securityContextFactoryStub);
            }
            var businessObjectClass = bindableSecurableObject.BusinessObjectClass;
            var property            = businessObjectClass.GetPropertyDefinition("PropertyToOverride");

            Assert.That(property.IsAccessible(bindableSecurableObject), Is.False);
        }
Пример #14
0
        public void Test_AccessDenied_ShouldThrowPermissionDeniedException()
        {
            _testHelper.ExpectFunctionalSecurityStrategyHasAccess(TestAccessTypes.First, false);
            _testHelper.ReplayAll();

            _securityClient.CheckStatelessAccess(typeof(SecurableObject), (IReadOnlyList <AccessType>) new[] { AccessType.Get(TestAccessTypes.First) });

            _testHelper.VerifyAll();
        }
Пример #15
0
 public void GetAccessTypeFromEnumWithoutAccessTypeAttribute()
 {
     AccessType.Get(TestAccessTypesWithoutAccessTypeAttribute.First);
 }
Пример #16
0
        public void Test_AccessGranted()
        {
            _testHelper.ReplayAll();

            _securityClient.CheckAccess(_testHelper.SecurableObject, (IReadOnlyList <AccessType>) new[] { AccessType.Get(TestAccessTypes.First) });

            _testHelper.VerifyAll();
        }
Пример #17
0
 public void GetFromCache()
 {
     Assert.That(AccessType.Get(TestAccessTypes.First), Is.EqualTo(AccessType.Get(TestAccessTypes.First)));
     Assert.That(AccessType.Get(TestAccessTypes.Second), Is.EqualTo(AccessType.Get(EnumWrapper.Get(TestAccessTypes.Second))));
     Assert.That(AccessType.Get(EnumWrapper.Get(TestAccessTypes.Third)), Is.EqualTo(AccessType.Get(EnumWrapper.Get(TestAccessTypes.Third))));
 }
Пример #18
0
        public void Test_WithinSecurityFreeSection_AccessGranted()
        {
            _testHelper.ReplayAll();

            using (SecurityFreeSection.Activate())
            {
                _securityClient.CheckAccess(_testHelper.SecurableObject, (IReadOnlyList <AccessType>) new[] { AccessType.Get(TestAccessTypes.First) });
            }

            _testHelper.VerifyAll();
        }
Пример #19
0
 public void Equals_True()
 {
     Assert.That(AccessType.Get(EnumWrapper.Get(TestAccessTypes.Second)).Equals((object)AccessType.Get(TestAccessTypes.Second)), Is.True);
 }
Пример #20
0
        public void Test_WithParamsArray_AndSecurityPrincipal()
        {
            _testHelper.ExpectFunctionalSecurityStrategyHasAccess(TestAccessTypes.First, true);
            _testHelper.ReplayAll();

            var securityPrincipal = _securityClient.PrincipalProvider.GetPrincipal();

            _securityClient.CheckStatelessAccess(typeof(SecurableObject), securityPrincipal, AccessType.Get(TestAccessTypes.First));

            _testHelper.VerifyAll();
        }